字符串函数
大小写转换
转大写
select upper('hello world') from dual;
转小写
select lower(ename)from emp;
首字母大写,其余字母小写
select initcap(ename)from emp;
取得字符串长度
select length('hello world')from dual;
select ename,length(ename)from emp;
替换自定字符串内容
select replace('hello world','l','_')from dual;
select replace(ename,'A','_')from emp;
字符串截取操作
select ename,substr(ename,1,3)from emp;
select ename,substr(ename,-3)from emp;
取得左右空格函数
select trim(' hello world ')from dual;
数字函数
四舍五入函数
select round(9631.6321),
round(9631.6321,2),
round(9651.6321,-2),
round(-15.5)
from dual;
截取小数函数
select trunc(9631.6321),
trunc(9631.6321,2),
trunc(9651.6321,-2),
trunc(-15.5)
from dual;
求模 (求余数)
select mod(10,3)from dual;
日期函数
SELECT SYSDATE FROM dual ;
SELECT SYSTIMESTAMP FROM dual ;
日期 + 数字 = 日期,表示若干天之后的日期;
select sysdate + 3,sysdate + 120 from dual;
日期 – 数字 = 日期,表示若干天之前的日期;
select sysdate - 120 from dual;
日期 – 日期 = 数字,表示两个日期之间的间隔天数。
select (sysdate + 6) - sysdate from dual;
转换函数
转字符串数据
select TO_CHAR(sysdate,'yyyy-mm-dd')from dual;
转数字类型
select to_number('1')+to_number('2') from dual;
select '1' + '2' from dual;
通用函数
处理null函数
select ename,sal,comm,(sal+nvl(comm,0))*12 from emp;
多数据判断
select ename,job,decode(job,'CLERK','办事员','SALESMAN','销售','MANAGER','经理','ANALYST','分析员','PRESIDENT','总裁')from emp;