现在的位置: 首页 > 综合 > 正文

字符函数操作

2014年01月24日 ⁄ 综合 ⁄ 共 1013字 ⁄ 字号 评论关闭

--数据库中是从1开始 下标
--去掉null  0
select sal,comm,sal+nvl(comm,0) "实际工资" from emp;
--小数点 向上取 正数向后  负数向前
select round(6666.6666,2) from dual;
--直接去掉
select trunc(5555.55555,2) from dual;
--截取字符串 n从几位开始 m取几位 
select substr('holle word',n,m) from dual;
 --从左边对齐 n位数 m 代替字符
 select lpad(ename,n,m) from emp;
 --去掉字符 只能是首 尾
 select trim(' d s ') from dual;
 --指定去掉字符 前 
 select trim(leading 'a' from 'abcaa') from dual; 
 --后
 select trim(trailing'a' from 'abcaa') from dual; 
 
--时间 函数转换  距离几个月
select months_between(date'2014-5-5',sysdate) from dual;
--距离指定时间 相差天数
select date'2014-2-14'-sysdate from dual;
--求前面几个月的今天
select add_months(sysdate,-3) from dual;
--指定 年 月 日 查询
select next_day(sysdate, '星期一') from dual;
select round(sysdate, 'MONTH') from dual;
select trunc(sysdate, 'year') from dual;
--cast强制转换
select 5+cast('55' as number(2)) from dual;
--查询指定时间
select to_char(sysdate,'fm yyyy"年"mm"月"dd"日" day hh24 pm ') from dual;
--DDL、DCL自动提交;但DML不会自动提交(只是本会话可见)
--排序状态 相同的值 不同的排法
select sal,row_number() over(order by sal desc), 
      rank() over(order by sal desc),
      dense_rank() over(order by sal desc)
from emp;
--decode判断函数 给值 相当与 case when then 
select decode 

抱歉!评论已关闭.