Mega Code Archive

 
Categories / Oracle PLSQL Tutorial / PL SQL Statements
 

CASE statements

A Traditional Condition Statement SQL> SQL> create or replace function f_getDateType (in_dt DATE)   2  return VARCHAR2   3  is   4      v_out VARCHAR2(10);   5  begin   6      if to_char(in_dt,'d') = 1 then   7          v_out:='SUNDAY';   8      elsif to_char(in_dt,'d') = 7 then   9          v_out:='SATURDAY';  10      else  11          v_out:='WEEKDAY';  12      end if;  13      return v_out;  14  end;  15  / Function created. A Condition Using a CASE Statement" case <selector>    when <valueA> then          ...<<set of statements>>...    when <valueB> then          ...<<set of statements>>...    else          ...<<set of statements>>... end case; SQL> SQL> create or replace function f_getDateType (in_dt DATE)   2  return VARCHAR2   3  is   4      v_out VARCHAR2(10);   5  begin   6      case to_char(in_dt,'d')   7          when 1 then   8              v_out:='SUNDAY';   9          when 7 then  10              v_out:='SATURDAY';  11          else  12              v_out:='WEEKDAY';  13      end case;  14      return v_out;  15  end;  16  / Function created.