如何在一个oracle脚本中包含一个或多个过程的示例在脚本中执行-参见下面的示例

vsmadaxz  于 2023-11-17  发布在  Oracle
关注(0)|答案(2)|浏览(186)

问题:Oracle脚本-如何在单个Oracle脚本中包含一个或多个过程

set pagesize 1000
set linesize 220
set trimspool on
set tab offset numwidth 10

procedure test01
as
begin

end test01;

procedure test02
as
begin

end test02;

execute test01;
execute test02;

字符串

deyfvvtc

deyfvvtc1#

不知道这是不是你要找的,但这确实有效:
脚本内容:

set pagesize 1000
set linesize 220
set trimspool on
set tab offset numwidth 10
set serveroutput on

create procedure test01
as
begin
  dbms_output.put_line('this is test01');
end test01;
/

create procedure test02
as
begin
  dbms_output.put_line('this is test02');
end test02;
/


execute test01;
execute test02;

字符串
运行脚本:

koen 19c>@/tmp/script

Procedure TEST01 compiled

Procedure TEST02 compiled

this is test01

PL/SQL procedure successfully completed.

this is test02

PL/SQL procedure successfully completed.

siv3szwd

siv3szwd2#

如果你想定义一个非存储过程,那么在PL/SQL块的DECLARE部分定义它,并在PL/SQL块的BEGIN部分调用它:

set pagesize 1000
set linesize 220
set trimspool on
set tab offset numwidth 10

DECLARE
  procedure test01
  as
  begin
    DBMS_OUTPUT.PUT_LINE('test01');
  end test01;

  procedure test02
  as
  begin
    DBMS_OUTPUT.PUT_LINE('test02');
  end test02;
BEGIN
  test01;
  test02;
END;
/

字符串
其输出:

test01
test02


fiddle
如果你想定义一个存储过程,那么使用CREATE PROCEDURE来创建一次存储过程(在你的脚本之外):

CREATE PROCEDURE test01
as
begin
  DBMS_OUTPUT.PUT_LINE('test01');
end test01;
/

CREATE PROCEDURE test02
as
begin
  DBMS_OUTPUT.PUT_LINE('test02');
end test02;
/


然后只从脚本中调用该过程:

set pagesize 1000
set linesize 220
set trimspool on
set tab offset numwidth 10
set serveroutput on

execute test01;
execute test02;

相关问题