天天看点

oracle数据库存储过程在哪里,Oracle数据库创建存储过程

1.最简单的存储过程

SQL> create procedure sample_proc is

2 begin

3 null;

4 end sample_proc;

5 /

2.如果我们重复建立存储过程

SQL> create procedure sample_proc is

2 begin

3 dbms_output.put_line('Hello World');

4 end sample_proc;

5 /

会出现以下状况

create procedure sample_proc is

*

第 1 行出现错误:

ORA-00955: 名称已由现有对象使用

3.避免存储过程,使用OF REPLACE

SQL> create or replace procedure sample_proc is

2 begin

3 dbms_output.put_line('Hello World');

4 end sample_proc;

5 /

4.在PL/SQL程序块中调用该存储过程

SQL> set serveroutput on

SQL> begin

2 sample_proc;

3 end;

4 /

结果:

Hello World

PL/SQL 过程已成功完成。

5.使用EXECUTE在PL/SQL程序块中调用该存储过程

SQL> execute sample_proc

结果:

Hello World

PL/SQL 过程已成功完成。

6.使用EXECUTE简写exec在PL/SQL程序块中调用该存储过程

exec sample_proc;

7.使用Show Error显示创建过程中出现的错误

SQL> create or replace procedure sample_proc is

2 begin

3 dbms_output.put_line(Hello World);

4 end sample_proc;

5 /

结果:

警告: 创建的过程带有编译错误。

SQL> show error

PROCEDURE SAMPLE_PROC 出现错误: LINE/COL ERROR -------- ----------------------------------------------------------------- 3/30     PLS-00103: 出现符号 "WORLD"在需要下列之一时:          . ( ) , * @ % & = - + < /          > at in is mod remainder not rem =>          <> or != or ~= >= <= <> and or like like2 like4 likec as          between from using || multiset member submultiset          符号 "." 被替换为 "WORLD" 后继续。