SQL Server 基本函数
2015-11-20 10:31
393 查看
datalength(Char_expr) 返回字符串包含字符字节数,一个汉字为两个字节,如:"abc"=3,“中华人民共和国”=14,“中华人民共和国abc”=17
len(expression)指定字符串或变量名称的长度,中文和英文字母及数字长度均为1,如“中华人民共和国”=7,“abc”=3,“中华人民共和国abc”=10。注意此时不能为length,必须为len
substring(expression,start,length) 不多说了,取子串
right(char_expr,int_expr) 返回字符串右边int_expr个字符
concat(str1,str2,...)返回来自于参数连结的字符串。
字符操作类 :
upper(char_expr) 转为大写
lower(char_expr) 转为小写
UCase(string) 返回 Variant (String),其中包含转成大写的字符串。
LCase(string) 返回字符串的小写形式。
space(int_expr) 生成int_expr个空格
replicate(char_expr,int_expr) 复制字符串int_expr次
reverse(char_expr) 反转字符串
stuff(char_expr1,start,length,char_expr2) 将字符串char_expr1中的从 start开始的length个字符用char_expr2代替
ltrim(char_expr) rtrim(char_expr) 去掉空格
ascii(char) char(ascii) 两函数对应,取ascii码,根据ascii吗取字符
字符串查找 :
charindex(char_expr,expression) 返回char_expr的起始位置
patindex("%pattern%",expression) 返回指定模式的起始位置,否则为0
locate(substr,str,pos) 返回子串substr在字符串str第一个出现的位置
2.数学函数
abs(numeric_expr) 求绝对值
ceiling(numeric_expr) 取大于等于指定值的最小整数
exp(float_expr) 取指数
floor(numeric_expr) 小于等于指定值得最大整数
power(numeric_expr,power) 返回power次方
log(float) 以e为底的对数
log10(float) 以10为底的对数
rand([int_expr]) 随机数产生器
round(numeric_expr,int_expr) 安int_expr规定的精度四舍五入
sign(int_expr) 根据正数,0,负数,,返回+1,0,-1
sqrt(float_expr) 平方根
exp(float x):求e的x次幂
tan(float x):计算x(弧度表示)的正切值。
atan(float x):求x(弧度表示)的反正切值
cos(float x):求x(弧度表示)的余弦值
acos(float x):求x(弧度表示)的反余弦值
sin(float x):计算x(弧度表示)的正弦值。
asin(float x):求x(弧度表示)的反正弦值
fabs(float x):求浮点数x的绝对值
fmod(float x, float y):计算x/y的余数
pow(float x, float y):计算x的y次幂。
sqrt(float x):计算x的平方根。
3.日期,时间函数
getdate() 返回日期
datename(datepart,date_expr) 返回名称
datepart(datepart,date_expr) 取日期一部份
datediff(datepart,date_expr1.dateexpr2) 日期差
dateadd(datepart,number,date_expr) 返回日期加上 number
len(expression)指定字符串或变量名称的长度,中文和英文字母及数字长度均为1,如“中华人民共和国”=7,“abc”=3,“中华人民共和国abc”=10。注意此时不能为length,必须为len
substring(expression,start,length) 不多说了,取子串
right(char_expr,int_expr) 返回字符串右边int_expr个字符
concat(str1,str2,...)返回来自于参数连结的字符串。
字符操作类 :
upper(char_expr) 转为大写
lower(char_expr) 转为小写
UCase(string) 返回 Variant (String),其中包含转成大写的字符串。
LCase(string) 返回字符串的小写形式。
space(int_expr) 生成int_expr个空格
replicate(char_expr,int_expr) 复制字符串int_expr次
reverse(char_expr) 反转字符串
stuff(char_expr1,start,length,char_expr2) 将字符串char_expr1中的从 start开始的length个字符用char_expr2代替
ltrim(char_expr) rtrim(char_expr) 去掉空格
ascii(char) char(ascii) 两函数对应,取ascii码,根据ascii吗取字符
字符串查找 :
charindex(char_expr,expression) 返回char_expr的起始位置
patindex("%pattern%",expression) 返回指定模式的起始位置,否则为0
locate(substr,str,pos) 返回子串substr在字符串str第一个出现的位置
2.数学函数
abs(numeric_expr) 求绝对值
ceiling(numeric_expr) 取大于等于指定值的最小整数
exp(float_expr) 取指数
floor(numeric_expr) 小于等于指定值得最大整数
power(numeric_expr,power) 返回power次方
log(float) 以e为底的对数
log10(float) 以10为底的对数
rand([int_expr]) 随机数产生器
round(numeric_expr,int_expr) 安int_expr规定的精度四舍五入
sign(int_expr) 根据正数,0,负数,,返回+1,0,-1
sqrt(float_expr) 平方根
exp(float x):求e的x次幂
tan(float x):计算x(弧度表示)的正切值。
atan(float x):求x(弧度表示)的反正切值
cos(float x):求x(弧度表示)的余弦值
acos(float x):求x(弧度表示)的反余弦值
sin(float x):计算x(弧度表示)的正弦值。
asin(float x):求x(弧度表示)的反正弦值
fabs(float x):求浮点数x的绝对值
fmod(float x, float y):计算x/y的余数
pow(float x, float y):计算x的y次幂。
sqrt(float x):计算x的平方根。
3.日期,时间函数
getdate() 返回日期
datename(datepart,date_expr) 返回名称
datepart(datepart,date_expr) 取日期一部份
datediff(datepart,date_expr1.dateexpr2) 日期差
dateadd(datepart,number,date_expr) 返回日期加上 number
相关文章推荐
- Oracle Form编译路径问题
- oracle怎样把查询的null转换为0
- 有关于DB2数据库连接的问题!
- redis 清除过期键算法流程
- mysql 5.7源码安装
- Oracle select * and rownum
- MySQL审计功能
- 4.1 SQLite 存储类型
- sqlite3 OC 提供的方法
- SQL_多条记录中取最大日期的记录
- MySQL求差集
- oracle 备份与还原 exp/imp
- pid及socket文件丢失,数据库无法启动问题
- mysql delete删除记录数据库空间不减少问题解决方法(优化表)
- MySQL升5.6引发的问题
- 一千行MySQL学习笔记
- Oracle执行计划不走索引的原因总结
- 数据库某些要注意的问题(转的,侵权删除)
- MySQL5.6新特性之GTID、多线程复制 - 不知为何
- 看了此文,Oracle SQL优化文章不必再看(转)