【Sql Server】Database-sql语言的流程控制语句
流程控制語句
If? else語句
If (表。列)
?????? {語句|語句塊begin,,,end}
Else
{語句|語句塊begin,,,end }
?
If?else 語句嵌套
If
Begin
????????????? If
Else if
Else
End
Else
?
Select
Case (判斷式)
When???? then
Else …
End
From
?
While 語句條件控制while語句中使用其他語句
?
延遲語句
Waitfor
{delay time|time}
Wait for delay ‘00:00:05’
Exec sp_help?????????????????? ----------時間間隔
?
Waitfor time ’21:00:00’
Exec sp_help????????????????? ------------時間點
?
Goto跳轉語句Lable
?
Try,,,catch錯誤處理語句
Begin try
?????? 容錯error
End try
Begin catch
{}
End catch
?
數學函數
| ABS | 絕對值 |
| EXP | 以e為底指數 |
| Ceiling | 退1法 |
| floor | 進1法 |
| Ln | 自然對數 |
| log | 以10為底對數 |
| power | 10power 2=102 |
| round | 舍入到指定小數 |
| sign | 返回 +- 0 |
| square | 平方 |
| aqrt | 平方根 |
?
字符串函數
| ASCII | 返回代碼的ASCI代碼值 |
| Char | 轉換為字符 |
| Left/right | 截取左/右指定個數 |
| len | 字符串的格數 |
| Lower/upper | 轉換大寫/小寫 |
| Ltim/rtrim | 刪除頭尾空格返回 |
| Replace | 原串,將要被替換的串,替換用的串 |
| space | 返回多個空格組成的字符串 |
| str | 數值轉字符串(串,開始,長度) |
| substring | 子串函數,返回部分 |
特殊字符串函數
Charindex:子字符串出現的開始位置
Charindex(子串,父串) 【不可以是text/image】
Patindex(子串含通配符)【支持 char varchar text】
?
?
聚合函數
| AVG | ? |
| COUNT | 影響行數 |
| MAX | ? |
| MIN | ? |
| SUM | ? |
?
日期和時間函數
| Dateadd | 單位,時間,日期 |
| Datediff | 單位,兩個日期 |
| Datename | ? |
| Datepart | Datepart(yy|dd|mm ,getdate) |
| Day Month Year | Year(getdate()) |
| Getdate | 當前系統時間 |
| Getutcdate | UTC 時間 |
Create function 函數名(參數列表)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?create function 函數名 (參數列表)
Return (返回類型)?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return table
[with encryption]? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?with encryption
[as]????????????????????????????????? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??as
Begin? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return (表變量/數據表/查詢結果)
?????? 函數體
End
總結
以上是生活随笔為你收集整理的【Sql Server】Database-sql语言的流程控制语句的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Sql Server】DateBase
- 下一篇: 【Sql Server】DateBase