我有一個日期列。現在我的任務是創建一個udf。這個UDF的基本目的是檢查日期的一年。這是在ORACLE中。PL/SQL腳本驗證
如果年份小於1753,則指定年份爲1753年並返回日期。
例:
1) select xyz_fun('1800-01-01') from a_table => Return 1800 - 01 -01
2) select xyz_fun('1600-01-01') from a_table => Return 1753 - 01 -01
3) select xyz_fun('0001-01-01') from a_table => Return 1753 - 01 -01
返回值應該是日期。
我寫了一個UDF,但它返回警告,雖然沒有警告顯示。
create or replace function someschema.change_date(date1 in date) return date
;
begin
if(extract(year from date1) < 1753)
then
return to_date('1753'||'-'|| to_char(date1,'MM')||'-'|| to_char(date1,'dd'),'yyyy-MM-dd');
else
return date1;
end if;
end;
考慮簡化你的表情,也許是:TO_DATE( '1753' || TO_CHAR(DATE1,' - MM-dd'),'yyyy-MM-dd') – 2013-05-10 09:29:55