Oracle存储过程包含三部分:过程声明,执行过程部分,存储过程异常。

语法

CREATE OR REPLACE PROCEDURE 存储过程名称 (参数in,参数out)

AS

--变量声明,每个声明用分号结束,可以在声明的同时初始化

name varchar2(50);

age number(8) default 0;

BEGIN

--执行业务逻辑

exception //存储过程异常

END

演示

create or replace procedure testProc01

as

age int;

begin

age:=10/0;
dbms_output.put_line(age);

exception when others then
dbms_output.put_line('error');

end;

调用

方法1

SQL> call testProc01();

SQL> exec testProc01();

SQL> call testProc01();

方法2

begin

testProc01;

end

最后修改:2024 年 01 月 25 日
如果觉得我的文章对你有用,请随意赞赏