oracle 通过存储过程 实现 表间字段迁移

来源:互联网 发布:最好的python视频教程 编辑:程序博客网 时间:2024/06/18 01:01

条件:

两个表:

ITPUB_TEST1 字段 id,value 

ITPUB_TEST2 字段 id,funcid ,action


ITPUB_TEST2  的funcid 关联ITPUB_TEST1 中的id。


任务:

将ITPUB_TEST2 中的action内容 迁移到对应ITPUB_TEST1的value字段。(funcid对应id)

create or replace procedure transfer asCursor cursor is select funcid,action from ITPUB_TEST2;myVar varchar2(50);begin  for myVar in cursor LOOP    begin     dbms_output.put_line(myVar.funcid);       dbms_output.put_line(myVar.action);       if(myVar.funcid != 0) then       dbms_output.put_line('ok');         update ITPUB_TEST1 set value=myVar.action where id=myVar.funcid;      end if;    end;  end LOOP;  commit;end;
执行:
exec transfer();



原创粉丝点击