RDBMS Practical Exercise-1
RDBMS Practical Exercise-1
NO
DATE Experiment Name PAGE NO SIGNATURE
2
EXECUTE DDL COMMANDS
3
EXECUTE DML COMMANDS
Table created.
1 row created.
SQL> /
Enter value for empno: 102
Enter value for name: Rithu Enter value for dept: BCA old 1:
insert into employee values(&empno,'&name','&dept') new
1: insert into employee values(102,'Rithu','BCA')
1 row created.
SQL> /
Enter value for empno: 103
Enter value for name: Shivanya Enter value for dept: BBA old
1: insert into employee values(&empno,'&name','&dept') new
1: insert into employee values(103,'Shivanya','BBA')
1 row created.
SQL> /
Enter value for empno: 104
Enter value for name: Sivangi Enter value for dept: B.Com old
1: insert into employee values(&empno,'&name','&dept') new
1: insert into employee values(104,'Sivangi','B.Com')
1 row created.
SQL> /
Enter value for empno: 105
Enter value for name: Prithika Enter value for dept: MCA old
1: insert into employee values(&empno,'&name','&dept') new
1: insert into employee values(105,'Prithika','MCA')
1 row created.
SQL> select * from employee;
UPPER(NAME)
--------------------
RAGUL
RITHU
SHIVANYA
SIVANGI
PRITHIKA
LOWER(NAME)
--------------------
ragul rithu
shivanya
sivangi
prithika
CONCAT(NAME,DEPT)
----------------------------------------
RagulB.Com.,(CA)
RithuBCA
ShivanyaBBA
SivangiB.Com
PrithikaMCA
SQL> select length(dept) from employee;
LENGTH(DEPT)
------------
11
3
3
5
3
ROUND(3.456)
------------
3
SQRT(144)
----------
12
SYSDATE
---------
16-MAR-23
Table dropped.
SQL> create table employee(empno number(10),name varchar(20),salary number(10));
Table created.
1 row created.
SQL> /
Enter value for empno: 202 Enter
value for name: Rithu
Enter value for salary: 60000
old 1: insert into employee values(&empno,'&name',&salary) new
1: insert into employee values(202,'Rithu',60000)
1 row created.
SQL> /
Enter value for empno: 203
Enter value for name: Shivanya Enter value for salary: 40000
old 1: insert into employee values(&empno,'&name',&salary)
new 1: insert into employee values(203,'Shivanya',40000)
1 row created.
SQL> /
Enter value for empno: 204
Enter value for name: Shivangi Enter value for salary: 80000
old 1: insert into employee values(&empno,'&name',&salary)
new 1: insert into employee values(204,'Shivangi',80000)
1 row created.
SQL> /
Enter value for empno: 205
Enter value for name: Prithika Enter value for salary: 90000
old 1: insert into employee values(&empno,'&name',&salary)
new 1: insert into employee values(205,'Prithika',90000)
1 row created.
MAX(SALARY)
-----------
90000
MIN(SALARY)
-----------
40000
AVG(SALARY)
-----------
64000
COUNT(SALARY)
-------------
5
SQL> commit;
Commit complete.
Ex. No: 02
Table created.
1 row created.
SQL> /
Enter value for empno: 102
Enter value for name: Rithu Enter value for dept: BBA old 1:
insert into empdetails values(&empno,'&name','&dept') new
1: insert into empdetails values(102,'Rithu','BBA')
1 row created.
SQL> /
Enter value for empno: 103
Enter value for name: Shivanya Enter value for dept: BCA old
1: insert into empdetails values(&empno,'&name','&dept') new
1: insert into empdetails values(103,'Shivanya','BCA')
1 row created.
SQL> /
Enter value for empno: 104
Enter value for name: Shivangi Enter value for dept: MCA old
1: insert into empdetails values(&empno,'&name','&dept') new
1: insert into empdetails values(104,'Shivangi','MCA')
1 row created.
SQL> /
Enter value for empno: 105
Enter value for name: Prithika Enter value for dept: MBA old
1: insert into empdetails values(&empno,'&name','&dept') new
1: insert into empdetails values(105,'Prithika','MBA')
1 row created.
Table altered.
Table altered.
SQL> select * from empdetails;
Table truncated.
no rows selected
Table dropped.
SQL> commit;
Commit complete.
Ex. No: 03
EXECUTE DML COMMANDS
Table created.
SQL> desc productdetails;
Name Null? Type
----------------------------------------- -------- ----------------------------
PRODUCTID NUMBER(20)
PRODUCTNAME VARCHAR2(20)
PRODUCTPRICE NUMBER(20)
PRODUCT_QUANTITY NUMBER(20)
1 row created.
SQL> /
Enter value for productid: 1102
Enter value for productname: Smartphone
Enter value for productprice: 50000
Enter value for product_quantity: 50
old 1: insert into productdetails
values(&productid,'&productname',&productprice,&product_quantity) new
1: insert into productdetails values(1102,'Smartphone',50000,50)
1 row created.
SQL> /
Enter value for productid: 1103
Enter value for productname: Pendrive
Enter value for productprice: 2800 Enter
value for product_quantity: 30
old 1: insert into productdetails
values(&productid,'&productname',&productprice,&product_quantity) new
1: insert into productdetails values(1103,'Pendrive',2800,30)
1 row created.
SQL> /
Enter value for productid: 1104
Enter value for productname: CD
Enter value for productprice: 50 Enter
value for product_quantity: 60
old 1: insert into productdetails
values(&productid,'&productname',&productprice,&product_quantity) new
1: insert into productdetails values(1104,'CD',50,60)
1 row created.
SQL> /
Enter value for productid: 1105
Enter value for productname: CPU
Enter value for productprice: 20000 Enter
value for product_quantity: 60
old 1: insert into productdetails
values(&productid,'&productname',&productprice,&product_quantity) new 1: insert
into productdetails values(1105,'CPU',20000,60)
1 row created.
SQL> update productdetails set productprice=100 where productid=1103;
1 row updated.
SQL> delete from productdetails where productname='Laptop';
1 row deleted.
SQL> select productname,productprice from productdetails;
PRODUCTNAME PRODUCTPRICE
-------------------- ------------
Smartphone 50000
Pendrive 100
CD 50
CPU 20000
2 rows deleted.
SQL> select * from productdetails;
PRODUCTID PRODUCTNAME PRODUCTPRICE PRODUCT_QUANTITY
---------------------------------------------------- ------------------------------- -------------------------------------
1103 Pendrive 100 30
1104 CD 50 60
SQL> commit;
Commit complete.
Ex. No: 04
EXECUTE DCL AND TCL COMMANDS
Table created.
1 row created.
SQL> /
Enter value for sno: 102
Enter value for name: Rithu
Enter value for course: BCA
Enter value for amount: 150000
old 1: insert into t1 values(&sno,'&name','&course',&amount) new
1: insert into t1 values(102,'Rithu','BCA',150000)
1 row created.
SQL> /
Enter value for sno: 103
Enter value for name: Shivanya
Enter value for course: MCA Enter value for amount: 200000
old 1: insert into t1 values(&sno,'&name','&course',&amount)
new 1: insert into t1 values(103,'Shivanya','MCA',200000)
1 row created.
SQL> commit;
Commit complete.
SQL> update t1 set amount=10000 where sno=102;
1 row updated.
SQL> rollback;
Rollback complete.
Savepoint created.
1 row updated.
Savepoint created.
Rollback complete.
SQL> commit;
Commit complete.
Enter user-name: connect/ sys as sysdba
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select * from all_users;
USERNAME USER_ID CREATED
------------------------------ -------------------------- ---------
SCOTT 84 02-APR-10
OWBSYS_AUDIT 83 02-APR-10
OWBSYS 79 02-APR-10
APEX_030200 78 02-APR-10
APEX_PUBLIC_USER 76 02-APR-10
FLOWS_FILES 75 02-APR-10
MGMT_VIEW 74 02-APR-10
SYSMAN 72 02-APR-10
SPATIAL_CSW_ADMIN_USR 70 02-APR-10
SPATIAL_WFS_ADMIN_USR 67 02-APR-10
MDDATA 65 02-APR-10
30 rows selected.
User created.
Grant succeeded.
Table created.
SQL> /
Enter value for sno: 102
Enter value for name: Ram
old 1: insert into b1 values(&sno,'&name') new
1: insert into b1 values(102,'Ram')
1 row created.
SQL> /
Enter value for sno: 103 Enter value for
name: Reema old 1: insert into b1
values(&sno,'&name') new 1: insert into
b1 values(103,'Reema')
1 row created.
Grant succeeded.
Revoke succeeded.
SQL> commit;
Commit complete.
Ex. No: 05
IMPLEMENT NESTED QUERIES IN SQL
Table created.
1 row created.
SQL> /
Enter value for isbn: 102
Enter value for title: Economics
Enter value for pyear: 2021
Enter value for authorname: Dhanpat Rai Enter
value for pubname: Dhanpat Rai & co.
old 1: insert into book values(&isbn,'&title',&pyear,'&authorname','&pubname')
new 1: insert into book values(102,'Economics',2021,'Dhanpat Rai','Dhanpat Rai &
co.')
1 row created.
SQL> /
Enter value for isbn: 103
Enter value for title: Mathematics
Enter value for pyear: 2022
Enter value for authorname: R D sharma Enter value for pubname: Margham old
1: insert into book values(&isbn,'&title',&pyear,'&authorname','&pubname') new
1: insert into book values(103,'Mathematics',2022,'R D sharma','Margham')
1 row created.
Table created.
1 row created.
SQL> /
Enter value for authorname: Dhanpat Rai Enter value for
country: China old 1: insert into author
values('&authorname','&country') new 1: insert into
author values('Dhanpat Rai','China')
1 row created.
SQL> /
Enter value for authorname: Sultan chand Enter value for
country: India old 1: insert into author
values('&authorname','&country') new 1: insert into
author values('Sultan chand','India')
1 row created.
AUTHORNAME COUNTRY
-------------------- --------------------
R D sharma India
Dhanpat Rai China
Sultan chand India
SQL> commit;
Commit complete.
Ex. No: 06
1 row created.
SQL> /
Enter value for eno: 102
Enter value for name: Rithu
Enter value for unit: 200 Enter value for amt: 3000 old
1: insert into eb values(&eno,'&name',&unit,&amt) new
1: insert into eb values(102,'Rithu',200,3000)
1 row created.
SQL> /
Enter value for eno: 103
Enter value for name: Shivanya
Enter value for unit: 300 Enter value for amt: 4000 old
1: insert into eb values(&eno,'&name',&unit,&amt) new
1: insert into eb values(103,'Shivanya',300,4000)
1 row created.
SQL> /
Enter value for eno: 104
Enter value for name: Shivangi
Enter value for unit: 500 Enter value for amt: 6000 old
1: insert into eb values(&eno,'&name',&unit,&amt) new
1: insert into eb values(104,'Shivangi',500,6000)
1 row created.
SQL> /
Enter value for eno: 105
Enter value for name: Prithika
Enter value for unit: 600 Enter value for amt: 8000 old
1: insert into eb values(&eno,'&name',&unit,&amt) new
1: insert into eb values(105,'Prithika',600,8000)
1 row created.
SQL> select * from eb;
Table created.
SQL> insert into eb1(eno,pdate)values(201,(to_date('03-04-2003','dd-mm-yy')));
1 row created.
SQL> insert into eb1(eno,pdate)values(101,(to_date('03-04-2003','dd-mm-yy')));
1 row created.
SQL> insert into eb1(eno,pdate)values(102,(to_date('03-04-2003','dd-mm-yy')));
1 row created.
SQL> insert into eb1(eno,pdate)values(103,(to_date('04-04-2003','dd-mm-yy')));
1 row created.
SQL> insert into eb1(eno,pdate)values(104,(to_date('04-05-2003','dd-mm-yy')));
1 row created.
SQL> insert into eb1(eno,pdate)values(105,(to_date('04-05-2004','dd-mm-yy')));
1 row created.
SQL> desc eb1;
Name Null? Type
----------------------------------------- -------- ----------------------------
ENO NUMBER(4)
PDATE DATE
SQL> select * from eb1;
ENO PDATE
---------- ---------
201 03-APR-03
101 03-APR-03
102 03-APR-03
103 04-APR-03
104 04-MAY-03
105 04-MAY-04
6 rows selected.
SQL> select * from eb inner join eb1 on eb.eno=eb1.eno;
11 rows selected.
SQL> select * from eb right outer join eb1 on eb.eno<eb1.eno;
6 rows selected.
SQL> select eb.name,eb1.pdate from eb natural join eb1;
NAME PDATE
-------------------- ---------
Ragul 03-APR-03
Rithu 03-APR-03
Shivanya 04-APR-03
Shivangi 04-MAY-03
Prithika 04-MAY-04
SQL> select eno,name,unit,amt from eb natural join eb1;
NAME PDATE
-------------------- ---------
Ragul 03-APR-03
Ragul 03-APR-03
Ragul 03-APR-03
Ragul 04-APR-03
Ragul 04-MAY-03
Ragul 04-MAY-04
Rithu 03-APR-03
Rithu 03-APR-03
Rithu 03-APR-03
Rithu 04-APR-03
Rithu 04-MAY-03
NAME PDATE
-------------------- ---------
Rithu 04-MAY-04
Shivanya 03-APR-03
Shivanya 03-APR-03
Shivanya 03-APR-03
Shivanya 04-APR-03
Shivanya 04-MAY-03
Shivanya 04-MAY-04
Shivangi 03-APR-03
Shivangi 03-APR-03
Shivangi 03-APR-03
Shivangi 04-APR-03
NAME PDATE
-------------------- ---------
Shivangi 04-MAY-03
Shivangi 04-MAY-04
Prithika 03-APR-03
Prithika 03-APR-03
Prithika 03-APR-03
Prithika 04-APR-03
Prithika 04-MAY-03
Prithika 04-MAY-04
30 rows selected.
SQL> commit;
Commit complete.
Ex. No: 07
CREATE VIEWS FOR A PARTICULAR TABLE
Table created.
1 row created.
SQL> /
Enter value for id: 122
Enter value for name: hema
Enter value for address: delhi Enter value for salary:
40000 old 1: insert into cust
values(&id,'&name','&address',&salary) new 1: insert
into cust values(122,'hema','delhi',40000)
1 row created.
SQL> /
Enter value for id: 123
Enter value for name: yash
Enter value for address: chennai Enter value for salary:
56000 old 1: insert into cust
values(&id,'&name','&address',&salary) new 1: insert
into cust values(123,'yash','chennai',56000)
1 row created.
SQL> /
Enter value for id: 124
Enter value for name: ravi
Enter value for address: gujart Enter value for salary:
80000 old 1: insert into cust
values(&id,'&name','&address',&salary) new 1: insert
into cust values(124,'ravi','gujart',80000)
1 row created.
SQL> /
Enter value for id: 125
Enter value for name: hemanth
Enter value for address: nagpur Enter value for salary:
60000 old 1: insert into cust
values(&id,'&name','&address',&salary) new 1: insert
into cust values(125,'hemanth','nagpur',60000) 1 row
created.
View created.
SQL> create view cu_view as select name,address from cust where address is not null
with check option;
create view cu_view as select name,address from cust where address is not null with
check option
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
1 row updated.
SQL> commit;
Commit complete.
Ex. No: 08
LOCKS FOR PARTICULAR TABLE
SQL> /
Enter value for sno: 102
Enter value for name: ram Enter value for salary:
20000 old 1: insert into t1 values
(&sno,'&name',&salary) new 1: insert into t1
values (102,'ram',20000)
1 row created.
SQL> select * from t1;
Table created.
SQL> insert into alumini values('&aname','&address','&phone','°ree','&desig');
Enter value for aname: aswini
Enter value for address: tvm
Enter value for phone: 222233
Enter value for degree: bca Enter value for desig: designer old 1: insert into
alumini values('&aname','&address','&phone','°ree','&desig') new 1: insert
into alumini values('aswini','tvm','222233','bca','designer')
1 row created.
SQL> /
Enter value for aname: balu
Enter value for address: chennai
Enter value for phone: 222277
Enter value for degree: bba Enter value for desig: manager old 1: insert into
alumini values('&aname','&address','&phone','°ree','&desig') new 1: insert
into alumini values('balu','chennai','222277','bba','manager')
1 row created.
SQL> /
Enter value for aname: chitra
Enter value for address: car str
Enter value for phone: 222999
Enter value for degree: b.com Enter value for desig: accountant old 1: insert into
alumini values('&aname','&address','&phone','°ree','&desig') new 1: insert
into alumini values('chitra','car str','222999','b.com','accountant')
1 row created.
SQL> /
Enter value for aname: devi
Enter value for address: bye pass
Enter value for phone: 222559
Enter value for degree: ba Enter value for desig: teacher old 1: insert into alumini
values('&aname','&address','&phone','°ree','&desig') new 1: insert into
alumini values('devi','bye pass','222559','ba','teacher')
1 row created.
SQL> select *from alumini;
ANAME ADDRESS PHONE DEGREE DESIG
----------- ---------- --------- ---------- ----------
aswini tvm 222233 bca designer
balu chennai 222277 bba manager
chitra car str 222999 b.com accountant
devi bye pass 222559 ba teacher
SQL> declare
2 alumini_name alumini.aname%type;
3 change_address exception;
4 name varchar2(10);
5 a varchar2(15);
6 a1 varchar2(15);
7 begin
8 name:='&name';
9 a:='&a';
10 select address into a1 from alumini where aname=name;
11 if(a1=a)then
12 dbms_output.put_line('********************');
13 dbms_output.put_line('address not changed');
14 dbms_output.put_line('*******************');
15 else
16 update alumini set address=a where aname=name;
17 raise change_address;
18 end if;
19 exception when change_address then
20 dbms_output.put_line('address changed');
21 end;
22 /
Enter value for name: aswini
old 8: name:='&name'; new
8: name:='aswini'; Enter
value for a: tvm old 9:
a:='&a'; new 9: a:='tvm';
******************
address not changed
******************
PL/SQL procedure successfully completed.
SQL> /
Enter value for name: aswini
old 8: name:='&name';
new 8: name:='aswini';
Enter value for a: us old 9:
a:='&a'; new 9: a:='us';
address changed
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
Ex. No: 10
5 rows selected.
SQL> commit;
Commit complete.
Ex. No: 11
SQL> commit;
Commit complete.
Ex. No: 12