Oracle(十二)序列
1、创建序列
create sequence dept_deptno_seq increment by 2 start with 60 maxvalue 99 nocache --是否缓存到内存 nocycle --不循环 select * from user_sequences;
2、序列的两个关键字:nextval应在currval之前指定
select dept_deptno_seq.nextval from dual; --会不断地找序列中的下一个值 select dept_deptno_seq.currval from dual; --不会不断地找下一个值
3、创建索引--create index...
create index emp_ename_idx on emp(ename); select * from emp e where e.ename = 'ALLEN'; 注:物理地址的伪列:rowid
4、同义词
create synonym d_2 for dept; select * from d_2;
其它练习:
--查询至少有一门课与学号是s001同学学的相同的学号、姓名
select s.sno from student s ,sc where s.sno = sc.sno and sc.cno in ( select cno from sc where sno = 's001') group by s.sno,s.sname;
--统计每门课程的学生选修人数(超过3人),要求输出课程号和选修人数,
--查询结果按人数降序排列,若人数相同,课程号按照升序排列。
select c.cno, count(1) from sc, course c where sc.cno = c.cno group by c.cno having count(1) > 3 order by count(1) desc, c.cno;
                    
                
                
            
        
浙公网安备 33010602011771号