Oracle的函数

Oracle的函数

nvl()

函数的格式如下:
NVL(expr1,expr2);
含义如下:
如果第一个参数为空,那么显示第二个参数的值
如果第一个参数的值不为空,则显示第一个参数本来的值。

exists()

函数的格式如下:
select * from T1 where exists(select 1 from T2 where T1.a=T2.a);
含义如下:
EXISTS用于检查子查询是否返回至少一行数据,该子查询实际上并不返回任何数据,而是返回truefalse。
注意事项:
 	T1数据量小而T2数据量非常大时,查询效率高。
 	反之用:
 	select * from T1 where T1.a in (select T2.a from T2) ;
 	效率高

TRUNC()

针对数字的案例,如:

select trunc(123.458) from dual --123

select trunc(123.458,0) from dual --123

select trunc(123.458,1) from dual --123.4

select trunc(123.458,-1) from dual --120

select trunc(123.458,-4) from dual --0

select trunc(123.458,4) from dual --123.458

select trunc(123) from dual --123

select trunc(123,1) from dual --123

select trunc(123,-1) from dual --120

针对日期的案例,如:

select trunc(sysdate) from dual --2017/6/13  返回当天的日期

select trunc(sysdate,'yyyy') from dual   --2017/1/1  返回当年第一天.

select trunc(sysdate,'mm') from dual  --2017/6/1  返回当月第一天.

select trunc(sysdate,'d') from dual  --2017/6/11 返回当前星期的第一天(以周日为第一天).

select trunc(sysdate,'dd') from dual  --2017/6/13  返回当前年月日

select trunc(sysdate,'hh') from dual  --2017/6/13 13:00:00  返回当前小时

select trunc(sysdate,'mi') from dual  --2017/6/13 13:06:00  返回当前分钟

decode()

//第一种形式
decode(条件,1,返回值1,2,返回值2,…值n,返回值n,缺省值)
//第二种形式
decode(字段或字段的运算,值1,值2,值3

查询前后30天数据

select * from 表名 where 时间字段 between to_date(sysdate-15,'yyyy-mm-dd') and to_date(sysdate+15,'yyyy-mm-dd');

查询前30天数据

select * from 表名 where 时间字段 between  to_date(sysdate-30,'yyyy-mm-dd') and to_date(sysdate,'yyyy-mm-dd');

查询后30天数据

select * from 表名 where 时间字段 between  to_date(sysdate,'yyyy-mm-dd') and to_date(sysdate+30,'yyyy-mm-dd');
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值