SQL Server(五)——常用函數

來源:互聯網
上載者:User

標籤:

1.數學函數:操作一個資料,返回一個結果

--取上限ceiling

select code,name,ceiling(price) from car ;

--取下限 floor

select floor(price) from car

--ABS 絕對值

--派 PI(),圓周率,括弧裡不需要加東西

--ROUND 四捨五入 select ROUND(3.76,0)

--SQRT 開根號

--SQUARE 平方,乘以自己

2.字串函數:

--轉換大寫 upper

select upper(pic) from car;

--轉換小寫 lower

--去空格 select ltrim (‘    123    ‘) 去左空格

select ‘ 123123 ‘ 可以不查資料,直接這樣顯示出來

--space() 裡面放幾個數字,就列印出來幾個空格

--LEFT,類似於SubString,從左邊開頭截取 select LEFT(‘123456‘,3);

--len,長度

select len(‘aaaaaa‘); 返回幾個長度

--replace  替換

select replace(‘aaaaabbaaaaa‘,‘bb‘,‘haha‘);把第一個字串中的bb替換成haha

--reverse  翻轉

select reverse(‘abc‘); 結果是 cba

--字串轉換函式  str

select str(1.567,3,1); 把1.567轉換成字串;3代表——最多留3位,小數點算一位;1代表——保留小數點後1位

--字串截取 SUBSTRING

select substring(‘abcdefg‘,2,3); 從第2位開始截取3位,索引從1開始

3.時間日期函數:

--擷取當前系統時間 GetDate()

select getdate();

sysdatetime() 擷取資料庫服務的時間戳記

--擷取年月日 year month day

select year(‘1999-1-1‘);

--判斷日期是否正確,isdate 返回bit

select isdate(‘2000-2-31‘)返回bit類型,false是0,true是1

--添加時間 dateadd

select dateadd(year,5,‘2000-1-1‘); 添加什麼類型,加多少,給誰加

--返回星期幾 datename,返回的值是字串

select datename(weekday,‘2000-1-1‘);

註:datepart 一樣可以返回周幾,但是返回的是int類型

也可以返回第幾天,按月

select datename(day,‘2000-1-1‘);

一年中第幾天

select datename(dayofyear,‘2000-1-1‘);

 

SQL Server(五)——常用函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.