Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Multiple IF/END IF

user8492264Nov 22 2016 — edited Nov 23 2016

I have a scenario wherein I have to write multiple conditional statements -

SET SERVEROUTPUT ON

DECLARE

   v_test VARCHAR2(100) := 'ABCDEF';

BEGIN

   IF INSTR(v_test,'A')> 0

   THEN

      DBMS_OUTPUT.PUT_LINE('A');

   END IF;

   IF INSTR(v_test,'B')> 0

   THEN

      DBMS_OUTPUT.PUT_LINE('B');

   END IF;

   IF INSTR(v_test,'C')> 0

   THEN

      DBMS_OUTPUT.PUT_LINE('C');

   END IF;

END;

/

Is there a more elegant way of writing this, instead of multiple IF - END IF statemnets?

Say something like

<<Conditional Operator>> INSTR(v_test,'A')> 0 THEN      DBMS_OUTPUT.PUT_LINE('A');

<<Conditional Operator>> INSTR(v_test,'B')> 0 THEN      DBMS_OUTPUT.PUT_LINE('B');

<<Conditional Operator>> INSTR(v_test,'C')> 0 THEN      DBMS_OUTPUT.PUT_LINE('C');

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 21 2016
Added on Nov 22 2016
12 comments
2,816 views