Dbms Record1
Dbms Record1
1 row created.
DEPARTMENT
--------------------
Accounts
it
sales
1 row created.
b) Create a new table client2 that has the same structure as client but
with no records. Display the structure and records.
SQL> create table client2(client_no,name,address,state,bal_due)as select
client_no,name,address,state,bal_due from client where 1=2;
Table created.
SQL> select*from client2;
no rows selected
d)Assign penalty as 10% of bal_due for the clients c1002, c1005, c1009
and for others 8%. Display records.
SQL> update client set penalty=0.08*bal_due;
10 rows updated.
SQL> update client set penalty=0.10*bal_due where client_no in('c002','c005','c009');
3 rows updated.
3. Create a table book using sql command to store accession no, title,
author, publisher, year, price. apply the suitable structure for the
columns. Specify primary key and not null constraints on the table.
Insert 10 records.
1 row created.
PUB
--------------------
tata mc graw hill
tata mc graw hill
c02 c# jennifer
abode press 1985 983.67
5. Create a table sales_details with the columns sno, month, target and
qty_sold to store the sales details of one year. Specify the composite
primary key to the columns sno and month. Target and sales must be
positive numbers.
1 row created.
SQL> commit;
Commit complete
SQL> select * from sales_details;
SNO TOTALSALES
-------------------------------
s0001 190
s0003 150
s0004 200
SNO COMMISION
-------------------------------
s0001 9500
s0003 7500
s0004 10000
SNO
------
s0001
s0002
s0003
d) Dispaly the sno, month and qtysold of the sales persons with sno
s0001 or s0003.
SQL> select sno,month,qtysold from sales_details where sno in('s0001','s0003');
SNO MONTH QTYSOLD
-----------------------------------------
s0001 feb 60
s0001 jan 70
s0001 mar 120
s0003 apr 80
s0003 nov 150
6. Create a table bank with the columns acno, act_name, act_type and
bal. specify the primary key. Initial bal must be greater than 500.
Write a pl/sql program to perform debit operation by providing
acct_no and amount required. the amount must be greater than 100
and less than 20000 for one transaction. If the account exist and bal-
amount>100 bank table must be updated, otherwise “no suffficient
balance” message should be displayed. If account number is not
present then display “no such account” message to the user.
declare
ano number(10);
balance number(10,2);
amount number(10,2);
begin
ano:=&ano;
amount:=&amount;
select acno into ano from bank where acno=ano;
if sql%found then
if amount>100 and amount<20000 then
select bal into balance from bank where acno=ano;
balance:=balance-amount;
if balance>500 then
update bank set bal=bal-amount where acno=ano;
dbms_output.put_line('transaction successful');
commit;
else
dbms_output.put_line('no sufficient balance');
end if;
else
dbms_output.put_line('amount must be greater than 100 and less than 20000');
end if;
end if;
exception
when no_data_found then
if(sql%notfound)then
dbms_output.put_line('account does not exist');
end if;
end;
/
OUTPUT 1
OUTPUT 2
OUTPUT 3
old 6: ano:=&ano;
new 6: ano:=101;
old 7: amount:=&amount;
new 7: amount:=5000;
no sufficient balance
OUTPUT 4
old 6: ano:=&ano;
new 6: ano:=104;
old 7: amount:=&amount;
new 7: amount:=20;
OUTPUT1:
Enter value for pnumber: p101
old 7: pnumber:='&pnumber';
new 7: pnumber:='p101';
Enter value for qtyreq: 3
old 8: qtyreq:=&qtyreq;
new 8: qtyreq:=3;
stock updated
OUTPUT2:
SQL> /
Enter value for pnumber: p104
old 7: pnumber:='&pnumber';
new 7: pnumber:='p104';
Enter value for qtyreq: 60
old 8: qtyreq:=&qtyreq;
new 8: qtyreq:=60;
no sufficient stock
OUTPUT3:
SQL> /
Enter value for pnumber: p107
old 7: pnumber:='&pnumber';
new 7: pnumber:='p107';
Enter value for qtyreq: 7
old 8: qtyreq:=&qtyreq;
new 8: qtyreq:=7;
product not found
6 rows selected.
b) List the name ,city,and address of the suppliers who are supplying
keyboard.
SQL> select sname, scity, saddr from supplier where sno in(select sno from citems
where iname='keyboard');
c) List the supplier name, items supplied by the suppliers ‘cats’ and
‘electrotech’.
SQL> select s.sname, i.iname from supplier s, citems i where s.sno=i.sno and s.sname in
('cats','electrotech');
SNAME INAME
---------------------------
cats mouse
electrotech printer
electrotech keyboard
d) Find the items having quantity less than 5 and insert the details of
supplier and item of these, into another table neworder.
SQL> create table neworder as select s.sno,s.sname,s.saddr,s.scity,i.ino,i.iname,i.iqty
from supplier s, citems i where s.sno=i.sno and i.iqty<5;
Table created.
TOTAL_AMT
-----------------
2620
PNAME
----------
cd drive
keyboard
monitor
PNAME QTYSOLD
-------------------------------
monitor 3
keyboard 1
PROFIT_OF_C1
-------------------
120.6
SUM(QTYSOLD)
---------------------
14
CLASS COUNT(M.REGNO)
-----------------------------------------
I bca 2
III bca 1
II bca 1
d) Display the student name with rollno and class of those who
passed in I internals and failed in II internals. (use set operator).
SQL>select s.regno, s.name, s.class from student s, marks m
where s.regno=m.regno and m.test=1 and m.m1>35 and m.m2>35 and m.m3>35
and m.eccmarks>35
intersect
dbms_output.put_line('----------------------------------------------------');
loop
fetch bk into bc,athr,name,ctgry,cost;
exit
when bk%notfound;
if bc='A' and ctgry='novels' then
disc:=0.1*cost;
end if;
if bc='A' and ctgry='technology' then
disc:=0.125*cost;
end if;
if bc='B' and ctgry='commerce' then
disc:=0.18*cost;
end if;
if bc='B' and ctgry='science' then
disc:=0.19*cost;
end if;
if bc='C' and ctgry='songs' then
disc:=0.25*cost;
end if;
if bc='C' and ctgry='sports' then
disc:=0.24*cost;
end if;
if bc='D' and ctgry='all' then
disc:=0.28*cost;
end if;
sp:=cost-disc;
dbms_output.put_line(bc||' '||athr||' '||name||' '||ctgry||' '||cost||' '||disc||' '||sp);
end loop;
close bk;
end;
/
BOOK CODE AUTHOR TITLE CATEGORY PRICE DISCOUNT SELLING PRICE -
-------------------------------------------------------------------------------------------------------------------
pf:=2000;
end if;
if gross<=25000 then
pt:=100;
else
pt:=200;
end if;
net:=gross-(pf+pt);
end;
/
Procedure created.
dbms_output.put_line('da:'||da);
dbms_output.put_line('hra:'||hra);
dbms_output.put_line('gross:'||gross);
dbms_output.put_line('pf:'||pf);
dbms_output.put_line('pt:'||pt);
dbms_output.put_line('net:'||net);
dbms_output.put_line('---------------------------------------');
end loop;
end;
/
OUTPUT:
1 row created.
1 row created.
1 row created.
1 row created.
Table created.
end pck_item;
Package created.
c varchar2(5);
begin
return 1;
exception
return 0;
end;
itemno varchar2(5);
qtyavail number(10);
begin
if qty>qtyavail then
dbms_output.put_line('low stock');
else
end if;
end;
end pck_item;
declare
itemno varchar2(5);
qty number(10);
d number(5);
begin
itemno:='&itemno';
qty:=&qty;
d:=pck_item.chk_item(itemno);
if d=1 then
dbms_output.put_line('item found');
pck_item.proc_item(itemno,qty);
else
end if;
end;
Output 1
Enter value for itemno: i101
old 6: itemno:='&itemno';
new 6: itemno:='i101';
old 7: qty:=&qty;
new 7: qty:=5;
item found
Output 2
Enter value for itemno: i103
old 6: itemno:='&itemno';
new 6: itemno:='i103';
old 7: qty:=&qty;
new 7: qty:=2;
item found
i101 5 25-FEB-23
i103 2 25-FEB-23
Output 3
Enter value for itemno: i101
old 6: itemno:='&itemno';
new 6: itemno:='i101';
old 7: qty:=&qty;
new 7: qty:=200;
item found
low stock
Output 4
Enter value for itemno: i109
old 6: itemno:='&itemno';
new 6: itemno:='i109';
old 7: qty:=&qty;
new 7: qty:=4;