Use decode in PL/SQL : Decode « PL SQL Programming « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL> CREATE OR REPLACE FUNCTION AverageGrade (p_Course IN NUMBER) RETURN VARCHAR2 AS
  2  v_NumericGrade varchar(1);
  3  BEGIN
  4    SELECT DECODE(ROUND(p_Course), 5, 'A',
  5                                         4, 'B',
  6                                         3, 'C',
  7                                         2, 'D',
  8                                         1, 'E')
  9      INTO v_NumericGrade
 10      FROM dual;
 11
 12    RETURN v_NumericGrade;
 13  END AverageGrade;
 14  /

Function created.

SQL>
SQL>
SQL> select AverageGrade(1) from dual;

AVERAGEGRADE(1)
----------------------
E








24.5.Decode
24.5.1.Use decode in PL/SQL