Oracle PL/SQL - IF...THEN statements

Introduction

The syntax is:

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

To comment out everything within an IF...THEN statement, you need to add a NULL statement.

if salary < 1000 then 
   null; 
   /* 
   salary = 5000; 
   */ 
end if; 

The following code shows how to write a function that checks whether the specified day is Sunday.

Demo

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

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