使用一列中的值更新新列

时间:2016-02-08 20:03:03

标签: plsql

我在表格中有两列,需要使用以下所有组合的a列值更新第三列:

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

2 个答案:

答案 0 :(得分:0)

我觉得你需要这样的东西。

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

答案 1 :(得分:0)

我认为"游标的当前位置"将帮助您实现所需的目标。

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;
相关问题