How to update multiple records in one go

Viewed 129

I want to update columns of a table whose values are NULL and I want to do this for 5 rows, but I'm getting the error : missing SET keyword

I am running the query in oracle SQL developer

The query I'm using is

UPDATE  top(5) table_name
set col1=value1,
col2=value2,
col3=value3 where col1=null;

Second query I used is

UPDATE  table_name  
set col1=value1,
col2=value2,
col3=value3 where col1=null and rownum<=5;
1 Answers

You can do this in below way:

UPDATE  table_name   
set (col1,col2,col3) = (select col1,col2,col3 from table_name where col1 is null and rownum<=5) 
where col1 is null;
Related