1.查看表结构
1) describe 表名;
2) set long = 6000; select DBMS_METADATA.GET_DLL('TABLE','表名') from dual;
2.in/not in 与 exists/not exists的区别
in是把外表和内表做hash连接,exists是对外表做loop循环,每次loop循环在对内表进行查询,如果两个表大小相当,效率相差不大
使用子查询时碰到一个小表和一个大表时,用in的时候使用小表做子查询,用exists的时候使用大表做子查询
如果使用not in时,那么内、外表都进行全表扫描,没有用到索引,而not exists依然可以用到索引;所以,无论哪个表大,not exists都比not in要快
且使用not in时在表中有null时会报逻辑错误,所以尽量不要使用not in
3.oracle数据库查询至少有一个员工的所有部门
1)select dname from dept where deptno in (select deptno from emp group by deptno having(count(deptno)>1));
2)select dname from dept where deptno in (select deptno from emp);
3)select * from dept where exists (select deptno from emp where dept.deptno=emp.deptno);
4,将两列相加的sql语句
select sal,comm,(sal+comm) as salary from emp; 这样salary就等于sal + comm了;