这是oracle包实体里面的一个存储过程 oracle存储过程中的if...elseif...else用法

这是oracle包实体里面的一个存储过程
CREATE OR REPLACE PACKAGE BODY CHXT_FWZ_FWH_RELATIONPACKAGE
is

    procedure GetFwxxByFwzl
    (
    ret_cursor out  mycursor,-- 定义过程,用游标变量作为返回参数
    p_fwzl in varchar2,
    p_yzh  in  varchar2,
    p_gczh in number,
    p_fh in varchar2,
    p_type in number)  as
    
    p_strsql varchar2(500);
    
    BEGIN
       IF p_type =1 then
       --精确查询
           
           p_strsql := 'select a.*,b.* from chxt_fwzxxb a,chxt_fwfhxxb b where a.fwzl = p_fwzl ';
           
           if p_yzh <> '' then
              p_strsql := p_strsql || ' and YZH= p_yzh';
                 end if;
           
           if p_gczh >0 then
              p_strsql := p_strsql || ' and gczh = p_gczh';
           end if;  
           
           p_strsql := p_strsql || ' and a.autoid = b.zbh';
           
           if p_fh <> '' then
               p_strsql := p_strsql || ' and b.fh = p_fh';
           end if;
           
           open ret_cursor for p_strsql;
           
     ----- else if p_type = 2 then
           -----p_strsql := 'select a.*,b.* from chxt_fwzxxb a,chxt_fwfhxxb b where a.fwzl = p_fwzl ';
           -----open ret_cursor for p_strsql;
      else 
           p_strsql := 'select a.*,b.* from chxt_fwzxxb a,chxt_fwfhxxb b where a.fwzl = p_fwzl ';
           open ret_cursor for p_strsql;
       end if;
    END GetFwxxByFwzl;

END CHXT_FWZ_FWH_RELATIONPACKAGE;
如果我注释掉
----- else if p_type = 2 then
           -----p_strsql := 'select a.*,b.* from chxt_fwzxxb a,chxt_fwfhxxb b where a.fwzl = p_fwzl ';
           -----open ret_cursor for p_strsql;
这一段,编译是正确的

但是,加上这一段 如下
CREATE OR REPLACE PACKAGE BODY CHXT_FWZ_FWH_RELATIONPACKAGE
is

    procedure GetFwxxByFwzl
    (
    ret_cursor out  mycursor,-- 定义过程,用游标变量作为返回参数
    p_fwzl in varchar2,
    p_yzh  in  varchar2,
    p_gczh in number,
    p_fh in varchar2,
    p_type in number)  as
    
    p_strsql varchar2(500);
    
    BEGIN
       IF p_type =1 then
       --精确查询
           
           p_strsql := 'select a.*,b.* from chxt_fwzxxb a,chxt_fwfhxxb b where a.fwzl = p_fwzl ';
           
           if p_yzh <> '' then
              p_strsql := p_strsql || ' and YZH= p_yzh';
                 end if;
           
           if p_gczh >0 then
              p_strsql := p_strsql || ' and gczh = p_gczh';
           end if;  
           
           p_strsql := p_strsql || ' and a.autoid = b.zbh';
           
           if p_fh <> '' then
               p_strsql := p_strsql || ' and b.fh = p_fh';
           end if;
           
           open ret_cursor for p_strsql;
           
      else if p_type = 2 then
           p_strsql := 'select a.*,b.* from chxt_fwzxxb a,chxt_fwfhxxb b where a.fwzl = p_fwzl ';
           open ret_cursor for p_strsql;
      else 
           p_strsql := 'select a.*,b.* from chxt_fwzxxb a,chxt_fwfhxxb b where a.fwzl = p_fwzl ';
           open ret_cursor for p_strsql;
       end if;
    END GetFwxxByFwzl;

END CHXT_FWZ_FWH_RELATIONPACKAGE;

编译就有错误

Compilation errors for PACKAGE BODY FCCH.CHXT_FWZ_FWH_RELATIONPACKAGE

Error: PLS-00103: 出现符号 "GETFWXXBYFWZL"在需要下列之一时:
       if
Line: 44
Text: END GetFwxxByFwzl;

Error: PLS-00103: 出现符号 "end-of-file"在需要下列之一时:
       beginfunction
          packagepragmaprocedureform
Line: 51



Compilation errors for PACKAGE BODY FCCH.CHXT_FWZ_FWH_RELATIONPACKAGE

Error: PLS-00103: 出现符号 "GETFWXXBYFWZL"在需要下列之一时:
       if
Line: 44
Text: END GetFwxxByFwzl;

Error: PLS-00103: 出现符号 "end-of-file"在需要下列之一时:
       beginfunction
          packagepragmaprocedureform

Line: 51



if ... then 
...   
elsif ... then 
...   

else 
...   
end if;   
    

or     
if ... then     
  ...   
else 
...   
end if;   
    
or     
if ... then 
...   
end if;

 

注:if后的条件不加括号

 

例子如下:
           if   p_fh <> ''   then
               p_strsql := p_strsql || ' and b.fh = p_fh';
           end if;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值