oracle帶返回值的儲存過程

2021-08-26 11:46:56 字數 2170 閱讀 2863

create table tb_storage

(id number(9),

shopid varchar(10),

storage number(10) not null

); table created

create table tb_shop(

id number(9),

shopid varchar(10),

shopname varchar(20)

);table created

insert into tb_storage values(1,1,20);

insert into tb_storage values(2,2,30);

insert into tb_storage values(3,3,33);

insert into tb_shop values(2,'s002','空調');

insert into tb_shop values(1,'s001','彩電');

insert into tb_shop values(3,'s003','電腦');

create or replace procedure proc_storage

(param_shopid number,--商品編號

param_storagequantity int ,--出庫數量

param_shopname out varchar2,--出庫商品名稱

param_oldstorage out number,--原有庫存

param_storage out number,--現在庫存

param_flag out number--執行狀態 0成功,1找不到,2庫存不足)as

begin

select storage into param_oldstorage from tb_storage where shopid=param_shopid;

select shopname into param_shopname from tb_shop where id=param_shopid;

if param_oldstorage < param_storagequantity then

param_flag:=2;

else

update tb_storage set storage=storage-param_storagequantity where shopid=param_shopid;

param_oldstorage:=param_oldstorage-param_storagequantity;

param_flag:=0;

end if;

exception

when no_data_found then

param_flag:=1;

end;

/declare

v_shopid number(5):=2;

v_storagequantity int :=10;

v_shopname varchar2(10);

v_oldstorage number(10);

v_storage number(10);

v_flag number(2);

begin

proc_storage(

v_shopid,

v_storagequantity ,

v_shopname,

v_oldstorage,

v_storage,

v_flag

);case v_flag

when 0 then-- 成功

dbms_output.put_line('出庫商品:'||v_shopname);

dbms_output.put_line('出庫數量:'||v_storagequantity);

dbms_output.put_line('原有庫存:'||v_oldstorage );

dbms_output.put_line('現在庫存:'||v_storage );

when 1 then

dbms_output.put_line('找不到對應的商品!' );

when 2 then

dbms_output.put_line('庫存不足,不能出庫!' );

end case;

end;

/

oracle帶返回值的儲存過程

create table tb storage id number 9 shopid varchar 10 storage number 10 not null table created create table tb shop id number 9 shopid varchar 10 shop...

儲存過程分頁,帶參,返回值

create procedure dbo nb arrearagelistbycar pageindex int,第幾頁 pagesize int,分頁大小 carnumber nvarchar 6 車牌號 rstatus int output,返回標識號 0 成功 rcode int output...

C 呼叫帶返回值的儲存過程

1 在sql server中建立如下的儲存過程 set ansi nulls on set quoted identifier on gocreate procedure dbo getnamebyid studentid varchar 8 studentname nvarchar 50 outp...