create procedure add_year(old_date timestamp)
returns (new_date timestamp)
as
declare variable themonth smallint;
declare variable theday smallint;
declare variable theyear smallint;
declare variable thehour smallint;
declare variable themin smallint;
declare variable thesec decimal(6,4);
begin
themonth = extract(month from old_date);
theday = extract(day from old_date);
theyear = extract(year from old_date) + 1;
thehour = extract(hour from old_date);
themin = extract(minute from old_date);
thesec = extract(second from old_date);
new_date = cast(themonth || '/' || theday || '/' || theyear || ' ' || thehour || ':' ||
themin || ':' || thesec as timestamp);
suspend;
end;
example usage:
SQL> set time on;
SQL> select * from add_year(current_timestamp);
NEW_DATE
=========================
28-MAY-2005 16:45:33.0000
SQL> execute procedure add_year(current_timestamp);
NEW_DATE
=========================
28-MAY-2005 16:46:02.0000
SQL> execute procedure add_year('1/1/4');
NEW_DATE
=========================
1-JAN-2005 00:00:00.0000