数据库的select语句以及一些简单函数
- 数据库的select语句以及一些简单函数
--desc 降序 --asc 升序 select * from emp order by sal desc; select * from emp order by sal asc; --upper,lower,大小写 select upper(ename) from emp; select lower(ename) from emp; --initcap首字母大写 select initcap('acbd') from dual; --Acbd --concat连接 Select concat('a','b')from dual; --ab select 'a' || 'b' from dual; --ab --substr截取字符串,2索引位置,3输出长度 select substr('abcde',2,3) from dual; --bcd --replace(替换,S=需要替换的内容,sss=用来替换的内容) select replace(ename,'S','sss') from emp; --instr 返回字符串b在a中出现的索引位置 select instr('abcdefghijklmnopqrstuvwxyz','mnop')from dual; --Lpad,Rpad,左/右侧填充,10=填充后的总长度,*=填充的字符 select lpad('abc',10,'*') from dual; --*******acb select rpad('abc',10,'*') from dual; --abc******* --round 四舍五入 select round(418,-2)from dual; select round(412.363,2)from dual; --trunc 截断,-1为小数点向左一位截断,如果是正数(如1,是向右保留一位) select trunc(412.13,-1) from dual; --410 select trunc(412.1314,3) from dual; --412.131 --mod 取余 select mod(412.13,100) from dual; --12.13 select mod(13,12) from dual; --1 --months_between 返回一个值,如果左边日期比右边日期早返回正数,否则负数,刚好是一个月的倍数返回值为整数 select months_between('4-2月-2017','4-8月-2017') from dual; --add_months() 为指定日期的月份增加x select add_months('3-12月-2017',3)from dual; --next_day() 返回以sysdate为对象的下一个星期四的日期(如果sys是星期4则也返回下个星期四的日期) select next_day('3-12月-2017','星期一') from dual; --last_day() 返回以指定日期在那个月份的最后一天 select last_day('17-12月-88') from dual; --to_char() select to_char(sysdate,'fmyyyy-mm-dd,d,hh:mm:ss')from dual; --fmyyyy-mm-dd,d,hh:mm:ss 时间格式,分别代表年-月-日,星期,时:分:秒 select to_char(sal,'L9,999')from emp; --L=¥,每三位加一个,分隔 --to_number() 转换数字 select to_number('13')+to_number('14') from dual; --字符串转换数字 --to_date() 转换日期 select to_date('090209','ddmmyy') from dual; --NVL() 如果所在列有值返回值,无值返回0 select * from emp; select nvl(comm,0)from emp; select * from emp where hiredate = last_day(hiredate)-2; select * from emp where hiredate <= add_months(sysdate,-25*12) select 'Dear '||initcap(ename) as ename from emp; select initcap(ename) as Ename from emp where length(ename) = 5; select * from emp where ename not like '%R%'; select ename,sal from emp order by ename desc; select * from (select * from emp order by sal asc) order by ename desc; select ename,round(sal/30,0) from emp; select * from emp where to_char(hiredate,'fmdd')='20' select ename,round(months_between(sysdate,hiredate)*30,-1) from emp;
posted on 2017-07-14 09:06 string9527 阅读(577) 评论(0) 收藏 举报
浙公网安备 33010602011771号