oracle如何创建存储过程和调用

oracle存储过程的创建语法

create or replace procedure 存储过程名称
(
--定义输入、输出参数--
参数名1 in 参数类型,
参数名2 in 参数类型,
参数名3 in 参数类型,
参数名4 out 参数类型
)
as
--定义变量--
--变量名 变量数据类型;如:
 -- numCount integer; 
begin   
     --处理方法-
end;

上面我们创建一个处理加、减、乘、除计算的函数,那么我们也可以建成存储过程

/*****
** 创建加、减、乘、除计算的存储过程
**输入参数: 数字1,数字2,计算类型
**输出参数: 数字3
*****/
create or replace procedure Proc_Test
(
--定义输入、输出参数--
num_A in integer,
num_B in integer,
numType in integer,
num_C out integer
)
as
--定义变量--
 -- numCount integer;
 -- numStr varchar(20);  
begin   
     --判断计算类型--
     if numType=1 then
        num_C := num_A + num_B;
     elsif numType=2 then
        num_C := num_A - num_B;
     elsif numType=3 then
        num_C := num_A * num_B; 
     elsif numType=4 then
        num_C := num_A / num_B; 
     else
     --其它处理
       dbms_output.put_line('其它处理');
     end if;
end;

那么如何调用存储过程

declare num_C integer;
begin
   --调用存储过程---
   Proc_Test(3,4,3,num_C);
   dbms_output.put_line('输出结果:'|| num_C );
end;

输出结果

 那么,如果我们要在存储过程调用函数,是怎么处理的呢?

create or replace procedure Proc_Test
(
--定义输入、输出参数--
num_A in integer,
num_B in integer,
numType in integer,
num_C out integer
)
as
--定义变量--
 -- numStr varchar(20);  
begin   
   /*  --判断计算类型--
     if numType=1 then
        num_C := num_A + num_B;
     elsif numType=2 then
        num_C := num_A - num_B;
     elsif numType=3 then
        num_C := num_A * num_B; 
     elsif numType=4 then
        num_C := num_A / num_B; 
     else
     --其它处理
       dbms_output.put_line('其它处理');
     end if;*/
     
     --调用函数 并赋值到num_C
     num_C:=fun_Test(num_A,num_B,numType);
end;

只要把处理过程放到函数中,存储过程调用函数就可以了

再次调用的结果

declare num_C integer;
begin
   --调用存储过程---
   Proc_Test(12,2,4,num_C);
   dbms_output.put_line('输出结果:'|| num_C );
end;

输出结果

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bijianhuan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值