加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle数据库创建存储过程

发布时间:2020-12-12 15:01:42 所属栏目:百科 来源:网络整理
导读: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 / 会出现以下状

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 => <an exponent (**)> <> or != or ~= >= <= <> and or like like2 like4 likec as between from using || multiset member submultiset 符号 "." 被替换为 "WORLD" 后继续。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读