Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to Update the Date in PL/SQL using a variable?

Stanley Lee-OracleMay 12 2009 — edited May 12 2009
Hi,

I am setting up a varchar of an update statement and would like to put a date variable for the value. It works when I just put SYSDATE in the statement, yet doesn't when I put the date variable. Gives me an ORA-0904 error. Thanks.

DECLARE
v_upd VARCHAR2(32767); -- update statement

l_date varchar(20);
BEGIN
select sysdate into l_date from dual;

v_upd := 'UPDATE table_name SET LAST_MODIFIED_DATE = ' ||
l_date ;
v_upd := v_upd || ' where xyz =''123'' ';

EXECUTE IMMEDIATE v_upd;

EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE;
END;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 9 2009
Added on May 12 2009
5 comments
560 views