100% found this document useful (1 vote)
440 views

Oracle Practical B.com Ca Bharathiar University

The document details the creation of tables in a company and student database using SQL commands. Information about 5 companies and 5 students is inserted into the respective tables, including company/student names, attributes, and percentages. Various select statements are then used to query and sort the data.

Uploaded by

kalpana
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
440 views

Oracle Practical B.com Ca Bharathiar University

The document details the creation of tables in a company and student database using SQL commands. Information about 5 companies and 5 students is inserted into the respective tables, including company/student names, attributes, and percentages. Various select statements are then used to query and sort the data.

Uploaded by

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

COMPANY DATABASE

SQL>create table company4(companyname char(15),proprietor char(15),address


char(25),suppliername char(15),no_employees number(5),gpercent number(6,2));

Table created.

SQL>insert into company4


values(‘&companyname’,’&proprieto’,’&address’,’&suppliername’,’&no_employees’,’&gperce
nt’);

Enter vaues for companyname:Samsung

Enter vaues for proprietor:Vinod

Enter vaues for address:Delhi

Enter vaues for suppliername:Tata

Enter vaues for no_employees:250

Enter vaues for gpercent:20

Old 1: insert into company4


values(‘&companyname’,’&proprieto’,’&address’,’&suppliername’,’&no_employees’,’&gperce
nt’);

New 1:insert into company4 values(‘Samsung’,’Vinod’,’Delhi’,’Tata’,250,20)

1 row created.

SQL>/

Enter vaues for companyname:Onida

Enter vaues for proprietor:Vinod

Enter vaues for address:Mumbai

Enter vaues for suppliername:Tata

Enter vaues for no_employees:150

Enter vaues for gpercent:25.50


Old 1: insert into company4
values(‘&companyname’,’&proprietor’,’&address’,’&suppliername’,’&no_employees’,’&gperc
ent’);

New 1:insert into company4 values(‘Onida’,’Vinod’,’Mumbai’,’Tata’,150,25.50)

1 row created.

SQL>/

Enter vaues for companyname:Sharp

Enter vaues for proprietor:Malhothra

Enter vaues for address:Mumbai

Enter vaues for suppliername:Tata

Enter vaues for no_employees:1000

Enter vaues for gpercent:35.50

Old 1: insert into company4


values(‘&companyname’,’&proprietor’,’&address’,’&suppliername’,’&no_employees’,’&gperc
ent’);

New 1:insert into company4 values(‘Sharp’,’Malhothra’,’Mumbai’,’Tata’,1000,35.50)

1 row created.

SQL>/

Enter vaues for companyname:Videocon

Enter vaues for proprietor:Rathra

Enter vaues for address:Delhi

Enter vaues for suppliername:Ravi

Enter vaues for no_employees:750

Enter vaues for gpercent:25.50

Old 1: insert into company4


values(‘&companyname’,’&proprietor’,’&address’,’&suppliername’,’&no_employees’,’&gperc
ent’);
New 1:insert into company4 values(‘Videocon’,’Rathra’,’Delhi’,’Ravi’,750,25.50)

1 row created.

SQL>/

Enter vaues for companyname:Mahendra

Enter vaues for proprietor:Mahendran

Enter vaues for address:Coimbatore

Enter vaues for suppliername:Telco

Enter vaues for no_employees:650

Enter vaues for gpercent:26.50

Old 1: insert into company4


values(‘&companyname’,’&proprietor’,’&address’,’&suppliername’,’&no_employees’,’&gperc
ent’);

New 1:insert into company4 values(‘Mahendra’,’Mahendran’,Coimbatore’,’Telco’,650,26.50)

1 row created.

SQL>select *from company4;

COMPANYNAME PROPRIETOR ADDRESS SUPPLIERNAME

--------------- --------------- --------------- --------------- ---------------

NO_EMPLOYEES GPERCENT

--------------- --------------- ---------------

Samsung Vinod Delhi Tata

250 20

Onida Vinod Mumbai Tata

150 25.5

Sharp Malhothra Mumbai Tata

1000 35.5

Videocon Rathra Delhi Ravi


750 25.5

Mahindra Mahendran Coimbatore Telco

650 26.5

SQL>select*from company4 order by gpercent asc;

COMPANYNAME PROPRIETOR ADDRESS SUPPLIERNAME

--------------- --------------- --------------- --------------- ---------------

NO_EMPLOYEES GPERCENT

--------------- --------------- ---------------

Samsung Vinod Delhi Tata

250 20

Onida Vinod Mumbai Tata

150 25.5

Videocon Rathra Delhi Ravi

750 25.5

Mahindra Mahendran Coimbatore Telco

650 26.5

Sharp Malhothra Mumbai Tata

1000 35.5

SQL>select*from company4 where suppliername=’telco’;

COMPANYNAME PROPRIETOR ADDRESS SUPPLIERNAME

--------------- --------------- --------------- --------------- ---------------

NO_EMPLOYEES GPERCENT

--------------- --------------- ---------------

Mahindra Mahendran Coimbatore Telco

SQL>select*from company4 wher e gpercent>20 order by gpercent asc;


COMPANYNAME PROPRIETOR ADDRESS SUPPLIERNAME

--------------- --------------- --------------- --------------- ---------------

NO_EMPLOYEES GPERCENT

--------------- --------------- ---------------

Onida Vinod Mumbai Tata

150 25.5

Videocon Rathra Delhi Ravi

750 25.5

Mahindra Mahendran Coimbatore Telco

650 26.5

Sharp Malhothra Mumbai Tata

1000 35.5

SQL>select*from company4 where no_employees between 300 and 1000;

COMPANYNAME PROPRIETOR ADDRESS SUPPLIERNAME

--------------- --------------- --------------- --------------- ---------------

NO_EMPLOYEES GPERCENT

--------------- --------------- ---------------

Sharp Malhothra Mumbai Tata

1000 35.5

Videocon Rathra Delhi Ravi

750 25.5

Mahindra Mahendran Coimbatore Telco

650 26.5

SQL>select*from company4 where suppliername=’Tata’;

COMPANYNAME PROPRIETOR ADDRESS SUPPLIERNAME


--------------- --------------- --------------- --------------- ---------------

NO_EMPLOYEES GPERCENT

--------------- --------------- ---------------

Sharp Malhothra Mumbai Tata

1000 35.5
STUDENT DATABASE

SQL>create table student15(studentname char(15),gender char(6),rollno number(10),

Department char(15),address char(25),percentage number(4,2));

Table created.

SQL>insert into student15


values(‘&studentname’,’&gender’,’&rollno’,’&department’,’&address’,’&percentage’);

Enter vaues for studentname:Anisha

Enter vaues for gender:Female

Enter vaues for rollno:062456

Enter vaues for department:commerce

Enter vaues for address:Thrissur

Enter vaues for percentage:76.7

Old 1: insert into student15


values(‘&studentname’,’&gender’,’&rollno’,’&department’,’&address’,’&percentage’);

New 1: insert into student15 values(‘Anisha’,’Female’,’062456’,’commerce’,’Thrissur’,76.7);

1 row created.

SQL>/

Enter vaues for studentname:Vismaya

Enter vaues for gender:Female

Enter vaues for rollno:061457

Enter vaues for department:commerce

Enter vaues for address:Calicut

Enter vaues for percentage:77.7

Old 1: insert into student15


values(‘&studentname’,’&gender’,’&rollno’,’&department’,’&address’,’&percentage’);

New 1: insert into student15 values(‘Vismaya’,’Female’,’061457’,’commerce’,’Calicut’,76.7);


1 row created.

SQL>/

Enter vaues for studentname:Athira

Enter vaues for gender:Female

Enter vaues for rollno:064878

Enter vaues for department:Science

Enter vaues for address:Kottayam

Enter vaues for percentage:70.5

Old 1: insert into student15


values(‘&studentname’,’&gender’,’&rollno’,’&department’,’&address’,’&percentage’);

New 1: insert into student15 values(‘Athira’,’Female’,’064878’,’Science’,’Kottayam’,70.5);

1 row created.

SQL>/

Enter vaues for studentname:Sowmya

Enter vaues for gender:Female

Enter vaues for rollno:064515

Enter vaues for department:Science

Enter vaues for address:Palakkad

Enter vaues for percentage:67.7

Old 1: insert into student15


values(‘&studentname’,’&gender’,’&rollno’,’&department’,’&address’,’&percentage’);

New 1: insert into student15 values(‘Sowmya’,’Female’,’064515’,’science’,’Palakkad’,67.7);

1 row created.

SQL>/

Enter vaues for studentname:Anjana

Enter vaues for gender:Female


Enter vaues for rollno:124578

Enter vaues for department:commerce

Enter vaues for address:Malappuram

Enter vaues for percentage:50.7

Old 1: insert into student15


values(‘&studentname’,’&gender’,’&rollno’,’&department’,’&address’,’&percentage’);

New 1: insert into student15


values(‘Anjana’,’Female’,’124578’,’commerce’,’Malappuram’,50.7);

1 row created.

SQL>select*from student15;

STUDENT GENDER ROLLNO DEPARTMENT

--------------- --------------- --------------- ---------------

ADDRESS PERCENTAGE

--------------- --------------- ---------------

Anisha Female 062456 commerce

Thrissur 76.7

Vismaya Female 061457 commerce

Calicut 77.7

Athira Female 064878 Science

Kottayam 70.5

Sowmya Female 064515 Science

Palakkad 67.7

Anjana Female 124578 Commerce

Malappuram 50.7

SQL>select avg(percentage)from student15;


AVG(PERCENTAGE)

--------------- ---------------

68.66

SQL>select studentname from student15 where percentage>80;

No rows selected.

SQL>select*from student15 where percentage=(select max(percentage)from student15);

STUDENT GENDER ROLLNO DEPARTMENT

--------------- --------------- --------------- ---------------

ADDRESS PERCENTAGE

--------------- --------------- ---------------

Vismaya Female 061457 commerce

Calicut 77.7

SQL>select*from student15 where percentage between 50 and 70;

STUDENT GENDER ROLLNO DEPARTMENT

--------------- --------------- --------------- ---------------

ADDRESS PERCENTAGE

--------------- --------------- ---------------

Sowmya Female 064515 Science

Palakkad 67.7

Anjana Female 124578 Commerce


Malappuram 50.7

SQL>select*from student15 where percentage>(select percentage from student15 where


rollno=124578);

STUDENT GENDER ROLLNO DEPARTMENT

--------------- --------------- --------------- ---------------

ADDRESS PERCENTAGE

--------------- --------------- ---------------

Anisha Female 062456 commerce

Thrissur 76.7

Vismaya Female 061457 commerce

Calicut 77.7

Athira Female 064878 Science

Kottayam 70.5

Sowmya Female 064515 Science

Palakkad 67.7
PRODUCT DATABASE

SQL>create table product(p_no number(6),pname char(15),unit_m char(15),qunty number(6,2));

Table created.

SQL>insert into product values(&p_no,’&pname’,’&unit_m’,&qunty);

Enter value for p_no:1234

Enter value for pname:pepsi

Enter value for unit_m:litre

Enter value for qunty:40

Old 1:insert into product values(&p_no,’pname’,’&unit_m’,&qunty)

New 1:insert into product values(1234,’pepsi’,’litre’,40)

1 row created.

SQL>/

Enter value for p_no:1235

Enter value for pname:miranda

Enter value for unit_m:litre

Enter value for qunty:50

Old 1:insert into product values(&p_no,’pname’,’&unit_m’,&qunty)

New 1:insert into product values(1235,’miranda’,’litre’,50)

1 row created.

SQL>/

Enter value for p_no:1236

Enter value for pname:idaya

Enter value for unit_m:Kg

Enter value for qunty:25


Old 1:insert into product values(&p_no,’pname’,’&unit_m’,&qunty)

New 1:insert into product values(1236,’idaya’,’Kg’,25)

1 row created.

SQL>/

Enter value for p_no:1237

Enter value for pname:fanda

Enter value for unit_m:litre

Enter value for qunty:35

Old 1:insert into product values(&p_no,’pname’,’&unit_m’,&qunty)

New 1:insert into product values(1237,’fanda’,’litre’,35)

1 row created.

SQL>/

Enter value for p_no:1238

Enter value for pname:sakthi

Enter value for unit_m:Kg

Enter value for qunty:8

Old 1:insert into product values(&p_no,’pname’,’&unit_m’,&qunty)

New 1:insert into product values(1238,’sakthi’,’Kg’,8)

1 row created.

SQL>alter table product add t_amt number(8,2);

Table created.

SQL>alter table product add price number(5,2);

Table created.

SQL>update product set price=60 where p_no=1234;

1 row updated.
SQL>update product set price=40 where p_no=1235;

1 row updated.

SQL>update product set price=30 where p_no=1236;

1 row updated.

SQL>update product set price=45 where p_no=1237;

1 row updated.

SQL>update product set price=50 where p_no=1238;

1 row updated.

SQL>update product set t_amt=qunty*price;

5 rows updated.

SQL>select*from product;

P_NO PNAME UNIT_M QUNTY T_AMT PRICE

--------------- --------------- --------------- --------------- ---------------

1234 pepsi litre 40 2400 60

1235 miranda litre 50 2000 40

1236 idaya Kg 25 30

1237 fanda litre 35 45

1238 sakthi Kg 8 400 50

SQL>select*from product where unit_m=’kg’;

P_NO PNAME UNIT_M QUNTY T_AMT PRICE

----------- ------------ ------------ ---------- --------- ---------

1236 idaya kg 25 750 30

1238 sakthi kg 8 400 50


SQL>select*from product where qunty<10 and qunty<=20;

P_NO PNAME UNIT_M QUNTY T_AMT PRICE

-------- ---------- ----------- ----------- ---------- ---------

1238 sakthi kg 8 400 50

SQL>select sum(t_amt) from product;

SUM(T_AMT)

-----------------

7125

SQL>select count(price) from product where price>50;

COUNT(PRICE)

-------------------

1
PAYROLL DATABASE

SQL> create table payroll (empno number(8),empname char(98), dept char (10),basicpay
number (8,2),hra number(6,2),da number (6,2),pf number (6,2));

Table created.

SQL> insert into

Payroll
(empno ,empname ,dept,basicpay,hra,da,pf)values(101,’pradeepa’,’sales’,7000,200,300,1000);

1 row created.

SQL> insert into

Payroll(empno,empname ,dept,basicpay,hra,da,pf)values(102,’shyam’,’purchase’,8000,400,500,
1500);

1 row created.

SQL>insert into

Payroll(empno,empname,dept,basicpay,hra,da,pf)values(103,’ajay’,’sales’,8000,1000,900,1500);

1 row created.

SQL>insert into

Payroll(empno,empname,dept,basicpay,hea,da,pf)values(104,’anitha’,’accounts’,7000,200,300,1
500);

1 row created.

SQL>insert into

Payroll(empno,empname,dept,
basicpay,hra,da,pf)values(105,’anju’,’sales’,8000,1000,900,1500);

1 row created.

SQL>alter table payroll add netpay number(8,2);

TYable altered.
SQL> update payroll set netpay=(basicpay+hra+da+)-pf;

5 row created.

SQL>Select * from payrlll;

EMPNO EMPNAME DEPT BASICPAY HRA DA


PF

------------- -------------- ----------------- -------------- --------------- ------------------- -------------- --


NETPAY

----------- ---------------

101 PRADEEPA SALES 7000 200 300


1000

6500

102 Shyam Purchase 8000 400 500 1500

7400

103 Ajay sales 8000 1000 900 1500

8400

104 Anitha accounts 9000 500 300 1500

8300

105 anju sales 8000 1000 900 1500

SQL>Select * from payroll order by netpay asc;

EMPNO EMPNAME DEPT BASICPAY HRA DA


PF

--------------- -------------- --------------- ------------- ---------------- -------------------


------------------ --------------- -

NETPAY

------------ -------

101 Pradeepa sales 7000 200 300 1000


6500

102 shyam purchase 8000 400 500 1500

7400

104 anitha accounts 9000 500 300 1500

8300

103 ajay sales 8000 1000 900 1500

8400

105 anju sales 8000 1000 900 1500

8400

SQL>Select * from payroll where dept =’sales’;

EMPNO EMPNAME DEPT BASICPAY HRA DA


PF

NETPAY

101 Pradeepa sales 7000 200 300 1000

6500

103 ajay sales 8000 1000 900 1500

8400

105 anju sales 8000 1000 900 1500

8400

SQL>Select from payroll where hra>=1000and da>=900;

EMPNO EMPNAME DEPT BASICPAY HRA DA


PF

------------ -------------- --------------- ----------------- -------------------- ---------------


----------------- --------------

NETPAY

----------- --------
103 Ajay sales 8000 1000 900 1500

8400

105 anju sales 8000 1000 900 1500

8400

SQL>Select * from payroll order by empno desc;

EMPNO EMPNAME DEPT BASICPAY HRA DA


PF

------------ ----------------- -------------- --------------- ------------------ ------------------ ----------


----- -------------

NETPAY

------------ ----------------

105 Anju sales 8000 1000 900 1500

8400

104 anitha accounts 9000 500 300 1500

8300

103 ajay sales 8000 1000 900 1500

8400

102 shyam purchase 8000 400 500 1500

7400

101 pradeep sales 7000 200 300 1000

6500
PUBLISHER AND BOOK DATABASE

SQL<create table publisher(pcode varchar(5),pname varchar(10),pcity varchar(12),pstate


varchar(10);

Table create

SQL>insert into publisher values(1001,’sathya’,’coimbatore’,’tamilnadu’);

1row creat.

SQL>insert into publisher values(1002,’sangeetha’,’chennai’,’tamilnadu’);

1row create.

SQL>insert into publisher values(1003,’lakshmi’,’coimbatore’,’tamilnadu’);

1row create.

SQL>insert into publisher values(1004,’kavya’,’delhi’,’newdelhi’);

1row create.

SQL>insert into publisher values(1005,’ram’,’coimbatore’,’tamilnadu’);

1row create.

SQL> create table book (pcode varcher(5),t_book varchar(15),bcode varchar(5),bprice


number(6,2));

Table created.

SQL>insert into book values(1001,’dbms’,32443,535);

1row created.

SQL>insert into book values(1002,’dbms’,54342,575);

1row created.

SQL>insert into book values(1003,’accouning’,87663,765);

1row created.

SQL>insert into book values(1004,’commerce’,35454,986);

1row created.

SQL>insert into book values(1005,’economics’,44754,454);


1 row created.

SQL>insert into book values(1006,’banking’,34563,676);

1row created.

SQL>deac publisher;

Name Null? Type

------------------ ---------------- -----------------

PCODE VARCHAR2(5)

PNAME VARCHAR(10)

PCITY VARCHAR(12)

PSTATE VARCHAR(10)

SQL>DESC BOOK;

Name Null? Type

--------------- ------------- -------------- -------------

PCODE VARCHAR2(5)

T_BOOK VAR CHAR2(15)

PCITY VARCHAR2(5)

BPRICE NUMBER(6,2)

SQL>desc book;

Name Null? Type

----------- ---------------- ----------- ------------ ----------

PCODE VARCHAR2(5)

T_BOOK VARCHAR2(15)

BCODE VARCHAR2(5)
BPRICE NUMBER(6,2)

SQL>select *from book where t_book=’dbms’;

PCODE T_BOOK BCODE BPRICE

------------ ------------------- ------------------ --------------------------

1001 dbms 32443 535

1002 dbms 54342 575

SQL>select*from book bprice >300;

PCODE T_BOOK BCODE BPRICE

------------ ----------------- -------------------- ----------------------------

1001 dbms 32443 535

1002 dbms 54342 575

1003 accounting 87663 765

1004 commerce 35454 986

1005 economics 44754 454

1006 banking 34563 676

6 rows selected.

SQL>select*from publisher where pname=’kavya’;

PCODE PNAME PCITY PSTATE

----------- -------------- -------------- -------------------

1004 kavya delhi newdelhi

SQL>select publisher. Pcode,t_pcity from publiusher,book where

Pcity=’delhi’ and publisher.pcode=book.pcode;

PCODE T_BOOK PCITY


------------- -------------- ----------------

1004 commerce delhi

SQL>select publisher.pcode,t_book,pcity from publisher, book where

Pcity=’delhi’ and publisher.pcode=book.pcode order by bprice asc;

PCODE T_BOOK PCITY

----------- --------------- --------------------

1004 commerce delhi

SQL>select count (*) from publisher where pname=’lakshmi’;

COUNT(*)

SQL>select*from publisher where pname like(‘s%’);

PCODE PNAME PCITY PSTATE

------------ --------------- ---------------- --------------------------

1001 sathya coimbatore tamilnadu

1002 sangeetha Chennai tamilnadu


DEPOSIT AND LOAN DATABASE

SQL>create table deposit(accno varchar(6), name varchar(15),cname varchar(20),bal_amt

Varchar(10));

Table created.

SQL>insert into deposit values(101,’cbe’,’sathya’,15000);

1row created.

SQL>insert into deposit values(102,’chennai’,’ambika’,18000);

1row created.

SQL>insert into deposit values(104,’cbe’,’balan’,12000)

1row created.

SQL>insert into deposit values(105,’erode’,’raj’,21000);

1row created.

SQL> create table loan(accno varchar(6),loanno varchar(7),loanamt varchar(6);

Table created.

SQL>insert into loan values(101,1112,25000);

1row created.

SQL>insert intoi values(102,1113,20000);

1row created.

SQL>insert into loan values(1q03,1114,55000);

1row created.

SQL>insert into values(104,1118,600000);

1row created.

SQL>insert into loan values(105,1115,75000);

1 row created
SQL>DESC DEPOSIT;

NAME NULL TYPE

---------- ----------- ---------- ----------- ----------- --------- ----------

ACCNO VARCHAR2(6)

NAME VARCHAR2(15)

CNAME VARCHAR2(20)

BAL_AMT VARCHAR2(10)

SQL>desc loan;

Name Null? Type

------------ ----------- ------------ ------------ ------------ --------------

ACCNO VARCHAR2(6)

LOANNO VARCHAR2(7)

LOANAMT VARCHAR2(6)

SQL>Select count (*)from loan where loanamt between 10000 and 50000;

COUNT(*)

-----------------

SQL>Select cname from deposit where name =’Cbe’ order by cname asc;

CNAME

------------

Balan
Sathya

SQL>Update deposit set bal _amt+(bal_amt*5/100);

4 rows updated.

SQL>Select * from deposit;

ACCNO NAME CNAME BAL_AMT

----------- ------------- ------------- ------------------- -------------- -- ----------------- -------------

101 Cbe Sathya 15750

102 Chennai Ambika 18900

104 Cbe Balan 12600

105 Erode Raj 22050

SQL>Select * from loan order by loanamt desc;

ACCNO LOANNO LOANAMT

------------ ------------ ---------------- --------------- ---------------

105 1115 75000

104 1118 60000

103 1114 55000

101 1112 25000

102 1113 20000

SQL>Select sum (bal_amt)from deposit where name=’Erode’;

SUM(BAL_AMT)

------------ ------------

43050

You might also like