將timestamp轉成date格式的指令碼

oracle_ace發表於2007-12-19

Create or replace function convert_ts_to_date(tstamp timestamp) return date is
V_DATE date;
V_DAY VARCHAR2(2);
V_MONTH VARCHAR2(2);
V_YEAR VARCHAR2(4);
BEGIN
V_DAY:=EXTRACT(DAY FROM tstamp);
V_MONTH:=EXTRACT(MONTH FROM tstamp);
V_YEAR:=EXTRACT(YEAR FROM tstamp);
V_DATE:= to_date(v_DAY || '-'|| V_MONTH || '-'|| V_YEAR,'DD-MM-YYYY');
Return(V_DATE);
end;
/

This can be used in applications where there is a need to extract date from timestamp column.

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

相關文章