-- 常用系统函数(一)
select initcap('hello') from dual;
select lower('FUN') from dual;
select upper('sun') from dual;
-- 从左边开始删除
select ltrim('xyzadams','xyz') from dual;
-- 从右边开始删除
select rtrim('xyzadams','adams') from dual;
-- 替换函数
select translate('jack','j','b') from dual;
-- 每个都替换掉了
select replace('jack','j','b') from dual;
-- substr(),中如果是负值,则倒着往回数。
select substr('abcdef',-2,2) from dual;
select concat('Hello',' World') from dual;
-- 获取当前的前后的月份
select add_months(sysdate,-12) from dual;
select sysdate from dual;
select last_day(sysdate) from dual;
-- 四舍五入
select round(sysdate,'month') from dual;
-- 从给定日期取出
select * from employee;、
-- 找出这个字符出现的位置
select instr('abcdef','c') from dual;
select chr(56) from dual;
select lpad('abcde',10,'ww') from dual;
select rpad('abcde',10,'ww') from dual;
select trim(trailing '半' from '半夜二更半') as 诗 from dual;
select trim(leading '半' from '半夜二更半') as 诗 from dual;
select trim('半' from '半夜二更半') as 诗 from dual;
-- 相当与case when 语句
select eno,ename,job,sal,
decode(job,'职员',sal*1.5,'销售员',sal*2,'经理',sal*3,sal)
"new_sal" from employee;
select eno,ename,job,sal
from employee;
-- 常用系统函数(二)
-- 数字函数
select ceil(44.78) from dual;
select floor(100.2) from dual;
-- 求余数
select mod(10,3) from dual;
-- 舍入小数函数(四舍五入)
select round(1123.456,2) from dual;
-- 返回正负值
select sign(-10) from dual;
-- 转换函数
select to_char(sal,'C99999') from employee;
select to_date('2009-03-11','yyyy-mm-dd')
from dual;
--其他函数
-- nullif() nvl(exp1,exp2) 如果是空,返回exp2,反之返回exp1
nvl(sal,0) 如果是sal是空,则返回0,不是空时,返回sal。
-- nvl(exp1,exp2,exp3) 如果exp1是空,返回exp2,不是空返回exp3
--分组函数
select avg(sal) from employee;
-- 分析函数(窗口函数)
select * from employee;
-- 返回连续的排名
row_number() over(order by sal desc)
-- 相同值行排位相同,序号是跳跃的
rank() over(partition by deptno order by sal desc)
-- 相同值行排位相同,序号是连续的
dense_rank() over(partition by deptno order by sal desc)
rder by sal desc)
– 相同值行排位相同,序号是连续的
dense_rank() over(partition by deptno order by sal desc)