If statement plsql包中的if语句

If statement plsql包中的if语句,if-statement,plsql,If Statement,Plsql,我在一个包中有六个插入块(工作、职位、等级等),类似于: create or replace package body XX_package_cust AS PROCEDURE main_procedure( p_entity In VARCHAR2 default 'ALL') is begin if p_entity='Job' then --execute job block elsif p_entity='Position' --execute postion block

我在一个包中有六个插入块(工作、职位、等级等),类似于:

create or replace package body XX_package_cust
AS

PROCEDURE main_procedure( p_entity In VARCHAR2 default 'ALL')

is

begin

if p_entity='Job'
then
--execute job block

elsif p_entity='Position'

--execute postion block

elsif p_entity='Grade'

--execute grade block
end if;

end;
现在在上面的if-else中,如果我想在p_实体中通过
'ALL'
,那么如果
所有
都通过了,那么所有这些块都应该执行,如果是'job',则只应该执行相应的块

在本例中,例如在作业部分

begin

    begin

    insert into job_i
    --------

    end;

    begin
    insert into job_x
    ----
    end;
   end;
现在如果我把if else包括在每个。。。我必须做一些类似的事情:

begin
if p_entity ='JOB'
then
    begin

    insert into job_i
    --------

    end;

    begin
    insert into job_x
    ----
    end;
end if;
   end;

这是每个街区的if else。是否有其他解决方法

您可以检查每个条件的具体值或
'ALL'
。注意,您必须用简单的
if
s替换
elsif
语句:

if p_entity IN ('ALL', 'Job')
then
--execute job block
end if;

if p_entity IN ('ALL', 'Position')
--execute position block
end if;

if p_entity IN ('ALL', 'Grade')
--execute grade block
end if;
试试这个


我不明白这个问题。。就像你做的那样,把它放在一个if-else里
CREATE OR REPLACE PACKAGE body XX_package_cust
AS
  PROCEDURE main_procedure(
      p_entity IN VARCHAR2 DEFAULT 'ALL')
  IS
  BEGIN
    IF p_entity ='Job' THEN
      --execute job block
      dbms_output.put_line('Job block executed');
    elsif p_entity='Position' THEN
      --execute postion block
      dbms_output.put_line('Position block executed');
    elsif p_entity='Grade' THEN
      --execute grade block
      dbms_output.put_line('Grade block executed');
    elsif p_entity='All' THEN
      --execute job block
      dbms_output.put_line('Job block executed');
      --execute postion block
      dbms_output.put_line('Position block executed');
      --execute grade block
      dbms_output.put_line('Grade block executed');
    END IF;
  END;
END;