Skip to content

Instantly share code, notes, and snippets.

@rithask
Last active November 7, 2023 02:50
Show Gist options
  • Save rithask/426e86eb23e0ac4acfc2baf104639923 to your computer and use it in GitHub Desktop.
Save rithask/426e86eb23e0ac4acfc2baf104639923 to your computer and use it in GitHub Desktop.
PL/SQL block to determines the category/type of customer after verifying their account balance
/*
AIM:
Create a pl/sql block for creating a function dc that determines the category/type of customer after verifying their account balance. The following are the categories category platinum(for account balance greater than 50k) , gold (account balance less than or equal to 50k but greater than 10k) ,silver(for account balance less than or equal to 10k). Assume necessary attributes in customer. Write a query to retrieve the details of customers along with customer category(using the created function dc)
*/
-- Create the function dc to determine the customer category
CREATE OR REPLACE FUNCTION dc(balance NUMBER)
RETURN VARCHAR2 IS
category VARCHAR2(20);
BEGIN
IF balance > 50000 THEN
category := 'Platinum';
ELSIF balance <= 50000 AND balance > 10000 THEN
category := 'Gold';
ELSE
category := 'Silver';
END IF;
RETURN category;
END;
/
-- Now, you can use the dc function in a query to retrieve customer details with their categories
SELECT customer_name, account_balance, dc(account_balance) AS customer_category
FROM Customer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment