-
efficient update program
Hi Friends,
I have a table emp with columns (hiredate date, birthdate date);
I want to update the two columns set to NULL if their value is
greater than sysdate. Like this:
sql> update emp set hiredate=null where hiredate>sysdate;
sql> update emp set birthdate=null where birthdate>sysdate;
How can i write this on one command line (maybe using decode)
so i wont re-read the table again, thus making it efficient.
I want one pass to the table.
Thanks a lot
-
Code:
update emp
set hiredate =
case when hiredate > sysdate then
null
else hiredate end,
birthdate =
case when birthdate > sysdate then
null
else birthdate end
where
birthdate > sysdate or hiredate > sysdate
Abhay.
-
Thanks hun, hmmnnn new look in sqlplus command. it looks like
pl/sql...i learned a new technique again, if u want to evaluate/validate all columns you can use CASE.