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" 后继续。
总结
以上是编程之家为你收集整理的Oracle数据库创建存储过程全部内容,希望文章能够帮你解决Oracle数据库创建存储过程所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。