0% found this document useful (0 votes)
4 views

Assignment 05 Jyoti

The document contains a series of PL/SQL programs and procedures that perform various tasks such as arranging numbers, calculating incentives based on targets, checking if a number is even or odd, and determining if a date falls on a weekend. Each program includes declarations, logic for processing, and output statements to display results. The document serves as an instructional guide for implementing PL/SQL functionalities in database management.

Uploaded by

seleniumjava63
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment 05 Jyoti

The document contains a series of PL/SQL programs and procedures that perform various tasks such as arranging numbers, calculating incentives based on targets, checking if a number is even or odd, and determining if a date falls on a weekend. Each program includes declarations, logic for processing, and output statements to display results. The document serves as an instructional guide for implementing PL/SQL functionalities in database management.

Uploaded by

seleniumjava63
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

ASSIGNMENT-05

Name-Jyoti Bist
3rd year,CSE

PL/SQL

1.Write a PL/SQL program to arrange the number of two variables in such a way that the small
number will store in num_small variable and large number will store in num_large variable.

DECLARE

num1 NUMBER := 10;

num2 NUMBER := 20;

num_small NUMBER;

num_large NUMBER;

BEGIN

IF num1 < num2 THEN

num_small := num1;

num_large := num2;

ELSE

num_small := num2;

num_large := num1;

END IF;

DBMS_OUTPUT.PUT_LINE('Small Number: ' || num_small);

DBMS_OUTPUT.PUT_LINE('Large Number: ' || num_large);

END;

2.Write a PL/SQL procedure to calculate the incentive on a target achieved and display the
message either the record updated or not.

CREATE OR REPLACE PROCEDURE calc_incentive(target_achieved NUMBER) AS

incentive NUMBER;

rows_updated NUMBER;

BEGIN
IF target_achieved >= 50000 THEN

incentive := target_achieved * 0.1;

ELSE

incentive := target_achieved * 0.05;

END IF;

UPDATE employees SET incentive_amount = incentive WHERE emp_id = 101;

rows_updated := SQL%ROWCOUNT;

IF rows_updated > 0 THEN

DBMS_OUTPUT.PUT_LINE('Record updated successfully.');

ELSE

DBMS_OUTPUT.PUT_LINE('No record updated.');

END IF;

END;

3.Write a PL/SQL program to check whether a number is even or odd.

DECLARE

num NUMBER := 7;

BEGIN

IF MOD(num, 2) = 0 THEN

DBMS_OUTPUT.PUT_LINE(num || ' is Even');

ELSE

DBMS_OUTPUT.PUT_LINE(num || ' is Odd');

END IF;

END;

4.Write a PL/SQL procedure to calculate the incentive on a specific target otherwise a general
incentive to be paid using IF-THEN-ELSE.

CREATE OR REPLACE PROCEDURE calc_incentive_specific(target_achieved NUMBER) AS


incentive NUMBER;

BEGIN

IF target_achieved >= 70000 THEN

incentive := target_achieved * 0.12;

ELSIF target_achieved >= 50000 THEN

incentive := target_achieved * 0.08;

ELSE

incentive := 5000;

END IF;

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

END;

5.Write a PL/SQL program to check whether a date falls on weekend i.e. SATURDAY or SUNDAY.

DECLARE

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

day_name VARCHAR2(20);

BEGIN

SELECT TO_CHAR(input_date, 'DAY') INTO day_name FROM DUAL;

IF TRIM(day_name) IN ('SATURDAY', 'SUNDAY') THEN

DBMS_OUTPUT.PUT_LINE('The date falls on a weekend.');

ELSE

DBMS_OUTPUT.PUT_LINE('The date is a weekday.');

END IF;

END;

6.Write a PL/SQL procedure to calculate incentive achieved according to the specific sale limit.

CREATE OR REPLACE PROCEDURE calc_incentive_sale(sale_amount NUMBER) AS

incentive NUMBER;
BEGIN

IF sale_amount > 100000 THEN

incentive := sale_amount * 0.15;

ELSE

incentive := sale_amount * 0.07;

END IF;

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

END;

7.Write a PL/SQL program to count the number of employees in department 50 and check whether
this department has any 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.Write a PL/SQL program to display the description against a grade.

DECLARE

grade CHAR(1) := 'A';

description VARCHAR2(50);

BEGIN
CASE grade

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

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

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

WHEN 'D' THEN description := 'Poor';

ELSE description := 'Invalid Grade';

END CASE;

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

END;

9.Write a PL/SQL program to count the number of employees in a specific department and check
vacancies.

DECLARE

dep_id NUMBER := 60;

emp_count NUMBER;

vacancies NUMBER := 50;

BEGIN

SELECT COUNT(*) INTO emp_count FROM employees WHERE department_id = dep_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.Write a PL/SQL program to display the description against a grade using CASE statement.

DECLARE

grade CHAR(1) := 'B';


description VARCHAR2(50);

BEGIN

SELECT CASE grade

WHEN 'A' THEN 'Excellent'

WHEN 'B' THEN 'Good'

WHEN 'C' THEN 'Average'

WHEN 'D' THEN 'Poor'

ELSE 'Invalid Grade'

END INTO description FROM DUAL;

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

END;

11. PL/SQL Program to Display Grade Description using CASE Statement with EXCEPTION

DECLARE

grade CHAR(1) := 'A'; -- Example grade

grade_description VARCHAR2(100);

BEGIN

grade_description :=

CASE grade

WHEN 'A' THEN 'Excellent'

WHEN 'B' THEN 'Good'

WHEN 'C' THEN 'Average'

WHEN 'D' THEN 'Below Average'

ELSE 'Grade not recognized'

END;

DBMS_OUTPUT.PUT_LINE('Grade Description: ' || grade_description);

EXCEPTION

WHEN OTHERS THEN


DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);

END;

12. PL/SQL Program to Check Whether a Given Number is Positive, Negative, or Zero

DECLARE

num INTEGER := -10; -- Example number

BEGIN

IF num > 0 THEN

DBMS_OUTPUT.PUT_LINE('Positive');

ELSIF num < 0 THEN

DBMS_OUTPUT.PUT_LINE('Negative');

ELSE

DBMS_OUTPUT.PUT_LINE('Zero');

END IF;

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);

END;

13. PL/SQL Program to Check Whether a Given Character is a Letter or Digit

DECLARE

ch CHAR := '5'; -- Example character

BEGIN

IF (ch >= '0' AND ch <= '9') THEN

DBMS_OUTPUT.PUT_LINE('Digit');

ELSIF ((ch >= 'A' AND ch <= 'Z') OR (ch >= 'a' AND ch <= 'z')) THEN

DBMS_OUTPUT.PUT_LINE('Letter');

ELSE

DBMS_OUTPUT.PUT_LINE('Neither letter nor digit');


END IF;

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);

END;

14. PL/SQL Program to Convert Temperature from Fahrenheit to Celsius and Vice Versa

DECLARE

fahrenheit NUMBER := 98.6; -- Example temperature in Fahrenheit

celsius NUMBER;

BEGIN

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

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

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);

END;

To convert Celsius to Fahrenheit, use:

fahrenheit := celsius * 9/5 + 32;

15. PL/SQL Program to Display Which Day a Specific Date Falls On

DECLARE

input_date DATE := TO_DATE('2025-03-10', 'YYYY-MM-DD'); -- Example date

day_name VARCHAR2(20);

BEGIN

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

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

EXCEPTION

WHEN OTHERS THEN


DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);

END;

You might also like