SQL脚本执行控制

发布于 2024-12-05 04:14:26 字数 142 浏览 1 评论 0原文

我正在寻找如何控制大型 SQL 脚本的执行的技巧。它将包含各种DDL和DML语句。我主要是在寻找 DDL 控制。我真正的意思是,基本上我有一个脚本,其中包含从我们的数据库之一生成的多个 DDL 语句。当我启动脚本时,即使存在编译错误或创建错误,它也会执行。 感谢任何想法

I am looking for tips how to control execution of large sql script. It will contain various DDL and DML statement. Mostly I was looking for DDL control.What do I actually mean is, that basically I have a script with multiple DDL statements that are generated from one of our DBs. When I start script it will go through even if there is compilation error or error on create.
Thx for any ideas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

影子的影子 2024-12-12 04:14:26

出现错误后要退出吗?这里有几个例子。请务必检查每当 SQLERROR

DDL (DML) 示例:

prompt continues after error
prompt =====================
prompt

create table foo;

prompt quits after error with error code 
prompt =================================
prompt

whenever sqlerror exit sql.sqlcode

create table foo;

prompt never gets here
prompt ===============
prompt

quit

PL/SQL 子程序引发异常:

create or replace function foo return number as
  foo_error exception;
begin
  raise foo_error;
end;
/
show errors

prompt continues after error
prompt =====================
prompt

select foo from dual;

prompt quits after error with error code 
prompt =================================
prompt

whenever sqlerror exit sql.sqlcode

select foo from dual;

prompt never gets here
prompt ===============
prompt

quit

PL/SQL 单元编译失败:

create or replace procedure compile_function (f in varchar2) as
begin
  execute immediate 'alter function :f compile' using f;
exception
  when others then
    raise_application_error(-20000, 'Failed to compile function ' || f);
end;
/
show errors

prompt continues after error
prompt =====================
prompt

create or replace function foo return number as
begin
  compilation will fail
end;
/
show errors

exec compile_function('foo')

prompt quits after error with error code 
prompt =================================
prompt

whenever sqlerror exit sql.sqlcode

create or replace function foo return number as
begin
  compilation will fail
end;
/
show errors

exec compile_function('foo')

prompt never gets here
prompt ===============
prompt

quit

Do you want to quit after an error ? Here is a few examples. Be sure to check documentation of WHENEVER SQLERROR.

DDL (DML) example:

prompt continues after error
prompt =====================
prompt

create table foo;

prompt quits after error with error code 
prompt =================================
prompt

whenever sqlerror exit sql.sqlcode

create table foo;

prompt never gets here
prompt ===============
prompt

quit

PL/SQL subprogram raises an exception:

create or replace function foo return number as
  foo_error exception;
begin
  raise foo_error;
end;
/
show errors

prompt continues after error
prompt =====================
prompt

select foo from dual;

prompt quits after error with error code 
prompt =================================
prompt

whenever sqlerror exit sql.sqlcode

select foo from dual;

prompt never gets here
prompt ===============
prompt

quit

PL/SQL unit compilation fails:

create or replace procedure compile_function (f in varchar2) as
begin
  execute immediate 'alter function :f compile' using f;
exception
  when others then
    raise_application_error(-20000, 'Failed to compile function ' || f);
end;
/
show errors

prompt continues after error
prompt =====================
prompt

create or replace function foo return number as
begin
  compilation will fail
end;
/
show errors

exec compile_function('foo')

prompt quits after error with error code 
prompt =================================
prompt

whenever sqlerror exit sql.sqlcode

create or replace function foo return number as
begin
  compilation will fail
end;
/
show errors

exec compile_function('foo')

prompt never gets here
prompt ===============
prompt

quit
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文