0% found this document useful (0 votes)
5 views9 pages

Snehal Assignment

The document contains a series of PL/SQL code snippets demonstrating various programming tasks such as arranging numbers, calculating incentives, checking if numbers are even or odd, and determining if a date falls on a weekend. It also includes procedures for calculating specific incentives based on sales and checking employee counts in departments. Additionally, it showcases the use of conditional statements, exception handling, and basic data conversions.

Uploaded by

seleniumjava63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views9 pages

Snehal Assignment

The document contains a series of PL/SQL code snippets demonstrating various programming tasks such as arranging numbers, calculating incentives, checking if numbers are even or odd, and determining if a date falls on a weekend. It also includes procedures for calculating specific incentives based on sales and checking employee counts in departments. Additionally, it showcases the use of conditional statements, exception handling, and basic data conversions.

Uploaded by

seleniumjava63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Snehal lal das

220240170057
Btech CSE(AI & ML) 3rd year

1. Arrange two numbers in small_num and large_num

DECLARE

num1 NUMBER := 10;

num2 NUMBER := 20;

small_num NUMBER;

large_num NUMBER;

BEGIN

IF num1 < num2 THEN

small_num := num1;

large_num := num2;

ELSE

small_num := num2;

large_num := num1;

END IF;

DBMS_OUTPUT.PUT_LINE('Small: ' || small_num || ', Large: ' || large_num);

END;

2. Procedure to calculate incentive and check update status

CREATE OR REPLACE PROCEDURE calc_incentive (emp_id NUMBER, target NUMBER) AS

incentive NUMBER;
updated NUMBER;

BEGIN

IF target >= 10000 THEN

incentive := target * 0.1;

ELSE

incentive := target * 0.05;

END IF;

UPDATE employees SET incentive = incentive WHERE emp_id = emp_id;

updated := SQL%ROWCOUNT;

IF updated > 0 THEN

DBMS_OUTPUT.PUT_LINE('Record updated successfully');

ELSE

DBMS_OUTPUT.PUT_LINE('No record updated');

END IF;

END;

3. Check if a number is even or odd

DECLARE

num NUMBER := 15;

BEGIN

IF MOD(num, 2) = 0 THEN

DBMS_OUTPUT.PUT_LINE('Even Number');
ELSE

DBMS_OUTPUT.PUT_LINE('Odd Number');

END IF;

END;

4. Procedure to calculate specific/general incentive

CREATE OR REPLACE PROCEDURE calc_incentive (target NUMBER) AS

incentive NUMBER;

BEGIN

IF target >= 20000 THEN

incentive := target * 0.15;

ELSE

incentive := target * 0.05;

END IF;

DBMS_OUTPUT.PUT_LINE('Incentive: ' || incentive);

END;

5. Check if a date falls on a weekend

DECLARE

check_date DATE := SYSDATE;

check_day VARCHAR2(10);

BEGIN

check_day := TO_CHAR(check_date, 'DAY');


IF check_day IN ('SATURDAY', 'SUNDAY') THEN

DBMS_OUTPUT.PUT_LINE('It is a weekend');

ELSE

DBMS_OUTPUT.PUT_LINE('It is a weekday');

END IF;

END;

6. Procedure to calculate incentive based on sale limit

CREATE OR REPLACE PROCEDURE sale_incentive (sales NUMBER) AS

incentive NUMBER;

BEGIN

IF sales > 50000 THEN

incentive := sales * 0.2;

ELSE

incentive := sales * 0.1;

END IF;

DBMS_OUTPUT.PUT_LINE('Incentive: ' || incentive);

END;

7. Count employees in department 50 and check vacancies

DECLARE

emp_count NUMBER;

vacancies NUMBER := 45;


BEGIN

SELECT COUNT(*) INTO emp_count FROM employees WHERE department_id = 50;

IF emp_count < vacancies THEN

DBMS_OUTPUT.PUT_LINE('Vacancies available: ' || (vacancies - emp_count));

ELSE

DBMS_OUTPUT.PUT_LINE('No vacancies available');

END IF;

END;

8. Display grade description

DECLARE

grade CHAR := 'A';

description VARCHAR2(50);

BEGIN

CASE grade

WHEN 'A' THEN description := 'Excellent';

WHEN 'B' THEN description := 'Good';

WHEN 'C' THEN description := 'Average';

ELSE description := 'Fail';

END CASE;

DBMS_OUTPUT.PUT_LINE('Grade: ' || description);

END;

/
9. Count employees in any department and check vacancies

DECLARE

dept_id NUMBER := 10;

emp_count NUMBER;

vacancies NUMBER := 30;

BEGIN

SELECT COUNT(*) INTO emp_count FROM employees WHERE department_id = dept_id;

IF emp_count < vacancies THEN

DBMS_OUTPUT.PUT_LINE('Vacancies available: ' || (vacancies - emp_count));

ELSE

DBMS_OUTPUT.PUT_LINE('No vacancies available');

END IF;

END;

10. Display grade description using CASE statement

DECLARE

grade CHAR := 'B';

description VARCHAR2(50);

BEGIN

description := CASE grade

WHEN 'A' THEN 'Excellent'

WHEN 'B' THEN 'Good'

WHEN 'C' THEN 'Average'

ELSE 'Fail'
END;

DBMS_OUTPUT.PUT_LINE('Grade: ' || description);

END;

-- 11. Grade description using CASE statement with EXCEPTION

DECLARE

grade CHAR := 'Z';

description VARCHAR2(50);

BEGIN

BEGIN

description := CASE grade

WHEN 'A' THEN 'Excellent'

WHEN 'B' THEN 'Good'

WHEN 'C' THEN 'Average'

ELSE RAISE_APPLICATION_ERROR(-20001, 'Invalid Grade');

END;

EXCEPTION

WHEN OTHERS THEN description := 'Error: Invalid Grade';

END;

DBMS_OUTPUT.PUT_LINE('Grade: ' || description);

END;

-- 12. Check if number is positive, negative, or zero


DECLARE

num NUMBER := -5;

BEGIN

IF num > 0 THEN

DBMS_OUTPUT.PUT_LINE('Positive Number');

ELSIF num < 0 THEN

DBMS_OUTPUT.PUT_LINE('Negative Number');

ELSE

DBMS_OUTPUT.PUT_LINE('Zero');

END IF;

END;

-- 13. Check if a character is letter or digit

DECLARE

ch CHAR := 'A';

BEGIN

IF ch BETWEEN '0' AND '9' THEN

DBMS_OUTPUT.PUT_LINE('Digit');

ELSIF ch BETWEEN 'A' AND 'Z' OR ch BETWEEN 'a' AND 'z' THEN

DBMS_OUTPUT.PUT_LINE('Letter');

ELSE

DBMS_OUTPUT.PUT_LINE('Other Character');

END IF;

END;
/

-- 14. Convert temperature

DECLARE

fahrenheit NUMBER := 100;

celsius NUMBER;

BEGIN

celsius := (fahrenheit - 32) * 5/9;

DBMS_OUTPUT.PUT_LINE('Celsius: ' || celsius);

END;

-- 15. Find day of a date

DECLARE

input_date DATE := '10-MAR-2025';

day_name VARCHAR2(20);

BEGIN

day_name := TO_CHAR(input_date, 'DAY');

DBMS_OUTPUT.PUT_LINE('Day: ' || day_name);

END;

You might also like