oracle 常用函数
-------------------------------字符函数 -------lower小写、upper大写、原本形式 select lower(ename),upper(ename),ename from emp; -------名字length长度等于5的 select ename from emp where length(ename) = 5; -------substr截取字符串,从1开始,长度为3 select subStr(ename,1,3) from emp; ------instr(a,b,c,d)函数,a是查找范围,b是要查找的字符串,c是起始位置,d是第几次出现 select ename from emp where instr(ename,'M',1,1)<>0 and instr(ename,'S',1,1)<>0; -------||为连接字符串的操作符 select upper(substr(ename,1,1))||lower(substr(ename,2,length(ename)-1)) from emp; select replace(ename,'A','替换') from emp; -------------------------------数学函数 -------负数取小数点以前位数,正数取小数点后的位数,四舍五入 select round(sal,-3),round(sal,3),sal from emp; -------负数为截取小数点以前位数,正数为截取小数点后的位数 select trunc(sal,-2),trunc(sal,1),sal from emp; -------floor向下取整,ceil向上取整 select floor(sal),ceil(sal),sal from emp; -------mod 取余 select mod(10,2),mod(10,3) from dual; ------------------------------日期函数 -------sysdate当前系统时间 select sysdate from dual; ----add_months,添加月数 select * from emp t where sysdate>add_months(t.hiredate,310) -----查询入职日期是当月倒数第3天的员工 select * from emp t where t.hiredate = last_day(t.hiredate)-2;--每月倒数第三天入职 -----------------日期类型也可以直接加减 select sysdate - hiredate,ename from emp; ------to_char函数 select ename,to_char(sal,'$99999.99'),to_char(hiredate,'mm') from emp; ------系统函数sys_context('userenv','') 第二个参数可以是: db_name,session_user,host,db_name,current_schema select sys_context('userenv','db_name') from dual;