您的位置:首页 > 数据库

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: