`
hulu26
  • 浏览: 222940 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

oracle 函数

阅读更多
--substr 和 between and
select substr(字段1,0,8) from 表名 t where 字段2 like '%关键字%' and substr(字段1,0,8) between '20100726' and '20100802';

--oracle 日期转字符串
--12小时制(hh)  
select to_char(sysdate,'yyyy-mm-dd HH:MI:SS') from dual;
--24小时制(hh24)  
select to_char(sysdate,'yyyy-mm-dd HH24:MI:SS') from dual;

--oracle 字符串转日期
--12小时制(hh)  
select to_date('2009-5-7 07:09:37','yyyy-mm-dd HH:MI:SS') from dual;
--24小时制(hh24)  
select to_date('2009-5-7 07:09:37','yyyy-mm-dd HH24:MI:SS') from dual;

--日期比较
--字符串比较
select * from 表名 where to_char(时间类型的字段,'yyyy-mm-dd hh:mi:ss') like '2010-11-23%';
--时间比较
select * from 表名 where date类型的字段 >= to_date('2010-11-23 00:00:00','yyyy-mm-dd hh24:mi:ss');

--获得字段值的长度
select length('qqq123') from dual;

--系统时间加上一秒钟
select sysdate,sysdate+1/(24*60*60) from dual;

--查找字符
select sysdate,instr(sysdate,'-',1,2) from dual;
注:
在ORACLE/PLSQL中,instr函数返回要截取的字符串在源字符串中的位置。
语法如下:instr(str1,str2,[start_position],[nth_appearance])
str1源字符串,要在此字符串中查找。
str2要在str1中查找的字符串。
start_position代表str1的哪个位置开始查找,此参数可选,默认为1,字符串索引从1开始。如果此参数为正,从左到右开始检索,如果此参数为负,从右到左开始检索,返回要查找的字符串在源字符串的开始索引。
nth_appearance代表要查找第几次出现的str2,此参数可选,默认为1,如果为负数系统会报错。

如果str2在str1中没有找到,instr函数返回0.

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

--NVL2函数  
NVL2函数的格式如下:NVL2(expr1,expr2, expr3)
  如果该函数的第一个参数为空那么显示第三个参数的值,如果第一个参数的值不为空,则显示第二个参数的值。

--NULLIF函数  
NULLIF(exp1,expr2)
  函数的作用是如果exp1和exp2相等则返回空(NULL),否则返回第一个值

--Coalesce函数  
Coalesce(expr1, expr2, expr3….. exprn)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics