.
select sysdate
, to_char(sysdate, '%b %d %Y %R') as _24h
, to_char(sysdate, '%b %d %Y %I:%M%p') as _12h
from sysmaster:sysdual;
--結果
(expression) _24h _12h
-----------------------------------------------------------------------------------------------------------------------------------
2017-12-15 07:47:04.0 Dec 15 2017 07:47 Dec 15 2017 07:47AM
來源:
https://stackoverflow.com/a/47830727
範例:
--我的Table有一個欄位叫做rec_date,Data Type是DateTime,允許Null值
select NVL(to_char(rec_date, '%Y%m%d'),'') as Display_Rec_Date
from mytable;
--結果:-----------------------------------------------
--null的紀錄:
display_rec_date = ''
--非null的紀錄:
display_rec_date = '20180701'
再一個例子:取得資料庫系統時間:
select to_char(current,'%Y%m%d'),to_char(current,'%H%M%S') from systables where tabid=1;