设为首页 收藏本站
查看: 496|回复: 0

[经验分享] Oracle的几个函数的用法。

[复制链接]

尚未签到

发表于 2016-7-29 11:28:31 | 显示全部楼层 |阅读模式
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  

 

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-251167-1-1.html 上篇帖子: 转载:ORACLE 中ROWNUM用法总结 下篇帖子: Oracle中start with...connect by递归
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表