国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > 綜合 > 正文

時(shí)間類型的轉(zhuǎn)換,SQL中CONVERT轉(zhuǎn)化函數(shù)的用法

2024-07-21 02:11:42
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
sql中convert轉(zhuǎn)化函數(shù)的用法

格式:
convert(data_type,expression[,style])

說(shuō)明:
此樣式一般在時(shí)間類型(datetime,smalldatetime)與字符串類型
(nchar,nvarchar,char,varchar)
相互轉(zhuǎn)換的時(shí)候才用到.

例子:
select convert(varchar(30),getdate(),101) now

結(jié)果為:
now
---------------------------------------
|09/15/2001

===================================================================

style數(shù)字在轉(zhuǎn)換時(shí)間時(shí)的含義如下:

--------------------------------------------------------------------
style(2位表示年份)   |  style(4位表示年份)   |   輸入輸出格式                                   
---------------------------------------------------------------------
0                               | 100                           |   mon dd yyyy hh:miam(或pm)             
---------------------------------------------------------------------
1                               |  101   美國(guó)                |   mm/dd/yy                                      
--------------------------------------------------------------------
2                               |  102    ansi               |   yy-mm-dd                                       
--------------------------------------------------------------------
3                               |  103    英法                |   dd/mm/yy                                      
--------------------------------------------------------------------
4                               |  104    德國(guó)                |   dd.mm.yy                                       
--------------------------------------------------------------------
5                               |  105    意大利             |   dd-mm-yy                                       
---------------------------------------------------------------------
6                               |  106                            |   dd mon yy                                       
---------------------------------------------------------------------------
7                               |  107                            |   mon dd,yy                                       
------------------------------------------------------------------------------
8                               |  108                            |   hh:mm:ss                                        
-----------------------------------------------------------------------
9                               |  109                            |   mon dd yyyy hh:mi:ss:mmmmam(或pm)
----------------------------------------------------------------------------
10                             |  110    美國(guó)                 |   mm-dd-yy                                        
-----------------------------------------------------------------------------
11                             |  111    日本                 |   yy/mm/dd                                       
-------------------------------------------------------------------------
12                             |  112    iso                  |   yymmdd                                          
------------------------------------------------------------------------
13                             |  113     歐洲默認(rèn)值     |   dd mon yyyy hh:mi:ss:mmm(24小時(shí)制) 
------------------------------------------------------------------------
14                             |  114                            |   hh:mi:ss:mmm(24小時(shí)制)                   
--------------------------------------------------------------------------
20                             |  120     odbc 規(guī)范     |    yyyy-mm-dd hh:mi:ss(24小時(shí)制)        
-----------------------------------------------------------------------------
21                             |   121                           |    yyyy-mm-dd hh:mi:ss:mmm(24小時(shí)制)
-----------------------------------------------------------------------

語(yǔ)句及查詢結(jié)果:
select convert(varchar(100), getdate(), 0): 05 16 2006 10:57am
select convert(varchar(100), getdate(), 1): 05/16/06
select convert(varchar(100), getdate(), 2): 06.05.16
select convert(varchar(100), getdate(), 3): 16/05/06
select convert(varchar(100), getdate(), 4): 16.05.06
select convert(varchar(100), getdate(), 5): 16-05-06
select convert(varchar(100), getdate(), 6): 16 05 06
select convert(varchar(100), getdate(), 7): 05 16, 06
select convert(varchar(100), getdate(), 8): 10:57:46
select convert(varchar(100), getdate(), 9): 05 16 2006 10:57:46:827am
select convert(varchar(100), getdate(), 10): 05-16-06
select convert(varchar(100), getdate(), 11): 06/05/16
select convert(varchar(100), getdate(), 12): 060516
select convert(varchar(100), getdate(), 13): 16 05 2006 10:57:46:937
select convert(varchar(100), getdate(), 14): 10:57:46:967
select convert(varchar(100), getdate(), 20): 2006-05-16 10:57:47
select convert(varchar(100), getdate(), 21): 2006-05-16 10:57:47.157
select convert(varchar(100), getdate(), 22): 05/16/06 10:57:47 am
select convert(varchar(100), getdate(), 23): 2006-05-16
select convert(varchar(100), getdate(), 24): 10:57:47
select convert(varchar(100), getdate(), 25): 2006-05-16 10:57:47.250
select convert(varchar(100), getdate(), 100): 05 16 2006 10:57am
select convert(varchar(100), getdate(), 101): 05/16/2006
select convert(varchar(100), getdate(), 102): 2006.05.16
select convert(varchar(100), getdate(), 103): 16/05/2006
select convert(varchar(100), getdate(), 104): 16.05.2006
select convert(varchar(100), getdate(), 105): 16-05-2006
select convert(varchar(100), getdate(), 106): 16 05 2006
select convert(varchar(100), getdate(), 107): 05 16, 2006
select convert(varchar(100), getdate(), 108): 10:57:49
select convert(varchar(100), getdate(), 109): 05 16 2006 10:57:49:437am
select convert(varchar(100), getdate(), 110): 05-16-2006
select convert(varchar(100), getdate(), 111): 2006/05/16
select convert(varchar(100), getdate(), 112): 20060516
select convert(varchar(100), getdate(), 113): 16 05 2006 10:57:49:513
select convert(varchar(100), getdate(), 114): 10:57:49:547
select convert(varchar(100), getdate(), 120): 2006-05-16 10:57:49
select convert(varchar(100), getdate(), 121): 2006-05-16 10:57:49.700
select convert(varchar(100), getdate(), 126): 2006-05-16t10:57:49.827
select convert(varchar(100), getdate(), 130): 18 ???? ?????? 1427 10:57:49:907am
select convert(varchar(100), getdate(), 131): 18/04/1427 10:57:49:920am


說(shuō)明:
使用 convert

convert ( data_type [ ( length ) ] , expression [ , style ] )

參數(shù)

expression

是任何有效的 microsoft® sql server™ 表達(dá)式。。

data_type

目標(biāo)系統(tǒng)所提供的數(shù)據(jù)類型,包括 bigintsql_variant。不能使用用戶定義的數(shù)據(jù)類型。
length

ncharnvarcharcharvarcharbinaryvarbinary 數(shù)據(jù)類型的可選參數(shù)。

style

日期格式樣式,借以將 datetime 或 smalldatetime 數(shù)據(jù)轉(zhuǎn)換為字符數(shù)據(jù)(ncharnvarcharcharvarcharncharnvarchar 數(shù)據(jù)類型);或者字符串格式樣式,借以將 floatrealmoneysmallmoney 數(shù)據(jù)轉(zhuǎn)換為字符數(shù)據(jù)(ncharnvarcharcharvarcharncharnvarchar 數(shù)據(jù)類型)。

sql server 支持使用科威特算法的阿拉伯樣式中的數(shù)據(jù)格式。

在表中,左側(cè)的兩列表示將 datetime 或 smalldatetime 轉(zhuǎn)換為字符數(shù)據(jù)的 style 值。給 style 值加 100,可獲得包括世紀(jì)數(shù)位的四位年份 (yyyy)。

不帶世紀(jì)數(shù)位 (yy)帶世紀(jì)數(shù)位 (yyyy)
標(biāo)準(zhǔn)

輸入/輸出**
-0 或 100 (*) 默認(rèn)值mon dd yyyy hh:miam(或 pm)
1101美國(guó)mm/dd/yyyy
2102ansiyy.mm.dd
3103英國(guó)/法國(guó)dd/mm/yy
4104德國(guó)dd.mm.yy
5105意大利dd-mm-yy
6106-dd mon yy
7107-mon dd, yy
8108-hh:mm:ss
-9 或 109 (*) 默認(rèn)值 + 毫秒mon dd yyyy hh:mi:ss:mmmam(或 pm)
10110美國(guó)mm-dd-yy
11111日本yy/mm/dd
12112isoyymmdd
-13 或 113 (*) 歐洲默認(rèn)值 + 毫秒dd mon yyyy hh:mm:ss:mmm(24h)
14114-hh:mi:ss:mmm(24h)
-20 或 120 (*) odbc 規(guī)范yyyy-mm-dd hh:mm:ss[.fff]
-21 或 121 (*) odbc 規(guī)范(帶毫秒)yyyy-mm-dd hh:mm:ss[.fff]
-126(***)iso8601yyyy-mm-dd thh:mm:ss.mmm(不含空格)
-130*hijri****dd mon yyyy hh:mi:ss:mmmam
-131*hijri****dd/mm/yy hh:mi:ss:mmmam

*    默認(rèn)值(style 0 或 100、9 或 109、13 或 113、20 或 120、21 或 121)始終返回世紀(jì)數(shù)位 (yyyy)。
** 當(dāng)轉(zhuǎn)換為 datetime時(shí)輸入;當(dāng)轉(zhuǎn)換為字符數(shù)據(jù)時(shí)輸出。
*** 專門用于 xml。對(duì)于從 datetime或 smalldatetimecharacter 數(shù)據(jù)的轉(zhuǎn)換,輸出格式如表中所示。對(duì)于從 floatmoneysmallmoneycharacter 數(shù)據(jù)的轉(zhuǎn)換,輸出等同于 style 2。對(duì)于從 realcharacter 數(shù)據(jù)的轉(zhuǎn)換,輸出等同于 style 1。
****hijri 是具有幾種變化形式的日歷系統(tǒng),microsoft® sql server™ 2000 使用其中的科威特算法。

 重要  默認(rèn)情況下,sql server 根據(jù)截止年份 2049 解釋兩位數(shù)字的年份。即,兩位數(shù)字的年份 49 被解釋為 2049,而兩位數(shù)字的年份 50 被解釋為 1950。許多客戶端應(yīng)用程序(例如那些基于 ole 自動(dòng)化對(duì)象的客戶端應(yīng)用程序)都使用 2030 作為截止年份。sql server 提供一個(gè)配置選項(xiàng)("兩位數(shù)字的截止年份"),借以更改 sql server 所使用的截止年份并對(duì)日期進(jìn)行一致性處理。然而最安全的辦法是指定四位數(shù)字年份。

當(dāng)從 smalldatetime 轉(zhuǎn)換為字符數(shù)據(jù)時(shí),包含秒或毫秒的樣式將在這些位置上顯示零。當(dāng)從 datetime 或 smalldatetime 值進(jìn)行轉(zhuǎn)換時(shí),可以通過(guò)使用適當(dāng)?shù)?charvarchar 數(shù)據(jù)類型長(zhǎng)度來(lái)截?cái)嗖恍枰娜掌诓糠帧?/font>



發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 丹巴县| 广丰县| 从化市| 湖南省| 九江县| 襄樊市| 颍上县| 荣昌县| 深水埗区| 平潭县| 桓台县| 海口市| 兴和县| 青铜峡市| 忻州市| 蒲城县| 瑞安市| 新宾| 潮州市| 太湖县| 正安县| 太仆寺旗| 宁陵县| 古丈县| 眉山市| 天等县| 丹江口市| 乳山市| 呼玛县| 泰来县| 隆化县| 马关县| 烟台市| 墨玉县| 大余县| 周至县| 哈密市| 玛曲县| 清镇市| 伽师县| 清镇市|