Database Reference
In-Depth Information
Let's implement the nest_if() function for CASE :
warehouse_db=# CREATE OR REPLACE FUNCTION simple_case(marks
integer)
RETURNS text AS $$
DECLARE
grade text;
BEGIN
CASE marks
WHEN 34,40 THEN
grade := 'PASS';
RETURN grade;
WHEN 33 THEN
grade := 'FAIL';
RETURN grade;
ELSE
grade := 'Did not appear in exam';
RETURN grade;
END CASE;
END;
$$ LANGUAGE plpgsql;
The result with 33 marks can be seen using the following statement:
warehouse_db=# SELECT simple_case(33);
simple_case
-------------
FAIL
(1 row)
The result with 34 marks can be seen using the following statement:
warehouse_db=# SELECT simple_case(34);
simple_case
-------------
PASS
(1 row)
The result with 40 marks can be seen using the following statement:
warehouse_db=# SELECT simple_case(40);
simple_case
-------------
PASS
(1 row)
 
Search WWH ::




Custom Search