一次更新两个表的简单oracle存储过程示例

一次更新两个表的简单oracle存储过程示例,oracle,stored-procedures,Oracle,Stored Procedures,谁能举一个Oracle存储过程的简单例子,一次更新两个表 我想您应该使用c中的值更新表a和表b。 CREATE OR REPLACE PROCEDURE update_2_tables IS begin update t1 set c1 = 1; update t2 set c1 = 2; end; / 这是PL/SQL create or replace procedure update_one_scan as cursor c is select a.rowid r1,

谁能举一个Oracle存储过程的简单例子,一次更新两个表

我想您应该使用c中的值更新表a和表b。
CREATE OR REPLACE PROCEDURE update_2_tables
IS
begin
  update t1 set c1 = 1;
  update t2 set c1 = 2;
end;
/
这是PL/SQL

create or replace procedure update_one_scan as
  cursor c is 
   select a.rowid r1, b.rowid r1, c.value_to_get
   from a join b on (join conditions)
     join c on (join conditions)
   where conditions;
begin
  for r in c
  loop
    update a set col_to_update=r.value_to_get where rowid=r1;
    update b set col_to_update=r.value_to_get where rowid=r2;
  end loop;
end;
您具有对源表进行单次扫描的优势

更新: 您甚至可以在oracle SQL中执行此操作,但在尝试时会看到更严格的限制。但这可以更快

是一个UPDATE SELECT语句:

Create or replace Procedure update_select AS
BEGIN
  update
  (select a.col_to_update as c1, b.col_to_update as c2, c.value_to_get v1
         from a join b on (join conditions)
           join c on (join conditions)
         where conditions)
  set 
  c1 = v1, c2 = v2;
END;

我想你应该用c中的值更新表a和表b。 这是PL/SQL

create or replace procedure update_one_scan as
  cursor c is 
   select a.rowid r1, b.rowid r1, c.value_to_get
   from a join b on (join conditions)
     join c on (join conditions)
   where conditions;
begin
  for r in c
  loop
    update a set col_to_update=r.value_to_get where rowid=r1;
    update b set col_to_update=r.value_to_get where rowid=r2;
  end loop;
end;
您具有对源表进行单次扫描的优势

更新: 您甚至可以在oracle SQL中执行此操作,但在尝试时会看到更严格的限制。但这可以更快

是一个UPDATE SELECT语句:

Create or replace Procedure update_select AS
BEGIN
  update
  (select a.col_to_update as c1, b.col_to_update as c2, c.value_to_get v1
         from a join b on (join conditions)
           join c on (join conditions)
         where conditions)
  set 
  c1 = v1, c2 = v2;
END;

请看:如果single go意味着atomicall更改,否则没有更改,您可以像schurik所说的那样进行更新并拍摄提交;如果single go意味着一个命令,或者single unitar处理更新,请参阅我的回复。请参阅:如果single go意味着原子化所有更改,否则没有更改,您可以像schurik所说的那样进行更新并拍摄提交;如果single go意味着一个命令,或者一个unitar处理更新,请参阅我的回答。ORA-01776:无法通过join viewmmm修改多个基表,可能你是对的,我没有测试过。我使用了update select语句,但我不知道限制。谢谢。ORA-01776:无法通过join viewmmm修改多个基表,可能你是对的,我没有测试过。我使用了update select语句,但我不知道限制。谢谢