PL/SQL If-Then-ElsIf-Else

Oracle PL/SQL If-Then-ElsIf-Else Example

CREATE OR REPLACE Function Sales_Report
( p_user_name IN varchar2 ) RETURN varchar2
IS
	sale_amount number(12);
	message     varchar2(20);
	Cursor c is
		Select sum(o.amount)
		From offers o, users u
		Where o.user_code=u.user_code
		And u.name = p_user_name;
BEGIN
	Open c;
		Fetch c Into sale_amount;
	Close c;

	IF sale_amount <= 5000 THEN  
		message := 'Low Sales';
	ELSIF sale_amount > 5000 and sale_amount <= 10000 THEN 
		message := 'Avg Salese';
	ELSIF sale_amount > 10000 and sale_amount <= 50000 THEN
		message := 'Moderate Sales';
	ELSE 
		message := 'High Sales';
	END IF;
RETURN message;
END;