创建或重新定义存储过程
SQL> create or replace procedure sample_proc is
2 begin
3 dbms_output.put_line('Hello WOrld');
4 end sample_proc;
5 /
过程已创建。
在匿名程序块中调用刚创建的存储过程,可以直接在BEGIN-END部分使用过程名调用存储过程SAMPLE_PROC。
SQL> set serverout on
SQL> begin
2 sample_proc;
3 end;
4 /
Hello WOrld
PL/SQL 过程已成功完成。
在SQL*PLUS中使用EXECUTE或者EXEC调用存储过程
SQL> execute sample_proc;
Hello WOrld
PL/SQL 过程已成功完成。
SQL> exec sample_proc;
Hello WOrld
PL/SQL 过程已成功完成。
如果在创建的过程中出现了错误 可以使用 SHOW ERRORS命令显示创建时产生的错误。
SQL> create or replace procedure sample_proc is
2 begin
3 dbms_output.put_line(hello world);
4 end sample_proc;
5 /
警告: 创建的过程带有编译错误。
SQL> show errors;
PROCEDURE SAMPLE_PROC 出现错误:
LINE/COL ERROR
-------- -----------------------------------------------------------------
3/28 PLS-00103: 出现符号 "WORLD"在需要下列之一时:
. ( ) , * @ % & | = - + <
/ > at in is mod remainder not range rem => ..
<an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_
LIKE4_ LIKEC_ as between from using || multiset member
SUBMULTISET_
符号 "." 被替换为 "WORLD" 后继续。
产生该错误的原因是输出语句中省略了表示字符的引号,是系统误认为该字符为变量。