存储过程中的异常控制?这个存储过程该如何写?

Michaelyfj 2002-11-06 05:18:37
利用存储过程实现数据的远程复制

存储过程脚本如下:
create procedure up_data
begin
create table table_a as select * from user_b.table_a@link1;
create table table_a as select * from user_b.table_a@link2;
create table table_a as select * from user_b.table_a@link3;
create table table_a as select * from user_b.table_a@link4;
......
end
/
以上存储过程执行时,如果其中一个有异常,能否继续往后执行,并把
异常信息保存到一个表里?
存储过程要做如何改进,如果把每个建表语句都做成一个事务来处理,是否
可行?
...全文
122 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
snowy_howe 2002-11-07
  • 打赏
  • 举报
回复
用begin..exception..end每个块中的异常即时处理。
Michaelyfj 2002-11-07
  • 打赏
  • 举报
回复
还是用execute immediate好,我试试
penitent 2002-11-06
  • 打赏
  • 举报
回复
如果是8i,这样即可
create procedure up_data
begin
begin
//要用动态sql
execute immediate 'create table table_a as select * from user_b.table_a@link1';
exception when others then
....
end;
begin
execute immed 'create table table_a as select * from user_b.table_a@link2';
exception when others then
....
end;
....

end;
/
注意以下三点
1、在过程中不可以有直接的create table的ddl语句。
2、如果是8,需要用dbms_sql包来代替execute immediate
3、这类语句需要特别的权限,如以上语句就需要create any table的特权
jlandzpa 2002-11-06
  • 打赏
  • 举报
回复
会的.
Michaelyfj 2002-11-06
  • 打赏
  • 举报
回复
这样如果其中一个表异常了,后面的会继续做吗
jlandzpa 2002-11-06
  • 打赏
  • 举报
回复
//多加几个begin end.

create procedure up_data
begin
begin
//要用动态sql
create table table_a as select * from user_b.table_a@link1;
exception when others then
....
end;
begin
create table table_a as select * from user_b.table_a@link2;
exception when others then
....
end;
....
create table table_a as select * from user_b.table_a@link3;
create table table_a as select * from user_b.table_a@link4;
......
end
/

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧