Untitled 1
Untitled 1
viii. Write a PL/SQL program to print the given number is odd or even.
Sample Output
S_No Name Designation Branch
ii. Alter the table by modifying the column Name (Example: Increase the length)
DESCRIBE workers;
Sample Output
Field Type Null Key Default Extra
S_No INT YES NULL
Name VARCHAR(100) YES NULL
Designation VARCHAR(50) YES NULL
Branch VARCHAR(50) YES NULL
Salary DECIMAL(10,2) YES NULL
Sample Output
The table workers is now empty.
Sample Output
S_No Name Designation Branch Salary
1 John Doe Manager New York 60000
3 Sam Brown Developer San Francisco 55000
Sample Output
The table workers is now deleted from the database.
viii. Write a PL/SQL program to print whether a given number is odd or even
Here’s a simple PL/SQL program to check if a number is odd or even:
DECLARE
num NUMBER := &Enter_Number;
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;
/
Sample Output
For example, if num is entered as 7, the output will be:
csharp
Copy code
7 is Odd
Sample Data
Let's insert some sample data into both tables for demonstration purposes.
Sample Output
register_no mark1 mark2 mark3 total
161 85 90 80 255
162 78 88 95 261
164 90 85 80 255
ii. Drop the table mark_details and delete the row whose register_no =
161
1. Drop the mark_details table:
Sample Output
register_no student_name DOB address city
162 Alex 2002-07-21 456 Oak St Los Angeles
164 Anna 2002-05-05 321 Elm St Seattle
iv. Write a PL/SQL program to print the details of the student when
register_no is given as input
Here’s a PL/SQL program that accepts a registration number as input and prints the student's details.
DECLARE
v_register_no student_details.register_no%TYPE := &Enter_RegNo;
v_student_name student_details.student_name%TYPE;
v_DOB student_details.DOB%TYPE;
v_address student_details.address%TYPE;
v_city student_details.city%TYPE;
BEGIN
SELECT student_name, DOB, address, city
INTO v_student_name, v_DOB, v_address, v_city
FROM student_details
WHERE register_no = v_register_no;
DBMS_OUTPUT.PUT_LINE('Student Details:');
DBMS_OUTPUT.PUT_LINE('Register No : ' || v_register_no);
DBMS_OUTPUT.PUT_LINE('Name : ' || v_student_name);
DBMS_OUTPUT.PUT_LINE('DOB : ' || TO_CHAR(v_DOB, 'YYYY-MM-DD'));
DBMS_OUTPUT.PUT_LINE('Address : ' || v_address);
DBMS_OUTPUT.PUT_LINE('City : ' || v_city);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No student found with Register No: ' ||
v_register_no);
END;
/
Sample Output
If the register_no is entered as 162, the output would be:
Student Details:
Register No : 162
Name : Alex
DOB : 2002-07-21
Address : 456 Oak St
City : Los Angeles
Sample Data
Let's add some sample data to the tables to demonstrate the queries.
INSERT INTO Customer (Customer_id, Customer_name, Age, phone_no)
VALUES (101, 'Alice', 30, '123-456-7890'),
(102, 'Bob', 45, '234-567-8901'),
(103, 'Carol', 28, '345-678-9012');
Sample Output
Customer_id Total_Loan_Amount
101 8000
102 4000
103 2500
Sample Output
Customer_id Customer_name
102 Bob
103 Carol
DBMS_OUTPUT.PUT_LINE('Customer Details:');
DBMS_OUTPUT.PUT_LINE('Customer ID : ' || v_Customer_id);
DBMS_OUTPUT.PUT_LINE('Name : ' || v_Customer_name);
DBMS_OUTPUT.PUT_LINE('Age : ' || v_Age);
DBMS_OUTPUT.PUT_LINE('Phone Number : ' || v_phone_no);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No customer found with Customer ID:
' || v_Customer_id);
END;
/
Sample Output
If the Customer_id is entered as 101, the output would be:
Customer Details:
Customer ID : 101
Name : Alice
Age : 30
Phone Number : 123-456-7890
If no record is found, the output will be:
No customer found with Customer ID: [entered Customer_id]
4.Consider the following database for a Banking Enterprise.
Branch{branch_name, branch_city, assets) Account(accno,
branch_name, balance} Depositor {customer_name, accno)
Customer(customer_name, customer_street, customer_city} Loan
{loan_number, branch_name, amount} Borrower { customer_name,
loan_number)}
i. Create the above tables by properly specifying the primary keys
and foreign keys and enter at least five tuples for each relation.
ii. Find all the customers who have at least two accounts at the
main branch.
iii. Find all the customers who have an account at all the
branches located in a specific city. iv. Write a PL/SQL program to
delete all account tuples at every branch located in a specific
city
Step 1: Create the Tables with Primary and Foreign Key Constraints
CREATE TABLE Branch (
branch_name VARCHAR(50) PRIMARY KEY,
branch_city VARCHAR(50),
assets DECIMAL(15, 2)
);
ii. Find all the customers who have at least two accounts
at the Main branch
SELECT d.customer_name
FROM Depositor d
JOIN Account a ON d.accno = a.accno
WHERE a.branch_name = 'Main'
GROUP BY d.customer_name
HAVING COUNT(d.accno) >= 2;
Sample Output
customer_name
Alice
iii. Find all the customers who have an account at all the branches located in a
specific city (e.g., 'New York')
To find customers who have an account at all branches in a specific city, say New York, we’ll use
a subquery.
SELECT d.customer_name
FROM Depositor d
JOIN Account a ON d.accno = a.accno
JOIN Branch b ON a.branch_name = b.branch_name
WHERE b.branch_city = 'New York'
GROUP BY d.customer_name
HAVING COUNT(DISTINCT a.branch_name) = (SELECT COUNT(branch_name)
FROM Branch
WHERE branch_city = 'New York');
Sample Output
customer_name
Alice
Bob
iv. Write a PL/SQL program to delete all account tuples at every branch located
in a specific city
Here's a PL/SQL program that deletes all account records for branches located in a specified city.
The program will take the city as input.
DECLARE
v_city VARCHAR(50) := '&Enter_City';
BEGIN
DELETE FROM Account
WHERE branch_name IN (SELECT branch_name FROM Branch WHERE branch_city =
v_city);
Sample Output
If the input city is New York, the output will be:
i. Display the total number of boys' and girls' hostels in the college
sql
Copy code
SELECT type, COUNT(*) AS Total_Hostels
FROM Hostel
GROUP BY type;
Sample Output
type Total_Hostels
boys 2
girls 2
Sample Output
hname Number_of_Wardens
Alpha Hostel 1
Beta Hostel 1
Gamma Hostel 1
Delta Hostel 1
IF is_prime THEN
DBMS_OUTPUT.PUT_LINE(num || ' is a prime number.');
ELSE
DBMS_OUTPUT.PUT_LINE(num || ' is not a prime number.');
END IF;
END;
/
Sample Output
If the entered number is 7:
csharp
Copy code
7 is a prime number.
If the entered number is 10:
csharp
Copy code
10 is not a prime number.
a) Find all employees in the database who earn more than each employee of
Small Bank Corporation
To find employees who earn more than each employee of Small Bank Corporation, we’ll
use a subquery.
sql
Copy code
SELECT w1.employee_name
FROM Works w1
WHERE w1.salary > ALL (
SELECT w2.salary
FROM Works w2
WHERE w2.company_name = 'Small Bank Corporation'
);
Sample Output
employee_name
Eve
Sample Output
company_name
Small Bank Corporation
First Bank Corporation
Sample Output
employee_name company_name salary
Bob First Bank Corporation 103500
Sample Output
If the entered number is 153:
csharp
Copy code
153 is an Armstrong number.
a) Print the names of employees who have borrowed any books published by
McGrawHill
sql
Copy code
SELECT DISTINCT e.name
FROM Employee e
JOIN Loan l ON e.empno = l.empno
JOIN Books b ON l.isbn = b.isbn
WHERE b.publisher = 'McGrawHill';
Sample Output
name
Alice
Bob
Carol
Eve
b) Print the names of employees who have borrowed all books published by
McGrawHill
To check if an employee has borrowed all books published by McGrawHill, we need to compare the
count of distinct McGrawHill books borrowed by each employee with the total number of
McGrawHill books.
sql
Copy code
SELECT e.name
FROM Employee e
JOIN Loan l ON e.empno = l.empno
JOIN Books b ON l.isbn = b.isbn
WHERE b.publisher = 'McGrawHill'
GROUP BY e.name
HAVING COUNT(DISTINCT b.isbn) = (SELECT COUNT(DISTINCT isbn) FROM Books WHERE
publisher = 'McGrawHill');
Sample Output
name
Eve
c) For each publisher, print the names of employees who have borrowed more
than five books of that publisher
sql
Copy code
SELECT b.publisher, e.name
FROM Employee e
JOIN Loan l ON e.empno = l.empno
JOIN Books b ON l.isbn = b.isbn
GROUP BY b.publisher, e.name
HAVING COUNT(l.isbn) > 5;
Sample Output
(Adjust the table as necessary based on actual data.)
publisher name
Pearson Eve
Sample Output
If the input numbers are 45, 78, and 32:
csharp
Copy code
The greatest number is: 78
10.i. Create a table as book (sl.no, book_name, author_name,price,
edition,publisher_name ). Perform the following operations:
a) Insert minimum ten tuples in book table
b) Commit the table book
c) Create a save point for the table book as B
d) Rollback the table book after inserting 4 & 5 row e) Define
Grant & Revoke ii.Create a view contains slno,book_name,price. iv.
Write a PL/SQL program to print the greatest of two numbers
-- Rollback to savepoint B
ROLLBACK TO B;
After rolling back, only rows 1-3 will remain in the table.
• REVOKE: The REVOKE command is used to remove previously granted privileges from a
user or role.
sql
Copy code
REVOKE INSERT ON book FROM some_user;
DECLARE
num1 INT := &Enter_Number1;
num2 INT := &Enter_Number2;
BEGIN
IF num1 > num2 THEN
DBMS_OUTPUT.PUT_LINE('The greatest number is: ' || num1);
ELSIF num2 > num1 THEN
DBMS_OUTPUT.PUT_LINE('The greatest number is: ' || num2);
ELSE
DBMS_OUTPUT.PUT_LINE('Both numbers are equal: ' || num1);
END IF;
END;
/
Sample Output
If the entered numbers are 45 and 78:
b) Create a View for All Salesmen with Columns salesman_id, name, and
city
sql
Copy code
CREATE VIEW all_salesmen AS
SELECT salesman_id, name, city
FROM salesman;
c) Find the Salesmen of the City New York Who Achieved the Commission More
Than 13%
sql
Copy code
SELECT *
FROM salesman
WHERE city = 'New York' AND commission > 0.13;
Sample Output
salesman_id name city commission
1 Alice Johnson New York 0.15
5 Eve Black New York 0.14
grade customer_count
A 3
B 3
grade customer_count
C 2
Sample Output
If the entered numbers are 45, 78, and 32:
csharp
Copy code
The greatest number is: 78
Sample Output
Customer_id Total_Loan_Amount
1 3000.00
2 1500.00
3 3000.00
4 3000.00
iii. Display the Customer_id and Customer_name Who Have Taken Less Than
Two Loans
sql
Copy code
SELECT c.Customer_id, c.Customer_name
FROM Customer c
LEFT JOIN Loan l ON c.Customer_id = l.Customer_id
GROUP BY c.Customer_id, c.Customer_name
HAVING COUNT(l.Loan_id) < 2;
Sample Output
Customer_id Customer_name
2 Bob Smith
4 David Brown
iv. Write a PL/SQL Program to Print the Details of the Customer When
customerid is Given as Input
Here’s a PL/SQL program that takes a customer ID as input and prints the customer's details.
sql
Copy code
DECLARE
v_customer_id INT := &Enter_CustomerID; -- Prompt for customer ID
v_customer_name VARCHAR(100);
v_age INT;
v_phone_no VARCHAR(15);
BEGIN
SELECT Customer_name, Age, phone_no
INTO v_customer_name, v_age, v_phone_no
FROM Customer
WHERE Customer_id = v_customer_id;
Sample Output
If the input customer ID is 1:
yaml
Copy code
Customer ID: 1
Customer Name: Alice Johnson
Age: 30
Phone Number: 555-1234
Sample Output
reg_no stu_name months_since_dob
101 Alice Johnson 297
102 Bob Smith 303
103 Carol White 274
c) Using ALTER Command Drop the Column address from the Table
stu_details
sql
Copy code
ALTER TABLE stu_details
DROP COLUMN address;
d) Write a PL/SQL Program to Find the Sum & Average Marks of All Students
Using Procedures
Here’s a PL/SQL program that calculates the total and average marks of all students.
sql
Copy code
CREATE OR REPLACE PROCEDURE calculate_marks AS
v_total_marks INT := 0;
v_average_marks NUMBER := 0;
v_count INT := 0;
BEGIN
FOR rec IN (SELECT total FROM mark_details) LOOP
v_total_marks := v_total_marks + rec.total;
v_count := v_count + 1;
END LOOP;
Sample Output
yaml
Copy code
Total Marks: 765
Average Marks: 255.00
14.Employee (Empno,Ename, Job,MgrId, DoB,DoJ,
Sal,Comm,Deptno) Department (Dname,Deptno,Dloc) (a)
Display the Emp no, name, salary and experience of each
employee ordered by salary (highest to lowest) (b) List
the names of the employee working for “Marketing”
Department. (c) List the names of the employees born in
the current month. (d) Write a PL/SQL function to display
the details of the employee when Employee no given as
input.
a) Display the Emp no, Name, Salary, and Experience of Each Employee
Ordered by Salary (Highest to Lowest)
To calculate the experience, we can use the SYSDATE to find the difference between the joining
date and the current date.
sql
Copy code
SELECT Empno, Ename, Sal,
TRUNC(MONTHS_BETWEEN(SYSDATE, DoJ)) AS Experience
FROM Employee
ORDER BY Sal DESC;
Sample Output
Empno Ename Sal Experience
1 Alice Johnson 90000 168
4 David Brown 70000 56
2 Bob Smith 60000 106
5 Eve Black 55000 26
3 Carol White 50000 64
b) List the Names of the Employees Working for the “Marketing” Department
sql
Copy code
SELECT E.Ename
FROM Employee E
JOIN Department D ON E.Deptno = D.Deptno
WHERE D.Dname = 'Marketing';
Sample Output
Ename
Alice Johnson
Eve Black
v_details := 'Employee No: ' || p_empno || ', Name: ' || v_name || ', Job: '
|| v_job ||
', DOB: ' || TO_CHAR(v_dob, 'YYYY-MM-DD') || ', DOJ: ' ||
TO_CHAR(v_doj, 'YYYY-MM-DD') ||
', Salary: ' || v_sal || ', Commission: ' || v_comm || ', Dept
No: ' || v_deptno;
RETURN v_details;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 'No employee found with the given employee number.';
WHEN OTHERS THEN
RETURN 'Error: ' || SQLERRM;
END;
/
Sample Usage
To execute the function and display the details of an employee with Empno 1:
sql
Copy code
DECLARE
emp_details VARCHAR2(400);
BEGIN
emp_details := get_employee_details(1);
DBMS_OUTPUT.PUT_LINE(emp_details);
END;
/
Sample Output
yaml
Copy code
Employee No: 1, Name: Alice Johnson, Job: Manager, DOB: 1985-06-15, DOJ: 2010-
01-10, Salary: 90000, Commiss
15. Write the Query statement for the following a. Create a
Student table (Regno, name, dept) and populate with data. b.
Create a view for CSE dept with the details of students of CSE
dept. c. Implement TCL commands with student table. d.Write a
PL/SQL program to find the details of the student when regno is
given as input.
b. Create a View for CSE Dept with the Details of Students of CSE Dept
sql
Copy code
CREATE VIEW CSE_Students AS
SELECT *
FROM Student
WHERE Dept = 'CSE';
-- COMMIT example
COMMIT; -- Commit the current transaction
-- ROLLBACK example
ROLLBACK; -- Rollback the current transaction
-- SAVEPOINT example
SAVEPOINT before_insertion;
v_details := 'Regno: ' || p_regno || ', Name: ' || v_name || ', Dept: ' ||
v_dept;
RETURN v_details;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 'No student found with the given registration number.';
WHEN OTHERS THEN
RETURN 'Error: ' || SQLERRM;
END;
/
Sample Output
yaml
Copy code
Regno: 1, Name: Alice Johnson, Dept: CSE
16. Create a database for Placement and Training cell.
Stud_details(regno, name, dept, percentage)
Company(companyID,name, noOfVacancy) Training_Details(CourseID,
name, Trainer) Placed(regno, companyID,minSal) i List the students
who are eligible for recruitment in a particular company. ii
Display the student who has been placed with highest salary iii
Develop a PL/SQL exception that provides an alternate for not
eligible students. iv Write a PL/SQL program to print the
factorial of given number
i. List the Students Who Are Eligible for Recruitment in a Particular Company
sql
Copy code
SELECT S.Name
FROM Stud_details S
JOIN Company C ON S.Percentage >= 75
WHERE C.CompanyID = 1; -- Change the company ID as needed
Sample Output
Name
Alice Johnson
Carol White
Eve Black
ii. Display the Student Who Has Been Placed with Highest Salary
sql
Copy code
SELECT S.Name, P.MinSal
FROM Stud_details S
JOIN Placed P ON S.Regno = P.Regno
ORDER BY P.MinSal DESC
FETCH FIRST 1 ROW ONLY;
Sample Output
Name MinSal
Eve Black 70000
iii. Develop a PL/SQL Exception that Provides an Alternate for Not Eligible Students
sql
Copy code
CREATE OR REPLACE PROCEDURE check_student_eligibility(p_regno IN INT) AS
v_percentage DECIMAL(5, 2);
BEGIN
SELECT Percentage INTO v_percentage
FROM Stud_details
WHERE Regno = p_regno;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No student found with the given registration
number.');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error: ' || SQLERRM);
END;
/
Sample Output
rust
Copy code
Student not eligible for recruitment.
Sample Output
csharp
Copy code
Factorial of 5 is 120
17. Create a database for the following tables. Hostel (hno,
hname, type [boys/girls]) Menu (hno, day, breakfast, lunch,
dinner) Warden (wname, qual, hno) Student (sid, sname, gender,
year, hno)
i. Display the total number of girls and boys hostel in the
college.
ii. Display the menu in the hostel ‘x’ on Tuesday.
iii. Display the number of wardens for each hostel.II.
iv. Write a PL/SQL program to print given number is Prime or not.
i. Display the Total Number of Girls and Boys Hostels in the College
sql
Copy code
SELECT Type, COUNT(*) AS Total_Hostels
FROM Hostel
GROUP BY Type;
Sample Output
Type Total_Hostels
boys 2
girls 2
ii. Display the Menu in the Hostel ‘x’ on Tuesday
sql
Copy code
-- Replace 'x' with the hostel number you want to query, for example, 2.
SELECT *
FROM Menu
WHERE Hno = 2 AND Day = 'Tuesday';
Sample Output
Hno Day Breakfast Lunch Dinner
2 Tuesday Fruit Salad Vegetable Curry Rice
iii. Display the Number of Wardens for Each Hostel
sql
Copy code
SELECT Hno, COUNT(*) AS Number_of_Wardens
FROM Warden
GROUP BY Hno;
Sample Output
Hno Number_of_Wardens
1 1
2 1
3 1
4 1
iv. Write a PL/SQL Program to Print Given Number is Prime or Not
sql
Copy code
CREATE OR REPLACE FUNCTION is_prime(n IN INT) RETURN VARCHAR2 IS
v_is_prime BOOLEAN := TRUE;
BEGIN
IF n <= 1 THEN
RETURN n || ' is not a prime number.';
END IF;
IF v_is_prime THEN
RETURN n || ' is a prime number.';
ELSE
RETURN n || ' is not a prime number.';
END IF;
END;
/
Sample Output
csharp
Copy code
11 is a prime number.
18. Consider the following database of student enrollment in
courses and books adopted for that course. STUDENT(regno, name,
major, bdate) COURSE(courseno, cname, dept) ENROLL(regno,
courseno, sem, marks)
i. Display the total number of students register for more than two
courses in a department specified.
ii. Display the students who have secured the highest mark in each
course
iii. List the youngest student of each course in all departments.
iv. Develop PL/SQL program that selects marks of a particular
student in a specified semester.
i. Display the Total Number of Students Registered for More Than Two Courses in a Specified
Department
sql
Copy code
SELECT S.Major, COUNT(S.Regno) AS Total_Students
FROM STUDENT S
JOIN ENROLL E ON S.Regno = E.Regno
JOIN COURSE C ON E.Courseno = C.Courseno
WHERE C.Dept = 'CSE'
GROUP BY S.Major
HAVING COUNT(E.Courseno) > 2;
Sample Output
Major Total_Students
CSE 1
ii. Display the Students Who Have Secured the Highest Mark in Each Course
sql
Copy code
SELECT E.Courseno, S.Name, MAX(E.Marks) AS Highest_Mark
FROM ENROLL E
JOIN STUDENT S ON E.Regno = S.Regno
GROUP BY E.Courseno, S.Name
HAVING MAX(E.Marks) = E.Marks;
Sample Output
Courseno Name Highest_Mark
101 Alice 95
102 Carol 91
iii. List the Youngest Student of Each Course in All Departments
sql
Copy code
SELECT C.Courseno, S.Name, S.Bdate
FROM STUDENT S
JOIN ENROLL E ON S.Regno = E.Regno
JOIN COURSE C ON E.Courseno = C.Courseno
WHERE S.Bdate = (
SELECT MAX(Bdate)
FROM STUDENT
WHERE Regno IN (SELECT Regno FROM ENROLL WHERE Courseno = C.Courseno)
);
Sample Output
Courseno Name Bdate
101 Carol 2002-01-20
102 Alice 2001-05-10
iv. Develop PL/SQL Program That Selects Marks of a Particular Student in a Specified
Semester
sql
Copy code
CREATE OR REPLACE FUNCTION get_student_marks(p_regno IN INT, p_sem IN INT)
RETURN VARCHAR2 IS
v_marks DECIMAL(5, 2);
BEGIN
SELECT Marks INTO v_marks
FROM ENROLL
WHERE Regno = p_regno AND Sem = p_sem;
RETURN 'Marks for student ' || p_regno || ' in semester ' || p_sem || ' is '
|| v_marks;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 'No marks found for the specified student and semester.';
WHEN OTHERS THEN
RETURN 'Error: ' || SQLERRM;
END;
/
Sample Output
csharp
Copy code
Marks for student 1 in semester 1 is 90
19. Create a database for Placement and Training cell.
Stud_details(regno, name, dept, percentage)
Company(companyID,name, noOfVacancy) Training_Details(CourseID,
name, Trainer) Placed(regno, companyID,minSal) v List the students
who are eligible for recruitment in a particular company. vi
Display the student who has been placed with highest salary vii
Develop a PL/SQL exception that provides an alternate for not
eligible students. viii Write a PL/SQL program to print the
factorial of given number.
v. List the Students Who Are Eligible for Recruitment in a Particular Company
sql
Copy code
-- Assuming a company name is provided, e.g., 'TechCorp'.
SELECT S.Regno, S.Name
FROM Stud_details S
WHERE S.Percentage >= 70 -- Assuming eligibility is based on a percentage
greater than or equal to 70
AND S.Regno NOT IN (SELECT P.Regno FROM Placed P WHERE P.CompanyID = (SELECT
C.CompanyID FROM Company C WHERE C.Name = 'TechCorp'));
Sample Output
Regno Name
3 Carol
vi. Display the Student Who Has Been Placed With Highest Salary
sql
Copy code
SELECT S.Regno, S.Name, P.MinSal
FROM Stud_details S
JOIN Placed P ON S.Regno = P.Regno
ORDER BY P.MinSal DESC
FETCH FIRST 1 ROW ONLY;
Sample Output
Regno Name MinSal
5 Eve 80000
vii. Develop a PL/SQL Exception for Not Eligible Students
sql
Copy code
CREATE OR REPLACE PROCEDURE check_eligibility(p_regno IN INT) IS
v_percentage DECIMAL(5, 2);
v_count INT;
BEGIN
SELECT Percentage INTO v_percentage
FROM Stud_details
WHERE Regno = p_regno;
IF v_percentage < 70 THEN
RAISE_APPLICATION_ERROR(-20001, 'Student ' || p_regno || ' is not
eligible for recruitment.');
ELSE
SELECT COUNT(*) INTO v_count
FROM Placed
WHERE Regno = p_regno;
Sample Output
makefile
Copy code
Factorial: 120
20. Consider the following relational schema for a Loan database
application: Customer{Customer_id, Customer_name, Age, phone_no}
Loan{ Loan_id, Amount, Customer_id)} i. Include the constraint on
Loan_id that it starts with letter ‘L’. ii. Display the list of
the customer_ids and total Loan amount taken. iii. Display the
Customer_id and Customer_name who have taken less than two loans
v. Write a PL/SQL program to print the details of the customer
when customerid is given as input
ii. Display the List of Customer_ids and Total Loan Amount Taken
sql
Copy code
SELECT Customer_id, SUM(Amount) AS Total_Loan_Amount
FROM Loan
GROUP BY Customer_id;
Sample Output
Customer_id Total_Loan_Amount
1 15000
2 7000
iii. Display the Customer_id and Customer_name Who Have Taken Less Than Two Loans
sql
Copy code
SELECT C.Customer_id, C.Customer_name
FROM Customer C
LEFT JOIN Loan L ON C.Customer_id = L.Customer_id
GROUP BY C.Customer_id, C.Customer_name
HAVING COUNT(L.Loan_id) < 2;
Sample Output
Customer_id Customer_name
2 Bob
iv. Write a PL/SQL Program to Print the Details of the Customer When Customerid is Given
as Input
sql
Copy code
CREATE OR REPLACE PROCEDURE get_customer_details(p_customer_id IN INT) IS
v_name VARCHAR(100);
v_age INT;
v_phone_no VARCHAR(15);
BEGIN
SELECT Customer_name, Age, Phone_no
INTO v_name, v_age, v_phone_no
FROM Customer
WHERE Customer_id = p_customer_id;
Sample Output
yaml
Copy code
Customer ID: 1
Name: Alice
Age: 30
Phone No: 1234567890
21. Create a Table as workers and the details are { S.No, Name,
Designation, Branch } Perform the following commands: i. Alter the
table by adding a column Salary ii. Alter the table by modifying
the column Name iii. Describe the table employee iv. Copy the
table employee as emp v. Truncate the table vi. Delete the Second
row from the table vii. Drop the table. viii. Write a PL/SQL
program to print the given number is odd or even.
22. Create the following tables student_details{register_no,
student_name, DOB, address, city} mark_details{register_no, mark1,
mark2, mark3, total } i. Display only those rows whose total
ranges between 250 and 300. ii. Drop the table mark_details and
Delete the row whose register_no=161. iii. Display all details
whose names begins with 'a'. iv. Write a PL/SQL program to print
the details of the student when regno is given as input