Oracle PL/SQL - Using boolean variable in IF statement

Introduction

IF condition may be either a Boolean expression or Boolean variable.

Demo

SQL>
SQL> create or replace function f_isSunday_tx (in_dt DATE)
  2  return VARCHAR2-- w  ww .  j a  v  a 2 s  . c om
  3  is
  4        v_out_tx VARCHAR2(10);
  5        v_flag_b BOOLEAN;
  6  begin
  7        v_flag_b := to_char(in_dt,'d')=1;
  8        if v_flag_b then
  9             v_out_tx:='Y';
 10             DBMS_OUTPUT.put_line('IsSunday=Y');
 11        end if;
 12        return v_out_tx;
 13  end;
 14  /

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

PL/SQL procedure successfully completed.

SQL>

Related Topic