复制表中的行(到同一个表),如果满足某个条件,则更改一列

时间:2015-07-29 10:40:27

标签: plsql

这样的事情:
(v_city,v_address v_name已经是我已声明过的变量)

    insert into table1 (id, name, address, city)
    select table1_seq.nextval, name, address, city from table1 where city=v_city;

但如果name = v_name,我希望将地址更改为v_address。

1 个答案:

答案 0 :(得分:1)

这个怎么样:

insert into table1 (id
                   ,name
                   ,address
                   ,city)
select table1_seq.nextval
      ,name
      ,case when name = v_name then v_address else address end
      ,city
from table1
where city = v_city;