oracle sql中的一些内置函数和一些常用的sql语句(笔记)



 

 is null; //是null
 is not null; //不是null
 savepoint aa;	//设置保存回归点
 rollback to aa;   //rollback回归点


set timing on //打开执行操作的时间
insert into user(id,username,password) selet * from user //超级复制,自己往自己插入数据
nvl(comm,0) //如果comm=null,就有0表示,如果不是null,就用他原来的值
select sal*13 as "工资" from emp;  //查询是每个sal乘以13,并且别名两边是双引号
data //默认的格式是 d-m月-y,比如02-08月-2010
like '__0%'; //表示前面两个字符随意,第三个字符是0后面随便是什么字符

order by departNo,sal desc;//一个升序,一个降序,按departNo asc,sal是desc
select sal+comm as "年工资" from user order by "年工资" //别名排序

//表示按 deptno和job分组,并计算  min(sal),avg(sal),max(sal)和显示deptno,job这些信息
select min(sal),avg(sal),max(sal),deptno,job from emp group by deptno,job

//表示先按 deptno 分组,并计算avg(sal),max(sal),在过滤( having)	 avg(sal)>2000
select avg(sal),max(sal),deptno from emp group by deptno having  avg(sal)>2000

//表示查询  sal大于 select sal from emp where depton=30这里面的(depton=30)的sal
select sal from emp where sal > all(select sal from emp where depton=30);
select sal from emp where sal >(select max(sal) from emp where depton=30));

all 所有
any 任何一个

//多列查询 顺序不能弄倒 (id,user)=(select  id,user)
select * from user where (id,user)=(select  id,user from user where id=2));

//oracle分页 ,表示order by name,然后 6到10条数据;
//所有的改动,只需要改动(select name from emp order by name)这一部分
select * from 
(
select t1.*,rownum rn from  
(select name from emp order by name) 
t1 where rownum<=10
) where rn>=6

 //用查询结果创建新表,并把数据也导过来了啊
 create table mytable(id,name) as select id,name from user

 //合并查询
 union  //去掉重复的数据,并集
 union all //不去掉重复的数据,拼张数据,全部的
 intersect    // 相交(交集),共同有的数据
 minus //   差集

//希望SOOTT的工作,工资,补助和 SMITH一样,使用子查询更新数据
update emp set(job,sal,comm)=(select job,sal,comm from emp where ename='SMITH') 
where ename='SOOTT';
//只读事务,表示不能查到在此之后的数据
set transaction read only;
to_date('20101010','yyyy-mm-dd');
lower('A')=a
upper('a')=A
length('length')=6
substr('abcdefg',2,3)= bcd; //oracle的substr函数的下标是1开始
//首字母小写,其它的字符大写
select lower(substr(APPNTNO,1,1)) ||substr(APPNTNO,2,length(APPNTNO))  from lcpol;
raplace('abcdefgffaggff','f',0)=abcde0g00agg00
round(n,[m]) round(10.236523,3)=10.237 //四舍五入
trunc(n,[m]) trunc(10.236523,3)=10.236//截取数字
mod(m,n)     mod(7,5)=2 //求余数
floor(m) floor(10.59)=10//返回小于或等于的最大整数
ceil(m)  ceil(10.59)=11//返回大于或等于的最大整数
abs(n) //绝对值
acos(n) //返回数字的反余旋值
atan(n)	  //返回数字的反正旋值
log(m,n) //返回对数值
power(m,n) //返回m的n次幂
sysdate; //返回系统时间
add_months(m,n) ;//在指定的月数加多少月
//查询入职多少天    ,hiredate表示入职的年份
select trunc(sysdate-hiredate)  as "入职天数" from emp;
last_day(d)  //一个月的最后一天
select	hiredate,last_day(hiredate) as "月天数" from emp'
to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') //比如等于2012-05-31 21:39:03
to_char(sysdate,'yyyy-mm-dd hh:mi:ss') //比如等于2012-05-31 09:39:03
//显示本国货币,中国就是RMB ,99999.99表示最长5位整数,2位小数
to_char(money,'L99999.99');
//显示本国货币,中国就是RMB ,99999.99表示最长5位整数,2位小数,并且每三位以,分隔
to_char(money,'L999,99.99'); 
to_char(date,'yyyy')=2012;//表示要得到的年份要等于2012
to_char(date,'mm')=09;//表示要得到的月份要等于09
 

猜你喜欢

转载自javaeedevelop.iteye.com/blog/1544504