1,字符串函数。
转大小写操作:
select upper('hello') from dual;
select lower(ename) from emp;
select * from emp where
ename=upper('&inputname');
首字母大写操作:
select ename ,initcap(ename)from emp;
取得字符串的长度:
select * from emp where length(ename)=5;
字符串的截取:
select substr('helloworld',6)from dual;
select substr('helloworld',0,5)from dual;
截取雇员姓名的前三位:
select ename ,substr(ename,1,3)from emp;
截取雇员姓名的后三位:
select ename
,substr(ename,length(ename)-2,3)from emp;
select ename ,substr(ename,-3)from emp;
2,数值函数。
四舍五入操作:
select round(78.2352423,2)from dual;
select round(78.9992423,-2)from dual;
数据截取操作:
select trunc(78.9992423,2)from dual;
求模操作:
select mod(10,3)from dual;
3,日期函数。
验证时间伪列:
select
sysdate from dual;
select systimestamp from dual;
要求查询每个雇员的编号、姓名、职位、已经被雇佣的天数:
select empno,ename,job,sysdate-hiredate from
emp;
增加指定的月份:
select add_months(sysdate,4) from dual;
计算出所有雇员到今天为止雇佣的月数:
select empno,ename,hiredate,months_between(sysdate,hiredate)from
emp;
要求查询出所有在雇佣所在月倒数第三天雇佣的雇员信息:
select
empno,ename,hiredate,last_day(hiredate)-2 from emp
where hiredate=last_day(hiredate)-2;
验证next_day:
select next_day(sysdate,'星期二')from
dual;
4,转换函数。
select to_char(sysdate,'yyyy-mm-dd')from
dual;
select to_char(sysdate,'yyyy-mm-dd
hh24:mi:ss')from dual;
要求查询出所有在2月雇佣的员工:
select *from emp where
to_char(hiredate,'mm')='02';
select *from emp where
to_char(hiredate,'mm')=2;
拆分数字:
select to_char(3453523452,'L999,999,999,999,999')from
dual;
5,通用函数。
- 处理null:
select
empno,ename,sal,comm,(sal+nvl(comm,0))*12 from emp;
decode()函数:
select ename,job,decode(job,'CLERK','办事员')from
emp;