Oracle PL/SQL - Using an ELSIF Statement

Introduction

Syntax for ELSIF statement

if <condition> then 
      ...<<set of statements>>... 
elsif <condition> then 
      ...<<set of statements>>... 
elsif <condition> then 
      ...<<set of statements>>... 
else 
      ...<<set of statements>>... 
end if; 

Demo

SQL>
SQL>-- from w  ww .  ja  v a2s.  c om
SQL> create or replace function f_getDateType_tx (in_dt DATE)
  2  return VARCHAR2
  3  is
  4       v_out_tx VARCHAR2(10);
  5  begin
  6       if to_char(in_dt,'MMDD') in ('0101','0704') then
  7            v_out_tx:='HOLIDAY';
  8       elsif to_char(in_dt,'d') = 1 then
  9            v_out_tx:='SUNDAY';
 10       elsif to_char(in_dt,'d') = 7 then
 11            v_out_tx:='SATURDAY';
 12       else
 13            v_out_tx:='WEEKDAY';
 14       end if;
 15       return v_out_tx;
 16  end;
 17  /

Function created.

SQL> begin
  2     DBMS_OUTPUT.put_line(f_getDateType_tx(SYSDATE));
  3  end;
  4  /
SATURDAY

PL/SQL procedure successfully completed.
SQL>

Related Topic