Oracle的几个函数的用法。

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

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

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

4.Coalesce
函数 
  Coalesce(expr1, expr2, expr3….. exprn) 
 
一句话就是显示第一个不为空的参数。如果全部为空则返回空. 

 

<!--[if !supportLists]-->1.  <!--[endif]-->4.INITCAP  

<!--[if !supportLists]-->2.  <!--[endif]-->返回字符串并将字符串的第一个字母变为大写;  

<!--[if !supportLists]-->3.  <!--[endif]-->SQL> select initcap('smith') upp from dual; 

 

 

<!--[if !supportLists]-->1.  <!--[endif]-->5.INSTR(C1,C2,I,J)  

<!--[if !supportLists]-->2.  <!--[endif]-->在一个字符串中搜索指定的字符,返回发现指定的字符的位置;  

<!--[if !supportLists]-->3.  <!--[endif]-->C1    被搜索的字符串  

<!--[if !supportLists]-->4.  <!--[endif]-->C2    希望搜索的字符串  

<!--[if !supportLists]-->5.  <!--[endif]-->I     搜索的开始位置,默认为1  

<!--[if !supportLists]-->6.  <!--[endif]-->J     出现的位置,默认为1  

<!--[if !supportLists]-->7.  <!--[endif]-->SQL> select instr('oracle traning','ra',1,2) instring from dual;  

<!--[if !supportLists]-->8.  <!--[endif]-->  

<!--[if !supportLists]-->9.  <!--[endif]--> INSTRING  

<!--[if !supportLists]-->10.<!--[endif]-->---------  

<!--[if !supportLists]-->11.<!--[endif]-->        9  

 

 

<!--[if !supportLists]-->1.  <!--[endif]-->13.SOUNDEX  

<!--[if !supportLists]-->2.  <!--[endif]-->返回一个与给定的字符串读音相同的字符串  

<!--[if !supportLists]-->3.  <!--[endif]-->SQL> create table table1(xm varchar(8));  

<!--[if !supportLists]-->4.  <!--[endif]-->SQL> insert into table1 values('weather');  

<!--[if !supportLists]-->5.  <!--[endif]-->SQL> insert into table1 values('wether');  

<!--[if !supportLists]-->6.  <!--[endif]-->SQL> insert into table1 values('gao');  

<!--[if !supportLists]-->7.  <!--[endif]-->  

<!--[if !supportLists]-->8.  <!--[endif]-->SQL> select xm from table1 where soundex(xm)=soundex('weather');  

<!--[if !supportLists]-->9.  <!--[endif]-->  

<!--[if !supportLists]-->10.<!--[endif]-->XM  

<!--[if !supportLists]-->11.<!--[endif]-->--------  

<!--[if !supportLists]-->12.<!--[endif]-->weather  

<!--[if !supportLists]-->13.<!--[endif]-->wether  

 

 

 

<!--[if !supportLists]-->1.  <!--[endif]-->14.TRIM('s' from 'string')  

<!--[if !supportLists]-->2.  <!--[endif]-->LEADING   剪掉前面的字符  

<!--[if !supportLists]-->3.  <!--[endif]-->TRAILING  剪掉后面的字符  

<!--[if !supportLists]-->4.  <!--[endif]-->如果不指定,默认为空格符

 

 

<!--[if !supportLists]-->1.  <!--[endif]-->26.MOD(n1,n2)  

<!--[if !supportLists]-->2.  <!--[endif]-->返回一个n1除以n2的余数  

<!--[if !supportLists]-->3.  <!--[endif]-->SQL> select mod(10,3),mod(3,3),mod(2,3) from dual;  

<!--[if !supportLists]-->4.  <!--[endif]-->  

<!--[if !supportLists]-->5.  <!--[endif]-->MOD(10,3)  MOD(3,3)  MOD(2,3)  

<!--[if !supportLists]-->6.  <!--[endif]-->--------- --------- ---------  

<!--[if !supportLists]-->7.  <!--[endif]-->        1         0         2 

 

 

<!--[if !supportLists]-->1.  <!--[endif]-->27.POWER  

<!--[if !supportLists]-->2.  <!--[endif]-->返回n1n2次方根  

<!--[if !supportLists]-->3.  <!--[endif]-->SQL> select power(2,10),power(3,3) from dual;  

<!--[if !supportLists]-->4.  <!--[endif]-->  

<!--[if !supportLists]-->5.  <!--[endif]-->POWER(2,10) POWER(3,3)  

<!--[if !supportLists]-->6.  <!--[endif]-->----------- ----------  

<!--[if !supportLists]-->7.  <!--[endif]-->       1024         27 

 

 

<!--[if !supportLists]-->1.  <!--[endif]-->28.ROUNDTRUNC  

<!--[if !supportLists]-->2.  <!--[endif]-->按照指定的精度进行舍入  

<!--[if !supportLists]-->3.  <!--[endif]-->SQL> select round(55.5),round(-55.4),trunc(55.5),trunc(-55.5) from dual;  

<!--[if !supportLists]-->4.  <!--[endif]-->  

<!--[if !supportLists]-->5.  <!--[endif]-->ROUND(55.5) ROUND(-55.4) TRUNC(55.5) TRUNC(-55.5)  

<!--[if !supportLists]-->6.  <!--[endif]-->----------- ------------ ----------- ------------  

<!--[if !supportLists]-->7.  <!--[endif]-->         56          -55          55          -55  

 

<!--[if !supportLists]-->1.  <!--[endif]-->58.USER  

<!--[if !supportLists]-->2.  <!--[endif]-->返回当前用户的名字  

<!--[if !supportLists]-->3.  <!--[endif]-->SQL> select user from  dual;  

<!--[if !supportLists]-->4.  <!--[endif]-->  

 

 1.  29.SIGN  

<!--[if !supportLists]-->2.  <!--[endif]-->取数字n的符号,大于0返回1,小于0返回-1,等于0返回0  

<!--[if !supportLists]-->3.  <!--[endif]-->SQL> select sign(123),sign(-100),sign(0) from dual;  

<!--[if !supportLists]-->4.  <!--[endif]-->  

<!--[if !supportLists]-->5.  <!--[endif]-->SIGN(123) SIGN(-100)   SIGN(0)  

<!--[if !supportLists]-->6.  <!--[endif]-->--------- ---------- ---------  

<!--[if !supportLists]-->7.  <!--[endif]-->        1         -1         0  

 

猜你喜欢

转载自xiaoxie.iteye.com/blog/1833112