SqlServer基本函數(shù)

字號:

1.字符串函數(shù)
    長度與分析用
    datalength(Char_expr) 返回字符串包含字符數(shù),但不包含后面的空格
    substring(expression,start,length) 不多說了,取子串
    right(char_expr,int_expr) 返回字符串右邊int_expr個字符
    字符操作類
    upper(char_expr) 轉(zhuǎn)為大寫
    lower(char_expr) 轉(zhuǎn)為小寫
    space(int_expr) 生成int_expr個空格
    replicate(char_expr,int_expr)復制字符串int_expr次
    reverse(char_expr) 反轉(zhuǎn)字符串
    stuff(char_expr1,start,length,char_expr2) 將字符串char_expr1中的從
    start開始的length個字符用char_expr2代替
    ltrim(char_expr) rtrim(char_expr) 取掉空格
    ascii(char) char(ascii) 兩函數(shù)對應,取ascii碼,根據(jù)ascii嗎取字符
    字符串查找
    charindex(char_expr,expression) 返回char_expr的起始位置
    patindex("%pattern%",expression) 返回指定模式的起始位置,否則為0
    2.數(shù)學函數(shù)
    abs(numeric_expr) 求絕對值
    ceiling(numeric_expr) 取大于等于指定值的最小整數(shù)
    exp(float_expr) 取指數(shù)
    floor(numeric_expr) 小于等于指定值得整數(shù)
    pi() 3.1415926.........
    power(numeric_expr,power) 返回power次方
    rand([int_expr]) 隨機數(shù)產(chǎn)生器
    round(numeric_expr,int_expr) 安int_expr規(guī)定的精度四舍五入
    sign(int_expr) 根據(jù)正數(shù),0,負數(shù),,返回+1,0,-1
    sqrt(float_expr) 平方根
    3.日期函數(shù)
    getdate() 返回日期
    datename(datepart,date_expr) 返回名稱如 June
    datepart(datepart,date_expr) 取日期一部份
    datediff(datepart,date_expr1.dateexpr2) 日期差
    dateadd(datepart,number,date_expr) 返回日期加上 number
    上述函數(shù)中datepart的
    寫法 取值和意義
    yy 1753-9999 年份
    qq 1-4 刻
    mm 1-12 月
    dy 1-366 日
    dd 1-31 日
    wk 1-54 周
    dw 1-7 周幾
    hh 0-23 小時
    mi 0-59 分鐘
    ss 0-59 秒
    ms 0-999 毫秒
    日期轉(zhuǎn)換
    convert()
    4.系統(tǒng)函數(shù)
    suser_name() 用戶登錄名
    user_name() 用戶在數(shù)據(jù)庫中的名字
    user 用戶在數(shù)據(jù)庫中的名字
    show_role() 對當前用戶起作用的規(guī)則
    db_name() 數(shù)據(jù)庫名
    object_name(obj_id) 數(shù)據(jù)庫對象名
    col_name(obj_id,col_id) 列名
    col_length(objname,colname) 列長度
    valid_name(char_expr) 是否是有效標識符