user2762770 February 2016

Update new column with value from one column

I two columns in a table and need to update third column with a value from column a for all combinations below:

   ColumnA  ColumnB  newColumn 
     1        2         1     
     2        1         1    
     3        4         3  
     4        3         3   

Answers


vishnu sable February 2016

I thing you need something like this.

update your_table set column3 = least(column1,column2);


Prashant Mishra February 2016

I think "Where Current of Cursor" will help you here in achieving the same what you need.

CREATE TABLE test_1(a INT ,b INT);
INSERT INTO  test_1 SELECT LEVEL , NULL FROM dual CONNECT BY LEVEL<10;
SELECT * FROM  test_1;

declare
 cursor c1 is 
  select * test_1
  for update of b;
BEGIN
  FOR rec IN c1
  LOOP
   update webowner.test_1 
   set b= rec.a
   where current of c1;
  END LOOP;
end;

Post Status

Asked in February 2016
Viewed 3,605 times
Voted 6
Answered 2 times

Search




Leave an answer