1、round 四舍五入 select round( number, [ decimal_places ] ) from dual参数:number : 欲处理之数decimal_places : 四舍五入 , 小数取几位 ( 预设为 0 ) sample :select round(123.456, 0) from dual; 回传 123 select round(123.456, 1) from dual; 回传
1、round 四舍五入
select round( number, [ decimal_places ] ) from dual参数:number : 欲处理之数值decimal_places : 四舍五入 , 小数取几位 ( 预设为 0 )
sample :select round(123.456, 0) from dual; 回传 123 select round(123.456, 1) from dual; 回传 123.5 select round(123.456, 2) from dual; 回传 123.46 select round(123.456, 3) from dual; 回传 123.456 select round(-123.456, 2) from dual; 回传 -123.46
2、 --oracle trunc()函数的用法
/**************日期********************/
1.select trunc(sysdate) from dual --2011-3-18 今天的日期为2011-3-18
2.select trunc(sysdate, 'mm') from dual --2011-3-1 返回当月第一天.
3.select trunc(sysdate,'yy') from dual --2011-1-1 返回当年第一天
4.select trunc(sysdate,'dd') from dual --2011-3-18 返回当前年月日
5.select trunc(sysdate,'yyyy') from dual --2011-1-1 返回当年第一天
6.select trunc(sysdate,'d') from dual --2011-3-13 (星期天)返回当前星期的第一天
7.select trunc(sysdate, 'hh') from dual --2011-3-18 14:00:00 当前时间为14:41
8.select trunc(sysdate, 'mi') from dual --2011-3-18 14:41:00 trunc()函数没有秒的精确
/***************数字********************/
/*
trunc(number,num_digits)
number 需要截尾取整的数字。
num_digits 用于指定取整精度的数字。num_digits 的默认值为 0。
trunc()函数截取时不进行四舍五入
*/
9.select trunc(123.458) from dual --123
10.select trunc(123.458,0) from dual --123
11.select trunc(123.458,1) from dual --123.4
12.select trunc(123.458,-1) from dual --120
13.select trunc(123.458,-4) from dual --0
14.select trunc(123.458,4) from dual --123.458
15.select trunc(123) from dual --123
16.select trunc(123,1) from dual --123
17.select trunc(123,-1) from dual --120
oracle截取字符串和查找字符串
oracle 截取字符(substr),检索字符位置(instr) case when then else end语句使用 收藏 常用函数:substr和instr1.substr(string,start_position,[length]) 求子字符串,返回字符串解释:string 元字符串 start_position 开始位置(从0开始) length 可选项,子字符串的个数for example:substr(abcdefg, 0); //返回:abcdefg,截取所有字符 substr(abcdefg, 2); //返回:cdefg,截取从c开始之后所有字符 substr(abcdefg, 0, 3); //返回:abc,截取从a开始3个字符 substr(abcdefg, 0, 100); //返回:abcdefg,100虽然超出预处理的字符串最长度,但不会影响返回结果,系统按预处理字符串最大数量返回。 substr(abcdefg, -3); //返回:efg,注意参数-3,为负值时表示从尾部开始算起,字符串排列位置不变。
2.instr(string,substring,position,ocurrence)查找字符串位置解释:string:源字符串 substring:要查找的子字符串 position:查找的开始位置 ocurrence:源字符串中第几次出现的子字符串for example:instr('corporate floor','or', 3, 2)中,源字符串为'corporate floor', 目标字符串为'or',起始位置为3,取第2个匹配项的位置;返回结果为 14 '