Update more than one row in oracle
I want to up开发者_开发技巧date the table values by using hard coded values.here is my code :
BEGIN
UPDATE emp_table
SET expiry_dt = TO_DATE('21.09.2009:00:00:01','DD.MM.YYYY:HH24:MI:SS'),
WHERE emp_id = '78629160';
UPDATE emp_table
SET expiry_dt = TO_DATE('21.09.2009:00:00:01','DD.MM.YYYY:HH24:MI:SS'),
WHERE emp_id = '78629160';
END
I want to do it in the single update statement. Can anyone tell me the solution?
UPDATE emp_table SET expiry_dt = TO_DATE
('21.09.2009:00:00:01','DD.MM.YYYY:HH24:MI:SS'),
WHERE emp_id IN ('78629160','111020102','88888888');
Should do you. Edited the IN clause with various employee id's as yours were identical.
UPDATE emp_table SET expiry_dt = CASE WHEN emp_id = '78629160' THEN TO_DATE('21.09.2009:00:00:01','DD.MM.YYYY:HH24:MI:SS') WHEN emp_id = '78629161' THEN TO_DATE('21.10.2009:00:00:01','DD.MM.YYYY:HH24:MI:SS') END WHERE emp_id IN ('78629160', '78629161')
I assume the fact that you have the same ID twice was just a copy and paste error, just like the fact that both dates are identical.
Btw: what data type is emp_id
? If that is a numeric type, get rid of the single quotes for the literals (numeric literals should not be quoted). They will prevent the usage of an index on that column!
Begin UPDATE emp_table SET expiry_dt = TO_DATE ('21.09.2009:00:00:01','DD.MM.YYYY:HH24:MI:SS'),-- why you are using ',' here?? WHERE emp_id = '78629160';
Begin
UPDATE emp_table SET expiry_dt = TO_DATE('21.09.2009:00:00:01','DD.MM.YYYY:HH24:MI:SS')
WHERE emp_id = '78629160';
end;
It is running in my machine whithout any error and problem.. adn giving expected result also.. try once again without using that ','.
精彩评论