DBMSBCOM
DBMSBCOM
SQL:
Cycle-I: Aim: The marketing company wishes to computerize its operations by using the following
tables.
Table Name: Client Master
Description: Used to store client information
Column Name Data Type Size Attribute
Primary key
CLIENT_NO Varchar2 6
NAME Varchar2 20 Not null
ADDRESS1 Varchar2 30
ADDRESSS Varchar2 30
CITY Varchar2 15
PINCODE Varchar2 8
STATE Varchar2 15
BAL_DUE Number 10,2
DELY_ADDRESS Varchar2 25
SALESMAN_NO Varchar2 6 Foreign Key
DELY_TYPE Char 1 Delivery:part(p)/full(f)anddefault‘
F’
BILL_YN Char 1
DELY_DATE Date Can’tbe lessthanorderdate
Varchar2 Values(“InProcess”,“Fulfilled”,
ORDER _STATUS 10
“Back Order”, “Cancelled)
4
DELY_TYPE CHAR(1) DEFAULT 'F', -- Delivery type ('F' for Full, 'P' for Part)
DELY_DATE DATE CHECK (DELY_DATE >= ORDER_DATE), -- Delivery date (must be later than
or equal to order date)
);
1. Retrieve the list of names, city, and the state of all the clients.
6
5. List the names o fall clients having ‘a’ as the second letter in their
names.
8
7. List the clients who stay in a city whose first letter is ‘M’.
9
8. List all information from the sales-order table for orders placed in
the month of March.
SELECT * FROM sales_orderS WHERE EXTRACT(MONTH FROM ORDER_DATE) = 3;
9. List the products whose selling price is greater than 1000 and less
than or equal to 3000.
10
10. Find the products whose selling price is greater than 1000 and
also find the new selling price as the original selling price of 0.50.
Cycle-II Supplier
11
Aim: A manufacturing company deals with various parts and various suppliers supply these parts. It
consists of three tables to record its entire information. Those are as follows.
CREATE TABLE JX (
Project_No VARCHAR(6) PRIMARY KEY, -- Unique project identifier
Project_Name VARCHAR(50) NOT NULL,-- Project name
City VARCHAR(30) -- Project city
);
13
1. List the details of employees who have joined before the end of
September ’23.
SELECT *
FROM Emp
WHERE Hiredate < '2023-09-30';
4. List the names of employees who are more than 2 years old in the
organization.
19
SELECT Ename
FROM Emp
WHERE Hiredate <= CURRENT_DATE - INTERVAL '2' YEAR;
UPDATE Emp
SET Sal = Sal * 1.20
WHERE Hiredate <= CURRENT_DATE - INTERVAL '12' YEAR;
select * from Emp;
PL/SQL PROGRAMS
22
Output:
LEVEL is a palindrome.
23
2. The HRD manager has decided to raise the employee salary by 15% write a PL/SQL block to
accept the employee number and update the salary of that employee. Display appropriate
messages based on the existence of the record in the Emp table.
DECLARE
v_empno NUMBER; -- Variable to hold the employee number
v_salary NUMBER; -- Variable to hold the employee's current salary
v_count NUMBER; -- Variable to check if the employee exists
BEGIN
-- Accept the employee number
v_empno := &empno; -- Replace &empno with the input employee number while running
3. Write a PL/SQL program to display the top 10 rows in the Emp table based on their job and
salary.
DECLARE
-- Cursor to fetch top 10 employees ordered by Job and Salary
CURSOR emp_cursor IS
SELECT Empno, Ename, Job, Sal
FROM Emp
ORDER BY Job, Sal DESC
FETCH FIRST 10 ROWS ONLY; -- For Oracle 12c and above
BEGIN
-- Loop through the cursor
FOR emp_record IN emp_cursor LOOP
DBMS_OUTPUT.PUT_LINE('Empno: ' || emp_record.Empno ||
', Name: ' || emp_record.Ename ||
', Job: ' || emp_record.Job ||
', Salary: ' || emp_record.Sal);
END LOOP;
END;