我有一个日期列。现在我的任务是创建一个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