Oracle中Cursor, A表a1字段值复制到B表b1字段 博客分类: 数据库 oraclecursorsql
程序员文章站
2024-02-12 09:02:22
...
不同表,字段赋值:
table_a 和table_b 两个表的code相关联, 把talbe_bd.name 属性值复制到table_a.name,
declare cursor css1 is select id,code from table_a; cursor css2 is select id,code,name from table_b; begin for cs1 in css1 loop for cs2 in css2 loop if cs1.code = cs2.code and cs1.id = cs2.id update table_a a set a.name = cs2.name where a.code = cs2.code; end if; end loop; end loop; commit; end;
相同表字段赋值:
table_a表, 把code1的字段值复制到code2字段里面
declare cursor css1 is select id from table_a; cursor css2 is select id,code1 from table_a; begin for cs1 in css1 loop for cs2 in css2 loop if cs1.id = cs2.id update table_a a set a.code2 = cs2.code1 where a.id = cs2.id; end if; end loop; end loop; commit; end;
更多参考:oracle-cursor