Case – When – Then

Case

Syntax and examples of conditional Case – When – Then – Else.

CREATE OR REPLACE FUNCTION 
	get_case(in p_name varchar(2)) 
RETURNS varchar AS $$
DECLARE
	v_name varchar(50);
BEGIN
	CASE WHEN p_name = 'T' then
		v_name:='The name is TEST';
		return v_name;
	ELSE
		v_name:='The name is XYZ';
		return v_name;
	END CASE;		
END;
$$ LANGUAGE 'plpgsql';  

Control structures |
IF |
IF Else |
IF Elsif Else |
LOOP