Oracle中常用的函数

开发用到的oracle函数,不断更新
1、instr

instr函数返回要截取的字符串在源字符串中的位置。只检索一次,就是说从字符的开始到字符的结尾就结束。

instr( string1, string2 [, start_position [, nth_appearance ] ] )
string1 源字符串,要在此字符串中查找。
string2 要在string1中查找的字符串.
start_position 代表string1 的哪个位置开始查找。此参数可选,如果省略默认为1. 字符串索引从1开始。如果此参数为正,从左到右开始检索,如果此参数为负,从右到左检索,返回要查找的字符串在源字符串中的开始索引。
nth_appearance 代表要查找第几次出现的string2. 此参数可选,如果省略,默认为 1.如果为负数系统会报错。

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

select instr('China','na') from dual; --返回4
select * from bd_site bs  where instr('1234',TYPE) > 0


2、nvl

NVL( string1, replace_with)
功能:如果string1为NULL,则NVL函数返回replace_with的值,否则返回string1的值。

select nvl('sfds1','sfds')  from bd_site; --返回'sfds1'
select nvl(null,'sfds')  from bd_site;    --返回'sfds'


3、decode

条件匹配返回值

DECODE(条件,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)
条件值为值1时,返回翻译值1...值2时,返回翻译值2。。。无匹配时,返回缺省值

select decode(606,606,'a',607,'b','c') from bd_site ; --返回'a'

4、to_char

to_char(timestamp,text)
将timestamp以text格式转化成字符串

select to_char(sysdate,'yyyy-mm-dd') from dual;

猜你喜欢

转载自wy649898543.iteye.com/blog/1449881