Oracle中关于处理小数点位数的几个函数,取小数位数,Oracle查询函数

关于处理小数点位数的几个oracle函数()
1. 取四舍五入的几位小数
select round(1.2345, 3) from dual;
结果:1.235
2. 保留两位小数,只舍
select trunc(1.2345, 2) from dual;
结果:1.23

select trunc(1.2399, 2) from dual;

结果:1.23
3.取整数
返回大于或等于x的最大整数:
SQL> select ceil(23.33) from dual;
结果: 24

返回等于或小于x的最大整数:
SQL> select floor(23.33) from dual;
结果: 23

返回舍入到小数点右边y位的x值:rcund(x,[y])
SQL> select round(23.33) from dual;
结果: 23

返回截尾到y位小数的x值:trunc(x,[y])
SQL> select trunc(23.33) from dual;
结果: 23

格式化数字

 The following are number examples for the to_char function.

  to_char(1210.73, '9999.9') would return '1210.7'
  to_char(1210.73, '9,999.99') would return '1,210.73'
  to_char(1210.73, '$9,999.00') would return '$1,210.73'
  to_char(21, '000099') would return '000021'

to_char函数特殊用法
  to_char(sysdate,'d') 每周第几天
  to_char(sysdate,'dd') 每月第几天
  to_char(sysdate,'ddd') 每年第几天
  to_char(sysdate,'ww') 每年第几周
  to_char(sysdate,'mm') 每年第几月
  to_char(sysdate,'q') 每年第几季
  to_char(sysdate,'yyyy') 年
  比如要找某个时间为每周第几天就可以
  SQL> select to_char(to_date('20070101','yyyymmdd'),'d') from dual;

1.instr

在Oracle/PLSQL中,instr函数返回要截取的字符串在源字符串中的位置。

语法如下:instr( string1, string2 [, start_position [, nth_appearance ] ] )

string1 源字符串,要在此字符串中查找。

string2 要在string1中查找的字符串.

start_position 代表string1 的哪个位置开始查找。此参数可选,如果省略默认为1. 字符串索引从1开始。如果此参数为正,从左到右开始检索,如果此参数为负,从右到左检索,返回要查找的字符串在源字符串中的开始索引。

nth_appearance 代表要查找第几次出现的string2. 此参数可选,如果省略,默认为 1.如果为负数系统会报错。

注意:

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

应用于:

Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g
举例说明:

select instr('abc','a') from dual; -- 返回 1
select instr('abc','bc') from dual; -- 返回 2
select instr('abc abc','a',1,2) from dual; -- 返回 5
select instr('abc','bc',-1,1) from dual; -- 返回 2
select instr('abc','d') from dual; -- 返回 0

注:也可利用此函数来检查String1中是否包含String2,如果返回0表示不包含,否则表示包含。

最新文章

  1. 【干货分享】流程DEMO-付款申请单
  2. zsh 命令提示符 PROMPT
  3. 关于小黄车(ofo共享单车)使用的问题
  4. Remoting&WebService的区别之处
  5. 杭电--1162--Eddy's picture--并查集
  6. UVA 1395 (kruskal)
  7. 关于iOS和OS X废弃的API知识点
  8. buildbot的codebaseGenerator
  9. 查看80端口被占用的方法(IIS、apmserv、system)
  10. 深入理解计算机系统第二版习题解答CSAPP 2.15
  11. Joomla安装图文教程 (送 Joomla 中文语言包)
  12. c++模板类被继承时他的成员不能被子类看到
  13. 如何在 Windows Phone 8 中获取手机的当前位置
  14. PAT (Advanced Level) 1013. Battle Over Cities (25)
  15. Combination Sum系列问题
  16. Python的语言类型
  17. JAVAEE——BOS物流项目12:角色、用户管理,使用ehcache缓存,系统菜单根据登录人展示
  18. 除了使用new关键字,还有什么方法可以创建Java对象呢?
  19. 前后端跨域 _ cross domain
  20. ubuntu 窗口操作快捷键

热门文章

  1. LeetCode——Valid Sudoku
  2. 从lca到树链剖分 bestcoder round#45 1003
  3. struts2原理分析
  4. 潜水 java类加载器ClassLoader
  5. 轻松管理您的网络password
  6. 阅读UML类图和时序图
  7. Cocos2d-x Box2D物理引擎编译设置
  8. List Set Map用法和区别
  9. state pattern
  10. ubuntu12.04硬盘安装