RDBMS Lab Programs
RDBMS Lab Programs
RDBMS Lab Programs
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
sum(Emp_salary)
36202.55
avg(Emp_Salary)
9050.637500
max(Emp_Salary)
10000.75
min(Emp_Salary)
7500.50
count(Emp_Salary)
upper(Emp_Name)
JOHN
JACK
JAI
JAGAN
john
jack
jai
jagan
SQL> Select substr(Emp_Name, 2, 3) from EMPLOYEE;
substr(Emp_Name, 2, 3)
ohn
ack
ai
aga
length(Emp_Name)
4
4
3
5
round(Emp_salary)
9001
9701
10001
7501
abs(-17.36)
17.36
mod(25,7)
power(2,3)
8
SQL> Select sqrt(36) from dual;
sqrt(36)
Emp_salary
9000.50
9700.80
10000.75
7500.50
Emp_ID
101
102
103
104
GROUP FUNCTIONS
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL>desc PRODUCT;
PRODUCT_NAME VARCHAR(10)
COMPANY_ID VARCHAR(10)
NO_OF_PRODUCT NUMBER
COST NUMBER
MRP NUMBER
count(*)
count(distinct Company_ID)
Company_ID count(*)
COM1 3
COM2 3
COM3 2
SQL>select Company_ID, count(*) from PRODUCT group by Company_ID
having count(*)>2;
Company_ID count(*)
COM1 3
COM2 3
sum(MRP)
1210
sum(MRP)
900
170
Company_ID sum(MRP)
COM1 520
COM2 1400
COM3 610
2. EXECUTE DDL COMMANDS
DDL COMMANDS
Table created.
SQL>Desc STUDENT_DETAILS;
STU_ID NUMBER(38)
STU_NAME VARCHAR2(10)
STU_AGE NUMBER(38)
STU_PHONE_NUM VARCHAR2(10)
Table altered.
SQL>Desc STUDENT_DETAILS;
STU_ID NUMBER(38)
STU_NAME VARCHAR2(10)
STU_AGE NUMBER(38)
STU_PHONE_NUM VARCHAR2(10)
STU_ADDRESS VARCHAR2(10)
Table altered.
SQL>Desc STUDENT_DETAILS;
STU_ID NUMBER(38)
STU_NAME VARCHAR2(10)
STU_PHONE_NUM VARCHAR2(10)
STU_ADDRESS VARCHAR2(10)
Table altered.
SQL>Desc STUDENT_DETAILS;
ERROR:
ORA-04043: object STUDENT_DETAILS does not exist
SQL>Desc STUDENT_INFO;
STU_ID NUMBER(38)
STU_NAME VARCHAR2(10)
STU_PHONE_NUM VARCHAR2(10)
STU_ADDRESS VARCHAR2(10)
1 row created.
Table truncated.
No rows selected.
SQL>drop table STUDENT_INFO;
Table dropped.
SQL>Desc STUDENT_INFO;
ERROR:
ORA-04043: object STUDENT_INFO does not exist
3. EXECUTE DML COMMANDS
DML COMMANDS
Table created.
SQL>Desc STUDENT_DETAILS;
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL>Select * from STUDENT_DETAILS;
Stu_Name
AAA
BBB
CCC
DDD
EEE
1 row updated.
1 row deleted.
DCL COMMANDS
Table created.
E_ID NUMBER
E_NAME VARCHAR(10)
SQL> conn
Connected.
Grant succeeded.
Revoke succeeded.
ERROR at line 1:
ORA-01749: you may not GRANT/REVOKE privileges to/from yourself
TCL COMMANDS
Table created.
REG_NUM NUMBER
STU_NAME VARCHAR(10)
TAMIL NUMBER
ENGLISH NUMBER
MAJOR NUMBER
ALLIED NUMBER
1 row created.
1 row created.
1 row created.
1 row created.
SQL> insert into STUDENT_MARK_DETAILS values(1005,'JAI', 87, 79, 76,
73);
1 row created.
1 row created.
1 row created.
1 row created.
SQL> commit;
Commit complete.
1001 JACK 90 70 87 76
1002 SMITH 69 86 77 78
1003 JHON 66 77 88 90
1004 JANANI 76 87 86 85
1005 JAI 87 79 76 73
1006 ARUN 87 79 76 73
1007 ABI 87 79 76 73
1008 PAVI 87 79 76 73
1 row deleted.
SQL> commit;
Commit complete.
SQL> select * from STUDENT_MARK_DETAILS;
1001 JACK 90 70 87 76
1002 SMITH 69 86 77 78
1004 JANANI 76 87 86 85
1005 JAI 87 79 76 73
1006 ARUN 87 79 76 73
1007 ABI 87 79 76 73
1008 PAVI 87 79 76 73
1 row deleted.
SQL> rollback;
Rollback complete.
1001 JACK 90 70 87 76
1002 SMITH 69 86 77 78
1004 JANANI 76 87 86 85
1005 JAI 87 79 76 73
1006 ARUN 87 79 76 73
1007 ABI 87 79 76 73
1008 PAVI 87 79 76 73
Savepoint created.
1 row deleted.
Savepoint created.
SQL> delete from STUDENT_MARK_DETAILS where English>= 80;
1 row deleted.
Savepoint created.
Table altered.
Rollback complete.
1001 JACK 90 70 87 76
1002 SMITH 69 86 77 78
1004 JANANI 76 87 86 85
1005 JAI 87 79 76 73
1006 ARUN 87 79 76 73
1007 ABI 87 79 76 73
5. IMPLEMENT THE NESTED QUERIES
NESTED QUERIES
Table created.
SQL>Desc DEPOSITOR;
Name Null? Type
--------------- ------- --------------------
CUST_NAME VARCHAR(20)
ACC_NO VARCHAR(10)
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Cust_Name Acc_No
Jones 101
Smith 102
Hayas 103
Adams 104
smith 105
SQL> commit;
Commit complete.
Table created.
CUS_NAME VARCHAR(20)
LOAN_NO VARCHAR(10)
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Williams 101
Johnson 102
Jones 103
Smith 104
Jackson 105
SQL> select Cust_Name from DEPOSITOR
where Cust_Name IN (select Cus_Name from BORROWER);
Cust_Name
Jones
Smith
smith
cust_name
Hayas
Adams
Cus_Name
Jones
Smith
Cus_Name
Williams
Johnson
Jackson
Table created.
SQL>Desc BRANCH;
BRANCH_NAME VARCHAR(20)
BRANCH_CITY VARCHAR(20)
ASSETS VARCHAR(20)
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> commit;
Commit complete.
SQL> select Branch_Name, Branch_City from BRANCH where Assets >
SOME (select Assets from BRANCH
where Branch_City ='brooklyn');
Branch_Name Branch_City
perryridge horseneck
redwood paloalto
Branch_Name Branch_City
roundhill bennington
Branch_Name Branch_City
brighton brooklyn
downtown brooklyn
perryridge horseneck
redwood paloalto
6. IMPLEMENT JOIN OPERATIONS IN SQL
Table created.
P_ID NUMBER(5)
P_NAME VARCHAR2(20)
SUPPLIER_NAME VARCHAR2(20)
UNIT_PRICE NUMBER(5)
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> select * from PRODUCT_DET;
SQL> commit;
Commit complete.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> select * from ORDER_DET;
SQL> commit;
Commit complete.
100 camera
101 television 5103 30
120 fridge 5101 10
103 ipod 5102 20
104 mobile 5100 30
SQL> commit;
Commit complete.
7. CREATE VIEWS FOR A PARTICULAR TABLE
Table created.
C_ID VARCHAR(10)
C_NAME VARCHAR(10)
C_AGE NUMBER
C_ADDRESS VARCHAR(10)
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> select * from CUSTOMER;
Table created.
P_ID VARCHAR(10)
P_COST NUMBER
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> select * from PRODUCT;
P_ID P_COST
P111 500
P122 450
P133 764
P144 674
P155 567
SQL> create view CUS_VIEW as select C_ID, C_NAME, C_AGE, P_ID from
CUSTOMER, PRODUCT;
View created.
View dropped.
8. IMPLEMENT LOCKS FOR A PARTICULAR TABLE
Table created.
C_ID NUMBER
C_NAME VARCHAR(10)
C_ADDRESS VARCHAR(10)
1 row created.
1 row created.
Table(s) Locked.
Table(s) Locked.
SQL> Lock table CUSTOMER in share update mode;
Table(s) Locked.
Table(s) Locked.
Table(s) Locked.
Table(s) Locked.
Table(s) Locked.
9. WRITE PL/SQL PROCEDURE FOR AN APPLICATION USING
EXCEPTION HANDLING
Table created.
ALUMINI_NO VARCHAR(5)
NAME VARCHAR(15)
PASSOUT_YEAR DATE
ADDRESS VARCHAR(15)
1 row created.
SQL> /
Enter value for alumini_no: 102
Enter value for name: bhuvana
Enter value for passout: 05-may-2010
Enter value for address: arcot
old 1: insert into alumini_02
values(&alumini_no,'&name','&passout','&address')
new 1: insert into alumini_02 values(102,'bhuvana','05-may-2010','arcot')
1 row created.
SQL> /
Enter value for alumini_no: 103
Enter value for name: romiya
Enter value for passout: 05-may-2010
Enter value for address: vandavasi
old 1: insert into alumini_0
values(&alumini_no,'&name','&passout','&address')
new 1: insert into alumini_02 values(102,'bhuvana','05-may-2010','arcot')
1 row created.
SQL> /
Enter value for alumini_no: 104
Enter value for name: lakshmi
Enter value for passout: 01-may-2010
Enter value for address: Chennai
old 1: insert into alumini_02
values(&alumini_no,'&name','&passout','&address')
new 1: insert into alumini_02 values(104,'lakshmi','01may2010','chennai')
1 row created.
SQL> commit
commit complete.
EXCEPTION HANDLING
ed alu_02.sql
Function created.
ed alu_03.sql
SQL> declare
address varchar2(150);
alumino number(5);
begin
dbms_output.put_line('enter alumino');
alumino:=&alumino;
address:=findaddress(alumino);
dbms_output.put_line('output is'||address);
end;
/
SQL> commit;
Commit complete.
10.WRITE PL/SQL PROCEDURE FOR AN APPLICATION USING
CURSORS
Table created.
E_NO NUMBER(5)
E_NAME VARCHAR2(15)
SALARY NUMBER(10)
1 row created.
SQL> /
Enter value for e_no: 102
Enter value for name: jones
Enter value for salary: 5000
old 1: insert into cursors_01 values(&e_no,'&name',&salary)
new 1: insert into cursors_01 values(101,'smith',3000)
1 row created.
SQL> /
Enter value for e_no: 103
Enter value for name: hayes
Enter value for salary: 1500
old 1: insert into cursors_01 values(&e_no,'&name',&salary)
new 1: insert into cursors_01 values(103,'hayes',1500)
1 row created.
SQL> /
Enter value for e_no: 104
Enter value for name: johnson
Enter value for salary: 1000
old 1: insert into cursors_01 values(&e_no,'&name',&salary)
new 1: insert into cursors_01 values(104,'johnson',1000)
1 row created.
SQL> commit;
Commit complete.
CURSOR
ed cur_01.sql
SQL>
declare
cursor emp_cur is select * from cursors_01 where salary>2000;
emp_no cursors_01.e_no % type;
emp_name cursors_01.e_name % type;
emp_sal cursors_01.salary % type;
begin
open emp_cur;
loop
fetch emp_cur into emp_no,emp_name,emp_sal;
exit when emp_cur % notfound;
update cursors_01 set salary=salary+100 where e_no=emp_no;
end loop;
commit;
close emp_cur;
end;
/
SQL> set serveroutput on;
SQL> @ cur_01;
SQL> commit;
Commit complete.
11.WRITE A PL/SQL PROCEDURE FOR AN APPLICATION USING
FUNCTIONS
Table created.
1 row created.
SQL> /
Enter value for phone_no: 225544
Enter value for user_name: pooja
Enter value for door_no: 24
Enter value for street: bazar street
Enter value for place: thellar
Enter value for pincode: 604408
old 1: insert into ph_bk_01
values(&phone_no,'&user_name',&door_no,'&street','&place',&pincode)
new 1: insert into ph_bk_01 values(225544,'pooja',24,'bazar
street','thellar',604408)
1 row created.
SQL> /
Enter value for phone_no: 224477
Enter value for user_name: priya
Enter value for door_no: 17
Enter value for street: police street
Enter value for place: chetpet
Enter value for pincode: 606801
old 1: insert into ph_bk_01
values(&phone_no,'&user_name',&door_no,'&street','&place',&pincode)
new 1: insert into ph_bk_01 values(224477,'priya',17,'police
street','chetpet',606801)
1 row created.
SQL> /
Enter value for phone_no: 226053
Enter value for user_name: sathya
nter value for door_no: 100
Enter value for street: gandhi street
Enter value for place: vellore
Enter value for pincode: 604478
old 1: insert into ph_bk_01
values(&phone_no,'&user_name',&door_no,'&street','&place',&pincode)
new 1: insert into ph_bk_01 values(226053,'sathya',100,'gandhi
street','vellore',604478)
1 row created.
Commit complete.
FUNCTIONS
ed ph_01.sql
SQL>
create or replace function findaddress(phone in number)return varchar is
address varchar(150);
begin
select user_name||','||door_no||','||street||','||place||','||pincode into address
from PHONE BOOK where phone_no=phone;
return address;
exception
when no_data_found then
dbms_output.put_line('ans:phone_no is not found');
end;
/
Function created.
ed ph_11.sql
SQL>
declare
address varchar2(150);
phone number(7);
begin
dbms_output.put_line('enter phone_no');
phone:=☎
address:=findaddress(phone);
dbms_output.put_line('output'||address);
end;
/
SQL> commit;
Commit complete.
12. WRITE A PL/SQL PROCEDURE FOR AN APPLICATION
USING
PACKAGE
SQL> create or replace package Manage_Employee Is
procedure Add_Emp(P_ID number, P_Name varchar);
procedure Edit_Emp(P_ID number, P_Name varchar);
end Manage_Employee;
/
Package created.
Employee Added
Employee Updated