is null 判读一个数据是否为空
is not null 判断一个数据是否不为空
聚组函数
max();
min();
sum();
avg();
count();
与group by连用
select max(sal),min(sal),sum(sal),avg(sal),count(name) from EMP
单行函数
random();
select random(3.1415926,3) from dual;
取三位小数,并且按照四舍五入
trunc();
select trunc(3.1415926) from dual;
截断,取整数 3
select trunc(3.1415926,3) from dual;
截断三位小数 3.141
转换函数
to_char()
将数值型数据转换成字符串类型
select to_ char(sal) from EMP;
将日期型数据转换成字符型,取出指定的时间类型
select to_char(sysdate,’yyyy’) from dual;
to_date()
将字符串类型的时间转换成日期
select to_char(‘20150819135040’,’yyyy-mm-dd hh24:mi:ss ’) from dual;
to_number()
将字符型数据转换成数据型
select to_number(sal) from dual;
字符函数
upper() 将字符串全部转换成大写
select upper(name) from dual;
lower() 将字符串全部转换成小写
select lower(name) from dual();
initcap() 将字符串的首字母转换成大写
select initcap(name) from dual;
replace(原字符串,想要替换的字符串,想要被替换成的字符串)
select replace(‘woishizhizhuxia’,’h’,’s’) from dual;
substr(原字符串,从哪里开始截取,截取几个)
select substr(‘woshizhizhuxia’,0,3) from dual;
instr(原字符串,想要搜索的字符串,从哪里开始搜索,寻找的第几个)
select instr(‘woshizhizhuxia’,’h’,0,2) from dual;
日期函数
yyyy 年
mm 月
ddd 一年中的第几天
dd 一个月中第几天
d 一周的第几天
hh24 24小时制的小时
hh12 12小时制的小时
mi 分钟
ss 秒
xff 毫秒数
ffs 毫秒数三位
add_months();在当前增加相应月数
select add_months(sysdate,3) from dual;
months_between();计算两个月之间的月数
select months_between(sysdate,hiredate) from dual;
last_day();求出相应日期数的最后一天
select last_day(hiredate) from dual;
next_day();求出下一周的时间
select next_day(sysdate’星期三’) from dual;
通用函数
nvl(原字符串,为空情况下展示什么)
select nvl(comm+sal,sal) from EMP
nvl2(原字符串,不为空的情况下展示什么,为空的情况下展示什么)
select nvl(comm+sal,comm+sal,sal) from EMP
decode(a,b,c,d,e,f)
(case when then else end)