您的位置:首页 > 数据库 > Oracle

Oracle过程的使用,调用函数,调用过程,使用游标

2008-05-15 11:02 561 查看
1、创建通常的过程:


create or replace procedure 过程名
(

--定义参数,格式(参数名 进出类型(in,out,inout) 数据类型,)
p_kh in t_djls.kh%type, --卡号
p_id in t_kcsm.id%type, --输入id
p_sm out t_kcsm.sm%type, --返回书名
p_dj out t_kcsm.dj%type, --定价
p_bbmc out t_kcsm.bbmc%type, --版别名称
p_kycs out t_kcsl.kccs%type, --可用册数
p_flowid out t_dpls.flowid%type, --订单流水号
p_sjcs out t_dpls.sjcs%type, --订单册数
p_qhcs out t_dpls.qhcs%type, --期货册书
p_gcbj out number, --是否有馆藏库存 1有,0没有
p_gcsl out t_gckc.gcsl%type, ---返回图书馆管仓库存
p_ccbj out number,--返回同一个下游客户之间的查重,有重复为1,没有重复为0
p_ccts out varchar2,--返回查重信息。包含数量和卡号
p_errcode out number, --错误代码0返回成功,-3没有可用库存,1已有采购信息修改,-4没有可用的书目信息
p_errtext out varchar2 --错误内容
) is
/*
得到可用库存和书目信息
2008-03-03
ljg
*/

--定义过程内参数,一般只为临时使用 格式(参数名 数据类型;)
v_uhlx t_kcsm.uhlx%type := '0002'; --货权
v_progress varchar2(200); --进度信息
v_ddcs t_kcsl.kccs%type; --订单册数
v_isbn t_kcsm.isbn%type; --书目的ISBN
v_dh t_djls.dh%type; --中盘店号
v_xydh t_djls.xydh%type; --下游店号
v_gcsl t_gckc.gcsl%type; --馆藏数量
v_gcbj t_xydm.gcbj%type; --馆藏标记
v_kccs t_kcsl.kccs%type; --库存册数
v_kycs t_kcsl.kccs%type; --可用册数
v_othercs t_kcsl.kccs%type;---其他卡下单册书
v_otherkh t_djls.kh%type;-----其他卡卡号
v_djlsh t_dpls.djlsh%type; --单据流水号
v_zt t_djls.zt%type; --卡号状态
v_tjbj t_djls.tjbj%type; --提交标记
v_sjcs t_dpls.sjcs%type; --原订单册数
v_qhcs t_dpls.qhcs%type; --订单期货册书
v_flowid t_dpls.flowid%type; --订单流水号
v_flag number := 1; --是否订过该品种
begin

--开始执行各种操作
end;

v_progress := '图书ID:' || p_id;
--判断卡号是否为空
if p_kh is null then
p_errcode := -2;
p_errtext := '卡号为空';
return;
end if;
--判断ID是否为空
if p_id is null then
p_errcode := -2;
p_errtext := '图书ID为空';
return;
end if;
--判断是否登记
begin
select td.flowid, nvl(td.zt, '0'), nvl(td.tjbj, '0'), td.dh, td.xydh,
nvl(tx.gcbj, '0')
into v_djlsh, v_zt, v_tjbj, v_dh, v_xydh, v_gcbj
from t_djls td, t_xydm tx
where td.xydh = tx.bh
and td.kh = p_kh;
exception
when NO_DATA_FOUND then
p_errcode := -2;
p_errtext := p_kh || '没有登记';
return;
end;
--判断是否登陆
if trim(v_zt) <> '1' then
p_errcode := -2;
p_errtext := p_kh || '没有登陆';
return;
end if;
--判断是否提交订单
if trim(v_tjbj) = '1' then
p_errcode := -2;
p_errtext := '该卡号已经提交订单,不能进行添加或修改';
return;
end if;
--库存册数
begin
select min(t_kcsm.sm), min(t_kcsm.dj), min(t_kcsm.bbmc), min(t_kcsm.tm),
nvl(sum(nvl(t_kcsl.kccs, 0) + nvl(t_kcsl.jkc, 0)), 0)
into p_sm, p_dj, p_bbmc, v_isbn, v_kccs
from t_kcsm, t_kcsl
where t_kcsm.uhlx = t_kcsl.uhlx
and t_kcsm.id = t_kcsl.id
and t_kcsm.uhlx = v_uhlx
and t_kcsm.id = p_id;
exception
when NO_DATA_FOUND then
p_errcode := -4;
p_errtext := v_progress || ' 没有满足条件的信息';
return;
end;
if p_sm is null then
p_errcode := -4;
p_errtext := v_progress || ' 没有满足条件的信息';
return;
end if;
--订单册数
begin
select nvl(sum(sjcs), 0)
into v_ddcs
from t_dpls
where uhlx = v_uhlx
and id = p_id;
exception
when NO_DATA_FOUND then
v_ddcs := 0;
end;
v_kycs := v_kccs - v_ddcs; --可用库存册数
v_kycs := GREATEST(v_kycs, 0); --取最大值
p_kycs := v_kycs;
--判读是否已经订过该品种
begin
v_flag := 1;
select nvl(sjcs, 0), flowid, nvl(qhcs, 0)
into v_sjcs, v_flowid, v_qhcs
from t_dpls
where djlsh = v_djlsh
and id = p_id;
exception
when NO_DATA_FOUND then
v_flag := 0;
v_flowid := 0;
v_sjcs := 0;
v_qhcs := 0;
end;
--读取该客户的馆藏库存
if v_gcbj = '1' then
begin
p_gcbj := 1;
select nvl(gcsl, 0)
into v_gcsl
from t_gckc
where t_gckc.dm = v_dh
and t_gckc.xydm = v_xydh
and t_gckc.isbn = v_isbn;
exception
when NO_DATA_FOUND then
p_gcbj := 0;
v_gcsl := 0;
end;

else
p_gcbj := 0;
v_gcsl := 0;
end if;

/* 2008-04-21修改,加参数 查重标记number(out),返回信息varchar2(out)
*/
--按下游客户进行查重
begin
select nvl(max(sjcs + qhcs), 0), max(kh)
into v_othercs, v_otherkh
from t_dpls
where dh = v_dh
and xydh = v_xydh
and id = p_id
and kh <> p_kh;
exception
when NO_DATA_FOUND then
p_ccbj := 0;
p_ccts := '没有查重数据';
end;
if v_othercs = 0 then
p_ccbj := 0;
p_ccts := '没有查重数据';
else
p_ccbj := 1;
p_ccts := '你馆卡号' || v_otherkh || '已经采购该书' || v_othercs || '册';
end if;

--库存小于等于0,判读卡是否已经采购该书目
if v_kycs <= 0 then
if v_flag = 0 then
p_errtext := v_progress || ' 没有可用库存';
p_errcode := -3;
p_gcsl := v_gcsl;
return;
end if;
end if;
p_flowid := v_flowid;
p_gcsl := v_gcsl;
p_sjcs := v_sjcs;
p_qhcs := v_qhcs;
p_errcode := v_flag;
return;
exception
when others then
rollback;
p_errcode := -1;
p_errtext := '进度信息:' || v_progress || '错误信息:' || sqlerrm;
return;

2.在过程中调用函数

假定先创建函数(判断是否为数字类型,是,返回1,非返回0)



create or replace function IS_NUMBER(p_string varchar2) return number is
/*
判断是否为数字
返回值: 0--非数字 1--数字
ljg
2008-04-18
*/
v_number number;
begin
v_number := TO_NUMBER(nvl(p_string, 'ABC'));
return 1;
exception
when others then
return 0;
end;

再调用;

过程头......

if is_number(v_tm) = 0 then
p_tm := v_isbn;
p_errcode := 0;
return;

过程尾.....

3.在过程中调用过程

SS_C001_ISBN2TM(p_isbn => v_isbn,
p_tm => v_tm,
p_errcode => p_errcode,
p_errtext => p_errtext);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: