码迷,mamicode.com
首页 > 数据库 > 详细

sql语句 字符函数,数字函数

时间:2017-10-04 11:37:24      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:数字   截断   power   asc   pow   round   ace   开始   cat   

 1 -- 字符函数
 2 
 3 -- ASCII(X) 返回字符x 的 ASCII码
 4 select ASCII(a) FROM DUAL;    -- 返回97
 5 
 6 -- CONCAT(X,Y) 连接字符串x和y
 7 select  concat(123, 456) from dual;  -- 返回 123 456
 8 
 9 -- INSTR(X,str [,start][,n) :在x中查找str,可以指定从start开始,也可以指定从第n次开始
10 select instr(hahdf,f) from dual;  -- 返回str的位置
11 
12 -- length(x) 返回x的长度
13 select length(d545) from dual;  --返回4
14 
15 -- lower(x)   将x转变为小写
16 select lower(ABCD) from dual; -- 返回abcd
17 
18 -- upper(x)  将x转变为大写
19 select upper(abcde) from dual;  -- 返回ABCDE
20 
21 -- ltrim(x,[str]) 把x的左边截去str 字符串,缺省截去空格
22 SELECT ltrim(===HELLO===, =) FROM DUAL  -- 返回  HELLO===
23 
24 
25 -- rtrim(x,[str]) 把x的右边截去str 字符串,缺省截去空格
26 SELECT rtrim(===HELLO===, =) FROM DUAL  -- 返回  ===HELLO
27 
28 -- trim([str from] x) 把x的两边截去str 字符串,缺省截去空格
29 SELECT TRIM(= FROM ===HELLO===) FROM DUAL; -- 返回  HELLO
30 
31 -- replace(x,old,new) 在x中查找old, 并替换为new
32 select replace(avaddfs,d,e) from dual; -- 返回结果avaeefs
33 
34 -- substr(x,start,[,length]) 返回x的字符串,从start处开始,
35 --截取length个字符,缺省length,默认到结尾
36 select substr(abcdefg,2,4) from dual;--返回:bcde
37 
38 
39 -- 数学函数
40 -- abs(x) x绝对值
41 select abs(-5) from dual; -- 返回  5
42 
43 -- acos(x) x的反余弦
44 select acos(1) from dual; -- 返回0
45 
46 -- cos(x) 余弦
47 select cos(1) from dual; -- 返回0.54030230586814
48 
49 -- ceil(x) 大于或等于x的最小值
50 select ceil(5.2) from dual; -- 返回6
51 
52 --floor(x) 小于或等于x的最大值
53 select floor(5.2) from dual; -- 返回5
54 
55 
56 --  log(x,y) x为低y的对数
57 select log(2,2) from dual; -- 返回1
58 
59 --  mod(x,y) x除以y的余数
60 select mod(2,3) from dual; -- 返回2
61 
62 --  power(x,y) x的y次幂
63 select power(2,3) from dual; -- 返回8
64 
65 -- round(x[,y])  x在第y位四舍五入 
66 --y默认为0,如果y为负数,小数点右边截补0 ,如果y为正数,小数点左边截 ,
67 select round(2.2160,2) from dual; -- 返回2.22
68 
69 -- sqrt(x)  x的平方根
70 select sqrt(4) from dual; -- 返回2
71 
72 -- trunc(x[,y]) x在第y位截断; 不四舍五入。
73 --y默认为0,如果y为负数,小数点右边截补0 ,如果y为正数,小数点左边截 ,
74 select trunc(334.255,-1) from dual; -- 返回330

 

sql语句 字符函数,数字函数

标签:数字   截断   power   asc   pow   round   ace   开始   cat   

原文地址:http://www.cnblogs.com/GreenCode/p/7624926.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!