056 Dbms Lab File
056 Dbms Lab File
iii) List the various products available from the product_master table.
iv) List all the clients who are located in Bombay.
v) Display the information for client no 0001 and 0002.
vi) Find the products with description as ‘1.44 drive’ and ‘1.22 Drive’.
vii) Find all the products whose sell price is greater than 5000.
viii) Find the list of all clients who stay in in city ‘Bombay’ or city ‘Delhi’ or ‘Madras’.
ix) Find the product whose selling price is greater than 2000 and less than or equal to 5000.
x) List the name, city and state of clients not in the state of ‘Maharashtra’.
ASSIGNMENT -2
v. Find the products whose selling price is more than 1500 and also find the new selling price as
original selling price *15.
vi. Find out the clients who stay in a city whose second letter is a.
vii. Find out the name of all clients having ‘a’ as the second letter in their names.
viii. List the products in sorted order of their description.
xiii. Count the number of products having price greater than or equal to 1500.
ASSIGNMENT - 03
Create the following tables:
i. Sales_master
ii. Sales_order
TABLE CREATION
City varchar2(20),
State varchar2(20),
Pincode numeric(6),
Remarks varchar2(20)
);
create table sales_order(
s_order_date date,
dely_address varchar2(25),
billed_yn char(1),
dely_date date,
','Cancelled')),
check(dely_date>s_order_date));
TABLE DESCRIPTION
i) DATA:-
Insert into Sales_master values (‘S001’, ‘Kiran’, ‘A/14’, ‘Worli’, ‘Mumbai’, 400002,
‘Maharashtra’, 3000, 100,50,‘Good’);
DATA
insert into challan_header values ( 'CH9001', 019001, '12-12-20' ,'Y'),
insert into challan_header values ('CH865' ,046865 ,'12-11-20' ,'Y'),
insert into challan_header values ('CH3965' ,010008 ,'12-10-20', 'Y');
DATA
insert into challan_details values ('CH9001', 'P00001', 4),
insert into challan_details values ('CH9002', 'P07965' ,1),
insert into challan_details values ('CH9003', 'P07885', 1),
insert into challan_details values ('CH6865', 'P07868', 3),
insert into challan_details values ('CH6866' ,'P03453' ,4),
insert into challan_details values ('CH6867', 'P00001' ,10),
insert into challan_details values ('CH3968', 'P00001' ,5),
insert into challan_details values ('CH3969', 'P07975', 2);
Q3. Add the not null constraint in the product_master table with the columns description,
profit percent , sell price and cost price.
Ans:- alter table product_master modify description varchar(90) not null;
alter table product_master modify profit_percent double(5,1) not null;
alter table product_master modify sell_price double(20,5) not null;
alter table product_master modify cost_price double(5,0) not null;
Q4.Change the size of client_no field in the client_master table.
Ans:- alter table client_master modify client_no varchar(10);
Q5. Select product_no, description where profit percent is between 2 and 6 both inclusive.
Ans:- Select product_no, description from product_master where profit_percent between 2
and 6 ;
ASSIGNMENT – 05
1.Find out the product which has been sold to ‘Ivan Sayross.’
Ans:-
select product_master.product_no,product_master.description,
sales_or der_details.qty_order from client_master,product_master,
sales_order_details,sales_order
where product_master.product_no=sales_order_details.product_no and
sales_order_details.s_order_no=sales_order.s_order_no and
sales_order.client_no=client_master.client_no and client_master.name like
'%Ivan%'
2.Find out the product and their quantities that will have do delivered.
Ans:-
select product_master.product_no,sales_order_details.Qty_order from
product_master,sales_order_details where
product_master.product_no=sales_order_details.product_no;
3.Find the product_no and description of moving products.
Ans:-
select product_no,description from product_master where description like
'%floppies%' union select product_no,description from product_master where
description like '%Drive%' union select product_no,description from
product_master where description like '%HDD%';
4. Find out the names of clients who have purchased ‘CD DRIVE’
Ans:-
select client_master.name from
client_master,product_master,sales_order_details,sales_o rder where
product_master.product_no=sales_order_details.product_ no and
sales_order_details.s_order_no=sales_order.s_order_no and
sales_order.client_no=client_master.client_no and
product_master.description='CD DRIVE';
5.List the product_no and s_order_no of customers haaving qty ordered less
than 5 from the order details table for the product “1.44 floppies”.
Ans:-
select sales_order_details.product_no,sales_order_details.s_ord er_no from
product_master,sales_order_details where
product_master.description='1.44floppies' and sales_order_details.qty_order
6.Find the products and their quantities for the orders placed by ‘Vandan
Saitwal ’ and “Ivan Bayross”. Ans:-
select product_master.product_no,product_master.description,s
ales_order_details.qty_order from
client_master,product_master,sales_order_details,sales_o rder where
product_master.product_no=sales_order_details.product_ no and
sales_order_details.s_order_no=sales_order.s_order_no and
sales_order.client_no=client_master.client_no and client_master.name like
'%Ivan%';
8. Find the order No, Client No and salesman No. where a client has been
received by more than one salesman.
Ans:-
select s_order_no,client_no,salesman_no from sales_order where client_no in
(select client_no from sales_order group by client_no having
count(salesman_no)>1);
select sales_order_details_051.product_no,product_master.description,
sum(sales_order_details_051.qty_order) from
sales_order_details_051, product_master
sales_order_details_051.product_no, product_master.description;
p.product_no=s.product_no group by
s.product_no, p.description;
Q3.- Calculate the average quantity sold for each client that has a maximum order value of 15000.
so.s_order_no=s.s_order_no group by
c.client_no,c.name having
max(s.qty_order*s.product_rate)>1500;
Q4.- Find out the products which has been sold to Ivan.
select product_master.product_no,product_master.description,sales_order_details_051.qty_order
from
product_master.product_no=sales_order_details_051.product_no and
sales_order_details_051.s_order_no=sales_order_051.s_order_no and
sales_order_051.client_no=client_master.client_no and
client_master,product_master,sales_order_details_051,sales_order_051 where
product_master.product_no=sales_order_details_051.product_no and
sales_order_details_051.s_order_no=sales_order_051.s_order_no and
sales_order_051.client_no=client_master.client_no and
product_master.description='CD Drive';
Q6.- Find the products and their quantities for the orders placed by ‘Vandana’ and ‘Ivan’.
client_master,product_master,sales_order_details_051,sales_order_051 where
(product_master.product_no=sales_order_details_051.product_no and
sales_order_details_051.s_order_no=sales_order_051.s_order_no and
sales_order_051.client_no=client_master.client_no and
product_master.product_no=sales_order_details_051.product_no and
sales_order_details_051.s_order_no=sales_order_051.s_order_no and
sales_order_051.client_no=client_master.client_no and
s.product_no, p.description;
Q8.- Select product_no, product description and qty ordered for each product.
p.product_no=s.product_no group by
s.product_no, p.description;
Q9.- Display the order number and day on which clients placed their order.
Q10.- Display the month and Date when the order must be delivered.
qty_order=0 and
sales_order_details_051.product_no=product_master.product_no;
2. Find the customer name, address, city and pincode for the client who has placed order no
“019001”
s_order_no='o19001' and
sales_order_051.client_no=client_master.client_no;
3. Find the client names who have placed order before the month of may 96.
product_master.product_no=sales_order_details_051.product_no and
sales_order_details_051.s_order_no=sales_order_051.s_order_no and
sales_order_051.client_no=client_master.client_no;
4. Find out if product “1.44 Drive” is ordered by only client and print the client_no name to whom
it was sold.
product_master.product_no=sales_order_details_051.product_no and
sales_order_details_051.s_order_no=sales_order_051.s_order_no and
sales_order_051.client_no=client_master.client_no;
5. find the names of client who have placed orders worth Rs.10000 or more.
product_master.product_no=sales_order_details_051.product_no and
sales_order_details_051.s_order_no=sales_order_051.s_order_no and
sales_order_051.client_no=client_master.client_no;
6. Select the orders placed by ‘Rahul Desai”
product_master.product_no=sales_order_details_051.product_no and
sales_order_details_051.s_order_no=sales_order_051.s_order_no and
sales_order_051.client_no=client_master.client_no;
8. Select all the clients and the salesman in the city of Bombay.
UNION
9. Select salesman name in “Bombay” who has atleast one client located at “Bombay”
so.salseman_no=s.salesman_no and
so.client_no=c.client_no and
c.city='Bombay';
10. Select the product_no, description, qty_on-hand,cost_price of non_moving items in the
product_master table
qty_order=0 and
sales_order_details_051.product_no=product_master.product_no;
ASSIGNMENT 8
Q1. Create an index on the table client_master, field client_no.
Q3. Create an composite index on the sales_order_details table for the columns s_order_no and
product_no.
select sal_amt
from sales_master_051
where
sal_amt<3500;
from client_master
Q9. Select the client names from client_view who lives in city ‘Bombay’.
declare
a number(10);
b number(10);
c number(20);
begin
a:=2;
b:=7;
c:=a+b;
dbms_output.put_line('sum is '||c);
end;
Q2. WAP in PL/SQL for addition of 1 to 100 numbers.
declare
a number;
sums number;
begin
a:=1;
sums:=0;
loop
sums:=sums+a;
a:=a+1;
end loop;
end;
DECLARE
n NUMBER := 27;
r NUMBER;
BEGIN
r := MOD(n, 2);
IF r = 0 THEN
dbms_output.Put_line('Even');
ELSE
dbms_output.Put_line('Odd');
END IF;
END;
Q4. WAP in PL/SQL to inverse a number, eg. Number 5639 when inverted must be display output
9365.
declare
num number;
reverse number:=0;
begin
num:=5639;
while num>0
loop
reverse:=(reverse*10) + mod(num,10);
num:=trunc(num/10);
end loop;
end;
ASSIGNMENT 10
Q) The HRD manager has decided to raise the salary for all the employees in the Dept No 20 by 5%.
Whenever any such raise is given to the employees, a record for the same is maintained in the
emp_raise table. It includes the EmpNo, the date when the raise was given and the actual raise.
Write a PL/SQL block to update the salary of each employee and insert a record in the emp_raise
table.
DECLARE
CURSOR c_cum IS SELECT emp_code, salalry FROM employee
WHERE deptno = 20;
Str_emp_code employee.emp_code%type;
Num_salary employee.salary%type;
BEGIN
OPEN c_emp;
LOOP
FETCH c_emp INTO str_emp_code, num_salary;
IF c_emp% FOUND THEN
UPDATE employee SET salary = num_salary + (num_salary * .05)
WHERE emp_code = str_emp_code ;
INSERT INTO emp_raise VALUES(str_emp_code, sysdate, num_salary * 0.05);
ELSE exit;
END IF ;
END LOOP;
COMMIT;
CLOSEc_emp;
END;
Q) Create a transparent audit system for a table Client_master. The system must keep track of the
records that are being deleted or modified and when they have been deleted or modified