第四章 单行函数
1.计算2000年1月1日到现在有多少月,多少周(四舍五入)。
select round(months_between(sysdate,‘01-1月-2000’))月,
round((sysdate-to_date(‘2000-01-01’,‘YYYY-MM-DD’))/7)周
from dual;
2.查询员工ENAME的第三个字母是A的员工的信息(使用2个函数)。
select *
from emp
where ename like ‘__A%’;
字符处理函数:substr 截取指定长度的字符串(从指定位置3截取1个)
select *
from emp
where substr(ename,3,1)=‘A’;
字符处理函数:inster 返回子串在字符串中出现的位置(指定位置从开始数并且指定子串第几次出现)
select *
from emp
where instr(ename,‘A’,3)=3;
3.使用trim函数将字符串‘hello’、‘ Hello ’、‘bllb’、‘ hello ’分别处理得到下列字符串ello、Hello、ll、hello。
select trim(leading ‘h’ from ‘hello’),
trim(’ Hello ‘),
trim (both ‘b’ from ‘bllb’),
trim(’ hello