SQL必知必会-08

使用函数处理数据

函数

SQL可以通过函数来处理函数,但是,大多数函数不能被不同的DBMS共用,也就是移植性不高。

使用函数

文本处理函数

将文本全部变为大写的函数:upper()

eg: select vend_name, upper(vend_name) as vend_name_upcase from Vendors orderby vend_name;

常用的文本处理函数

left()      返回字符串左边的字符

right()      返回字符串右边的字符

lengtth()     返回字符串的长度

lower()      将字符串转化为小写

upper()      将字符串转化为大写

ltrim()      去掉字符串左边的空格

rtrim()      去掉字符串右边的空格

soundex()     返回字符串的soundex值

使用soundex函数

eg:select cust_name , cust_contact from customers where soundex(cust_contact) = soundex('michael green');搜索发音和michael green相似的行。

日期和时间处理函数

在SQL server中时间函数是 datepart(yy, '2019-09-04')

oracle中时间函数常用to_date()或者使用to_char来改变时间的格式。

MySQL中可以使用year()等函数。

数值处理函数

常用数值函数

abs()    返回一个数的绝对值

cos()    返回一个角度的余弦

exp()    返回一个数的指数值

pi()     圆周率

sin()    返回值个角度的正弦

sqrt()    返回一个数的平方根

tan()    返回一个角度的正切

      

猜你喜欢

转载自www.cnblogs.com/sunshine-2018/p/11456889.html