DB2日期與字串轉換函式

fjzcau發表於2015-03-28
--TIMESTAMP_FORMAT   to_date

db2 "
WITH temp1 (ts1) AS                                                   
(VALUES  ('1999-12-31 23:59:59') , ('2002-10-30 11:22:33')
)             
SELECT   ts1  ,to_date(ts1,'YYYY-MM-DD HH24:MI:SS') AS ts2         
FROM     temp1                                                        
ORDER BY ts1
"

--VARCHAR_FORMAT  to_char

db2 "
WITH temp1 (ts1) AS                                                   
(VALUES  (TIMESTAMP('1999-12-31-23.59.59')) , (TIMESTAMP('2002-10-30-11.22.33'))                           
)                                                                     
SELECT   ts1 ,char( to_char(ts1,'YYYY-MM-DD HH24:MI:SS'), 30 )  AS ts2           
FROM     temp1                                                        
ORDER BY ts1
"


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22661144/viewspace-1477102/,如需轉載,請註明出處,否則將追究法律責任。

相關文章