存储过程IF --ELSE IF -- END IF 使用

CREATE OR REPLACE PROCEDURE BJPJYXK_HF_SD(
sqid_p IN VARCHAR2,--申请单ID
xkbh_p IN VARCHAR2,--新生成的许可证编号
flag OUT VARCHAR2--标识位
)
AS
ywlx VARCHAR2(50);--业务类型(0:新办,1:变更)
v_raise EXCEPTION;--自定义异常
zsid_p VARCHAR2(50);--许可证ID
yxkzh_p VARCHAR2(50);--原许可证编号
xkzlx_p VARCHAR2(50);--许可证类型
v_xkzh varchar2(50); --京药到京食药临时变量
BEGIN
-- routine body goes here, e.g.
DBMS_OUTPUT.PUT_LINE('==============许可证核发审定开始================');
--获取许可证类型
SELECT YWLX INTO ywlx FROM XZXK_BJPJYWS_HF_SQ WHERE SQID=sqid_p;
--许可证类型
SELECT xkzlx INTO xkzlx_p FROM GG_XKZ_BJPSCWS WHERE SQID=sqid_p;
--获取受理阶段生成许可证信息记录
SELECT ZSID,XMZH INTO zsid_p,yxkzh_p FROM GG_XKZ_BJPSCWS WHERE SQID=sqid_p;

--更新许可证信息
IF ywlx = '0' THEN
IF xkzlx_p = '1' THEN--经营新许可证号
--update gg_xkz_bjpscws set czzt='I',DATEXC='11',INSTNUM=f_getslbs(),LASTDATE=sysdate where czzt='V' and XMZH=xkbh_p;
UPDATE gg_xkz_bjpscws set
XMZH = xkbh_p,
FZRQ = to_char(SYSDATE,'yyyymmdd'),
YXQQSRQ = to_char(SYSDATE,'yyyymmdd'),
YXQJZRQ = to_char(add_months(sysdate, 48) - 1,'yyyymmdd'),
XKZZT = '1',
DYBS = '000',
GSBS = 'N',
CZZT = 'V',
INSTNUM = f_getslbs(),
LASTDATE = sysdate,
DATEXC = '11'
WHERE ZSID = zsid_p;
--更新申请表许可证号
UPDATE XZXK_BJPJYWS_HF_SQ SET BJBS='Y',DATEXC='11',INSTNUM=f_getslbs(),LASTDATE=sysdate WHERE sqid=sqid_p;
--将申请表插入全部信息表中
INSERT INTO XZXK_BJPSCWS_XX_QB
(XKZID,XKZH,qyid,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PDATE xzxk_bjpscws_xx_ryxx SET(xm)=
(SELECT FDDBR
FROM GG_XKZ_BJPSCWS WHERE SQID=sqid_p) WHERE xkzid=zsid_p;
ELSIF xkzlx_p = '3' THEN--生产使用经营许可证号
--更新生产许可证为无效
update gg_xkz_bjpscws set czzt='I',DATEXC='11',INSTNUM=f_getslbs(),LASTDATE=sysdate where czzt='V' and XMZH=yxkzh_p;
-- 将京药变更为京食药
v_xkzh := REPLACE(yxkzh_p, '京药', '京食药');
--新许可证为有效
UPDATE gg_xkz_bjpscws set
XMZH = v_xkzh,
FZRQ = to_char(SYSDATE,'yyyymmdd'),
YXQQSRQ = to_char(SYSDATE,'yyyymmdd'),
YXQJZRQ = to_char(add_months(sysdate, 48) - 1,'yyyymmdd'),
XKZZT = '1',
DYBS = '000',
GSBS = 'N',
CZZT = 'V',
INSTNUM = f_getslbs(),
LASTDATE = sysdate,
DATEXC = '11'
WHERE ZSID = zsid_p;

--更新申请表许可证号
UPDATE XZXK_BJPJYWS_HF_SQ SET BJBS='Y',DATEXC='11',INSTNUM=f_getslbs(),LASTDATE=sysdate WHERE sqid=sqid_p;
--数据交换删除使用
/* INSERT INTO PUB_TABLE_DATA_DELEXC(id, tablename,tablepkname,tablepk,delflag,instnum,lastdate,datexc)
select sys_guid(),'XZXK_BJPSCWS_XX_QB','XKZID',xkzid as tablepk,'N',f_getslbs(),sysdate, '11'
from XZXK_BJPSCWS_XX_QB where xkzh=yxkzh_p;
*/
--将申请表插入全部信息表中
update XZXK_BJPSCWS_XX_QB set
(XKZH,qyid,QYMC,QYXZ,QYZCDZ,QYZCDZSZQX,QYZCDZSZJD,QYZCDZYZBM,JYDZ,JYDZSZQX,JYDZSZJD,JYDZYZBM,BGDZ,BGDZSZQX,BGDZSZJD,
BGDZYZBM,FDDBR,ZGRS,YTJRS,GDZC,SYMJ,TJCLLX,BGCS,XKFW,QTCL,DATEXC,XKZLX,INSTNUM,LASTDATE,LXR,LXDH)
=(SELECT v_xkzh,QYID,QYMC,QYXZ,QYZCDZ,QYZCDZSZQX,QYZCDZSZJD,QYZCDZYZBM,JYDZ,JYDZSZQX,JYDZSZJD,JYDZYZBM,BGDZ,BGDZSZQX,BGDZSZJD,
BGDZYZBM,FDDBR,ZGRS,YTJRS,GDZC,SYMJ,'','',XKXM,QTCL,'11',XKZLX,f_getslbs(),sysdate,LXR,LXDH
FROM XZXK_BJPJYWS_HF_SQ WHERE SQID=sqid_p) where xkzh=yxkzh_p;

--更新全表信息(根据许可证信息)
UPDATE XZXK_BJPSCWS_XX_QB SET (XKZZT,FZRQ,SCFZRQ,YXQQSRQ,YXQJZRQ,ZZJGDM,FZJGDM,FZJGMC,DYBS,GSBS,XKZLX,QYMC,FDDBR,QYZCDZ,BGDZ,SCDZ,SCDZSZQX,SCDZSZJD,XKFW)=
(SELECT XKZZT,FZRQ,FZRQ,YXQQSRQ,YXQJZRQ,ZZJGDM,FZJGDM,FZJGMC,DYBS,GSBS,XKZLX,QYMC,FDDBR,QYDZ,BGDZ,SCDZ,SCDZSZQX,SCDZSZJD,XKFW
FROM GG_XKZ_BJPSCWS WHERE SQID=sqid_p) where xkzh=v_xkzh;

--数据交换删除使用 人员表
INSERT INTO PUB_TABLE_DATA_DELEXC(id, tablename,tablepkname,tablepk,delflag,instnum,lastdate,datexc)
select sys_guid(),'xzxk_bjpscws_xx_ryxx','zj',zj as tablepk,'N',f_getslbs(),sysdate, '11' from xzxk_bjpscws_xx_ryxx where xkzh=yxkzh_p;

delete xzxk_bjpscws_xx_ryxx where xkzh=yxkzh_p;
--插入人员信息表
INSERT INTO XZXK_BJPSCWS_XX_RYXX(ZJ,XKZH,QYID,XM,ZJLX,ZJH,XL,SXZY,ZC,INSTNUM,LASTDATE,DATEXC,XKZID)
SELECT sys_guid(),v_xkzh,QYID,FDDBR,ZJLX,ZJH,XL,SXZY,ZC,f_getslbs(),sysdate,'11',zsid_p
FROM XZXK_BJPJYWS_HF_SQ WHERE SQID=sqid_p;

UPDATE xzxk_bjpscws_xx_ryxx SET(xm)=
(SELECT FDDBR
FROM GG_XKZ_BJPSCWS WHERE SQID=sqid_p) WHERE xkzid=zsid_p;

ELSE
Raise v_raise;
END IF;

 

 

ELSIF ywlx = '1' THEN
--把原来的有效许可证更改为无效
update gg_xkz_bjpscws set czzt='I',DATEXC='11',INSTNUM=f_getslbs(),LASTDATE=sysdate where czzt='V' and XMZH=yxkzh_p;
--处理上线前的许可证号把京药改成京食药
if instr(yxkzh_p,'京药')>0 then
v_xkzh:=replace(yxkzh_p,'京药','京食药');
else
v_xkzh:=yxkzh_p;
end if;
--更新许可证
UPDATE GG_XKZ_BJPSCWS
SET FZRQ = to_char(SYSDATE,'yyyymmdd'),
YXQQSRQ = to_char(SYSDATE,'yyyymmdd'),
XMZH = v_xkzh,
XKZZT = '1',
DYBS = '000',
GSBS = 'N',
CZZT = 'V',
INSTNUM = f_getslbs(),
LASTDATE = sysdate,
DATEXC = '11'
WHERE ZSID = zsid_p;

--更新申请表许可证号
UPDATE XZXK_BJPJYWS_HF_SQ SET BJBS='Y',DATEXC='11',INSTNUM=f_getslbs(),LASTDATE=sysdate WHERE sqid=sqid_p;

--数据交换删除使用
--INSERT INTO PUB_TABLE_DATA_DELEXC(id, tablename,tablepkname,tablepk,delflag,instnum,lastdate,datexc)
-- select sys_guid(),'xzxk_bjpscws_xx_qb','XKZID',xkzid as tablepk,'N',f_getslbs(),sysdate, '11'
-- from XZXK_BJPSCWS_XX_QB where xkzh=yxkzh_p;
--更新全表信息
UPDATE XZXK_BJPSCWS_XX_QB
SET(XKZH,QYID,QYMC,QYXZ,QYZCDZ,QYZCDZSZQX,QYZCDZSZJD,QYZCDZYZBM,JYDZ,JYDZSZQX,JYDZSZJD,JYDZYZBM,BGDZ,BGDZSZQX,BGDZSZJD,
BGDZYZBM,FDDBR,ZGRS,YTJRS,GDZC,SYMJ,TJCLLX,BGCS,XKFW,QTCL,DATEXC,XKZLX,INSTNUM,LASTDATE,LXR,LXDH)=
(SELECT v_xkzh,QYID,QYMC,QYXZ,QYZCDZ,QYZCDZSZQX,QYZCDZSZJD,QYZCDZYZBM,JYDZ,JYDZSZQX,JYDZSZJD,JYDZYZBM,BGDZ,BGDZSZQX,BGDZSZJD,
BGDZYZBM,FDDBR,ZGRS,YTJRS,GDZC,SYMJ,'','',XKXM,QTCL,'11',XKZLX,f_getslbs(),sysdate,LXR,LXDH
FROM XZXK_BJPJYWS_HF_SQ WHERE SQID=sqid_p)
WHERE XKZH=yxkzh_p;

--更新全表信息(根据许可证信息)
UPDATE XZXK_BJPSCWS_XX_QB SET(XKZZT,FZRQ,SCFZRQ,YXQQSRQ,YXQJZRQ,ZZJGDM,FZJGDM,FZJGMC,DYBS,GSBS,XKZLX,QYMC,FDDBR,QYZCDZ,BGDZ,SCDZ,SCDZSZQX,SCDZSZJD,XKFW)=
(SELECT XKZZT,FZRQ,FZRQ,YXQQSRQ,YXQJZRQ,ZZJGDM,FZJGDM,FZJGMC,DYBS,GSBS,XKZLX,QYMC,FDDBR,QYDZ,BGDZ,SCDZ,SCDZSZQX,SCDZSZJD,XKFW
FROM GG_XKZ_BJPSCWS WHERE SQID=sqid_p) WHERE xkzid=zsid_p;

--数据交换删除使用 人员表
INSERT INTO PUB_TABLE_DATA_DELEXC(id, tablename,tablepkname,tablepk,delflag,instnum,lastdate,datexc)
select sys_guid(),'xzxk_bjpscws_xx_ryxx','zj',zj as tablepk,'N',f_getslbs(),sysdate, '11'
from xzxk_bjpscws_xx_ryxx where xkzh=yxkzh_p;
delete xzxk_bjpscws_xx_ryxx where xkzh=yxkzh_p;

--插入人员表
insert into xzxk_bjpscws_xx_ryxx
(zj,xkzh,qyid,xm,zjlx,zjh,xl,sxzy,zc,instnum,lastdate,datexc,xkzid)
select sys_guid(),v_xkzh,qyid,fddbr,zjlx,zjh,xl,sxzy,zc,f_getslbs(),sysdate,'11',zsid_p
from XZXK_BJPJYWS_HF_SQ where sqid=sqid_p;

UPDATE xzxk_bjpscws_xx_ryxx SET(xm)=
(SELECT FDDBR
FROM GG_XKZ_BJPSCWS WHERE SQID=sqid_p) WHERE xkzid=zsid_p;


DBMS_OUTPUT.PUT_LINE('==============许可证核发审定结束================');
ELSE
Raise v_raise;
END IF;

commit;
Exception
WHEN v_raise THEN
flag := 'N';
DBMS_OUTPUT.PUT_LINE('==============未找到指定业务类型================');
rollback;
WHEN NO_DATA_FOUND THEN
flag := 'N';
rollback;
WHEN others THEN
flag := 'N';
rollback;
END BJPJYXK_HF_SD;

posted @ 2015-03-12 14:25  meimao5211  阅读(6811)  评论(0编辑  收藏  举报