oracle9i种引用表的方式一般是用户名.表名的格式.
几种较复杂的SQL.
1:非等值查询
例句:select emp.empno,emp.ename,emp.deptno,dept.dname,dept.doc from scott.emp,scott.dept where scottemp.deptno!=scott.dept.deptno and scott.emp.deptno=10;
2:嵌套查询:
例句:
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal>=(select sal from scott.emp where ename="WARD");
IN:
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal IN(select sal from scott.emp where ename="WARD");
ANY:
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal>any(select sal from scott.emp where ename="WARD");
SOME:
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal=some(select sal from scott.emp where ename="WARD");
ALL:
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal>all(select sal from scott.emp where ename="WARD");
EXITS:
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp,scott.dept where exits(select * from scott.emp where scott.emp.deptno=scott.dept.deptno);
UNION:将列合并
(select * deptno from scott.emp)
union
(select * deptno from scott.dept)
INTERSECT:取相同的
(select * deptno from scott.emp)
insertsect
(select * deptno from scott.dept)
MINUS:取不同的
(select * deptno from scott.emp)
minus
(select * deptno from scott.dept)
3:函数查询:
ceil(n):取大于等于数值n的最小整数(向上取整)--------floor(n):向下取整
mod(m,n):取m整除n后的余数;
power(m,n):取m的n次方;
round(m,n)四舍五入,保留n位;
sign(n):n>0,取1;n=0;取0;n<0,取-1;
avg(字段名_,求平均值;
count(字段名):统计总数
min(字段名),计算数字型字段最小数
max(字段名),计算数字型字段最大数
sum(字段名),计算数字型字段总和
4:从数据表种查询到的数据稍做修改成批录入
insert into 数据表(字段.....) (select (字段或运算,字段名或运算....)from 数据表 where
5:整表删除
truncate table 表名;
truncate table命令将快输删除表中的所有记录,但保留数据表结构.这种删除跟delete from 数据表的删除全部数据表记录不一样,delete命令删除的数据将存储再系统回滚段中,需要的时候,数据可以回滚恢复,而truncate明亮删除的数据是不可恢复的.所以如果数据没有必要恢复,最好采取truncate table命令,这样可以节省空间.
posted on 2006-04-05 11:38  kuning的程序博客  阅读(358)  评论(0编辑  收藏  举报