1 关于处理小数点位数的几个oracle函数()
2 1. 取四舍五入的几位小数
3 select round(1.2345, 3) from dual;
4 结果:1.235
5 2. 保留两位小数,只舍
6 select trunc(1.2345, 2) from dual;
7 结果:1.23
8
9 select trunc(1.2399, 2) from dual;
10
11 结果:1.23
12 3.取整数
13 返回大于或等于x的最大整数:
14 SQL> select ceil(23.33) from dual;
15 结果: 24
16
17
18
19 返回等于或小于x的最大整数:
20 SQL> select floor(23.33) from dual;
21 结果: 23
22
23 返回舍入到小数点右边y位的x值:rcund(x,[y])
24 SQL> select round(23.33) from dual;
25 结果: 23
26
27 返回截尾到y位小数的x值:trunc(x,[y])
28 SQL> select trunc(23.33) from dual;
29 结果: 23
30
31
32 格式化数字
33
34 The following are number examples for the to_char function.
35
36
37 to_char(1210.73, '9999.9') would return '1210.7'
38 to_char(1210.73, '9,999.99') would return '1,210.73'
39 to_char(1210.73, '$9,999.00') would return '$1,210.73'
40 to_char(21, '000099') would return '000021'
41
42
43 to_char函数特殊用法
44 to_char(sysdate,'d') 每周第几天
45 to_char(sysdate,'dd') 每月第几天
46 to_char(sysdate,'ddd') 每年第几天
47 to_char(sysdate,'ww') 每年第几周
48 to_char(sysdate,'mm') 每年第几月
49 to_char(sysdate,'q') 每年第几季
50 to_char(sysdate,'yyyy') 年
51 比如要找某个时间为每周第几天就可以
52 SQL> select to_char(to_date('20070101','yyyymmdd'),'d') from dual;
53
54 1.instr
55
56
57
58 在Oracle/PLSQL中,instr函数返回要截取的字符串在源字符串中的位置。
59
60
61
62 语法如下:instr( string1, string2 [, start_position [, nth_appearance ] ] )
63
64
65
66 string1 源字符串,要在此字符串中查找。
67
68 string2 要在string1中查找的字符串.
69
70 start_position 代表string1 的哪个位置开始查找。此参数可选,如果省略默认为1. 字符串索引从1开始。如果此参数为正,从左到右开始检索,如果此参数为负,从右到左检索,返回要查找的字符串在源字符串中的开始索引。
71
72
73
74 nth_appearance 代表要查找第几次出现的string2. 此参数可选,如果省略,默认为 1.如果为负数系统会报错。
75
76
77 注意:
78
79 如果String2在String1中没有找到,instr函数返回0.
80
81
82
83 应用于:
84
85 Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g
86 举例说明:
87
88 select instr('abc','a') from dual; -- 返回 1
89 select instr('abc','bc') from dual; -- 返回 2
90 select instr('abc abc','a',1,2) from dual; -- 返回 5
91 select instr('abc','bc',-1,1) from dual; -- 返回 2
92 select instr('abc','d') from dual; -- 返回 0
93
94
95
96 注:也可利用此函数来检查String1中是否包含String2,如果返回0表示不包含,否则表示包含。