sql基本函數大全_MsSql

來源:互聯網
上載者:User
SQLServer基本函數 
1.字串函數長度與分析用
datalength(Char_expr) 返回字串包含字元數,但不包含後面的空格 
substring(expression,start,length) 不多說了,取子串 
right(char_expr,int_expr) 返回字串右邊int_expr個字元 
字元操作類 
upper(char_expr) 轉為大寫 
lower(char_expr) 轉為小寫 
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 
2.數學函數 
abs(numeric_expr) 求絕對值 
ceiling(numeric_expr) 取大於等於指定值的最小整數 
exp(float_expr) 取指數
floor(numeric_expr) 小於等於指定值得最大整數 
pi() 3.1415926......... 
power(numeric_expr,power) 返回power次方 
rand([int_expr]) 隨機數產生器 
round(numeric_expr,int_expr) 安int_expr規定的精度四捨五入 
sign(int_expr) 根據正數,0,負數,,返回+1,0,-1 
sqrt(float_expr) 平方根 
3.日期函數 
getdate() 返回日期 
datename(datepart,date_expr) 返回名稱如 June 
datepart(datepart,date_expr) 取日期一部份
datediff(datepart,date_expr1.dateexpr2) 日期差 
dateadd(datepart,number,date_expr) 返回日期加上 number 
上述函數中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 毫秒 
日期轉換 
convert() 
4.系統函數 
suser_name() 使用者登入名稱 
user_name() 使用者在資料庫中的名字 
user 使用者在資料庫中的名字 
show_role() 對目前使用者起作用的規則 
db_name() 資料庫名 
object_name(obj_id) 資料庫物件名 
col_name(obj_id,col_id) 列名 
col_length(objname,colname) 列長度 
valid_name(char_expr) 是否是有效標識符

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.