Oracle PL/SQL - IF...ELSE statements

Introduction

PL/SQL has an ELSE construct to support else conditions.

Syntax

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

Demo

SQL>
SQL> create or replace function f_isSunday_tx (in_dt DATE)
  2  return VARCHAR2-- from  w w  w.  j av  a 2s.  co m
  3  is
  4        v_out_tx VARCHAR2(10);
  5        v_flag_b BOOLEAN;
  6  begin
  7        if to_char(in_dt,'d')=1 then
  8             v_out_tx:='Y';
  9        else
 10             v_out_tx:='N';
 11        end if;
 12        return v_out_tx;
 13  end;
 14  /

Function created.

SQL> begin
  2     DBMS_OUTPUT.put_line(f_isSunday_tx(SYSDATE));
  3  end;
  4  /
N

PL/SQL procedure successfully completed.

SQL>

Related Topic