Oracle PL/SQL Tutorial/PL SQL Programming/Decode

Материал из SQL эксперт
Перейти к: навигация, поиск

Use decode in PL/SQL

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