加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle数据库函数总结

发布时间:2020-12-12 16:45:11 所属栏目:百科 来源:网络整理
导读:1、ceil()向上取整,结果为124。select ceil(123.123) from dual;2、floor()向下取整,结果为123。select floor(123.123) from dual;3、trunc(n1,n2)取整函数,n1代表字符串,n2代表小数位数,结果为123.12。select trunc(123.125,2) from dual;4、round(n1,n

1、ceil()向上取整,结果为124。select ceil(123.123) from dual;2、floor()向下取整,结果为123。select floor(123.123) from dual;3、trunc(n1,n2)取整函数,n1代表字符串,n2代表小数位数,结果为123.12。select trunc(123.125,2) from dual;4、round(n1,n2)四舍五入,n1代表字符串,n2代表小数位数,结果为123.57。select round(123.567) from dual;5、lower()将字符串转化为小写,结果为abc。select lower(‘ABC’) from dual;6、upper()将字符串转化为大写,结果为ABC。select upper(‘abc’) from dual;7、字符串拼接,结果为 ‘Hello,小明’。详细:select concat(‘Hello’,’,小明’) from dual;

8、时间是12小时制,结果2018-07-06 05:07:20select to_char(sysdate,’yyyy-mm-dd hh:mm:ss’) from dual;9、时间是24小时制,结果2018-07-06 17:07:33select to_char(sysdate,’yyyy-mm-dd hh24:mm:ss’) from dual;10、时间是带上下午的12小时制,结果2018-07-06 下午05:07:03select to_char(sysdate,’yyyy-mm-dd pmhh:mm:ss’) from dual;11、时间是带上下文的24小时制,结果2018-07-06 下午17:07:49select to_char(sysdate,’yyyy-mm-dd pmhh24:mm:ss’) from dual;

12、格式化日期,结果为25-4月 -17select to_date(‘2017-04-25’,’yyyy-mm-dd’)from dual;—格式化日期

13、count()函数,统计一共有多少条数据,假如表中有20条数据,count()结果则为20。select count(*) from table_name;14、min(),查询列的最小值。15、max(),查询列的最大值。16、avg(),查询列平均数。17、sum(),查询列的总和,只能是数值型。18、mod(n1,n2),n1/n2 求余数。结果2。select mod(2,3)from dual;

19、substr(n1,n2,n3) n1是截取的字符串,n2开始截取位置,n3是截取多少位 结果是321select substr(‘13122123456’,2,3) from dual;20、substring(n1,n3) n1是截取的字符串,n2开始下标,n3结束下标 结果是122select substr(‘13122123456’,5) from dual;21、decode()函数判断,sex为0则显示女,1则显示男,其他显示未知select decode(sex,’女’,1,’男’,’未知’) from student;

22、nvl(n1,n2)函数,n1为空则显示n2,不为空则显示n1值。n2值可自己根据需要设置select nvl(n1,n2) from table_name;23、nvl2(n1,n3)函数,n1为空则显示n3,不为空则显示n2。select nvl2(n1,n3) from table_name;

24、fn_getpy()函数,汉字进行拼音转换。select fn_getpy(‘鲁智深’,0) from dual; 结果:luzhishenselect fn_getpy(‘鲁智深’) from dual; 结果:luzhishenselect fn_getpy(‘鲁智深’,1) from dual; 结果:LUZHISHENselect fn_getpy(‘鲁智深’,2) from dual; 结果:LuZhiShenselect fn_getpy(‘鲁智深’,3) from dual; 结果:lzsselect fn_getpy(‘鲁智深’,4) from dual; 结果:LZS

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读