Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
15 views40 pages

DBMS PDF

The document is a practical record for students at C.S.I College of Arts and Science for Women, detailing various SQL commands and PL/SQL programs. It includes sections on DDL, DML, aggregate functions, sub-queries, and row types, with examples and outputs for each command. The record serves as a certification of the practical work completed by students during their course.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views40 pages

DBMS PDF

The document is a practical record for students at C.S.I College of Arts and Science for Women, detailing various SQL commands and PL/SQL programs. It includes sections on DDL, DML, aggregate functions, sub-queries, and row types, with examples and outputs for each command. The record serves as a certification of the practical work completed by students during their course.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

C.S.

I COLLEGE OF ARTS AND SCIENCE FOR


WOMEN
KARPAGA NAGAR, K.PUDUR, MADURAI-625007.

CERTIFICATE

RECORD OF PRACTICAL WORK IN: BRANCH:

THIS TO CERTIFY THAT THIS IS THE BONAFIDE RECORD OF PRACTICAL

WORK DONE BY………………………………………….REG.NO. ……………..…………………………….

IN THE YEAR………………….

STAFF IN-CHARGE

SUBMITTED FOR

PRACTICAL EXAMINATION

EXTERNAL EXAMINER

1.

2.
INDEX

S.NO DATE CONTENT PAGE NO SIGNATURE


SQL QUERIES
1 DDL COMMANDS 1
2 DML COMMANDS 4
3 AGGREGATE FUNCTION 8
4 SUB-QUERY 13
PL/SQL PROGRAMS
5 ROWTYPE 17
6 FACTORIAL NUMBER 19
7 FIBONACCI SERIES 21
8 ARMSTRONG NUMBER 23
9 IMPLICIT CURSOR 25
10 EXPLICIT CURSOR 27
11 STRING MANIPULATION 29
12 EMPLOYEE DETAILS 31
13 GREATER NUMBER 33
14 EB BILL PREPARATION 35
15 EXCEPTION HANDLING 37
EX.NO:1 DDL COMMANDS

1. Create a Student Marklist with the following fields:

name,reg_no,mark_1,mark_2,mark_3.

Query 1:

SQL> create table student_Marklist(name varchar(20),reg_no number(5),mark_1


number(3),mark_2 number(3),mark_3 number(3));

Table created.

2. Show the structure of the Student Marklist table.

Query 2:.

SQL> desc student_Marklist;

Name Null? Type

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

NAME VARCHAR2(20)

REG_NO NUMBER(5)

MARK_1 NUMBER(3)

MARK_2 NUMBER(3)

MARK_3 NUMBER(3)

3. Add the new field Total to the Student Marklist table.

Query 3:

SQL> Alter table student_Marklist add(Total number(3));

Table altered.

1
SQL> desc student_Marklist;

Name Null? Type

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

NAME VARCHAR2(20)

REG_NO NUMBER(5)

MARK_1 NUMBER(3)

MARK_2 NUMBER(3)

MARK_3 NUMBER(3)

TOTAL NUMBER(3)

4. Modify the Not null value to field of reg_no in the student marklist table.

Query 4:

SQL> alter table student_Marklist modify(reg_no number(5)not null);

Table altered.

SQL> desc student_Marklist;

Name Null? Type

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

NAME VARCHAR2(20)

REG_NO NOT NULL NUMBER(5)

MARK_1 NUMBER(3)

MARK_2 NUMBER(3)

MARK_3 NUMBER(3)

TOTAL NUMBER(3)

2
5. Clear the screen.

Query 5:

SQL>cl scr;

Output:

SQL>

6. Delete the student marklist table.

Query 6:

SQL>drop table student_Marklist;

Table dropped.

7. Check the existence of the table.

Query 7:

SQL>desc Student_Marklist;

ERROR:

ORA-04043:object student does not exist.

RESULT:

Thus the above program is executed and the output is verified.

3
EX.NO:2 DML COMMANDS

8. Insert 5 rows into the Student marklist table.

Query 8:

SQL> insert into student_Marklist values('&name','&reg_no',&mark_1,&mark_2,&mark_3);

5 rows inserted.

9. Display all the records from the Student Marklist table.

Query 9:

SQL> select*from student_Marklist;

NAME REG_NO MARK_1 MARK_2 MARK_3 TOTAL

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

Abi 1 98 99 100 297

Poojakumari 2 60 79 80 219

janani 3 45 55 80 180

Dharshini 4 35 12 55 102

Ayesha 5 75 46 50 171

10. Display only the name and reg_no for all the students.

Query 10:

SQL> select name,reg_no from student_Marklist;

4
OUTPUT:

NAME REG_NO

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

Abi 1

Poojakumari 2

janani 3

Dharshini 4

Ayesha 5

11. Display the name,mark_1,mark_2,mark_3,total of all the students which reg_no


is 1.

Query 11:

SQL> select name,mark_1,mark_2,mark_3,total from student_Marklist where reg_no=1;

OUTPUT:

NAME MARK_1 MARK_2 MARK_3 TOTAL

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

Abi 98 99 100 297

12. Display the name, mark_2 which mark_2 is less than 35.

Query 12:

SQL> select name,mark_2 from student_Marklist where mark_2<=35;

OUTPUT:

NAME MARK_2

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

Dharshini 12

5
13. Change the mark_2 of the student to 86 whose mark_2 is 12.

Query 13:

SQL> update student_Marklist set mark_2=86 where mark_2=12;

1 row updated.

SQL> select*from student_Marklist;

NAME REG_NO MARK_1 MARK_2 MARK_3 TOTAL

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

Abi 1 98 99 100 297

Poojakumari 2 60 79 80 219

janani 3 45 55 80 180

Dharshini 4 35 86 55 102

Ayesha 5 75 46 50 171

14. Delect the student whose reg_no is 5.

Query 14:

SQL> delete from student_Marklist where reg_no=5;

1 row deleted.

SQL> select*From student_Marklist;

NAME REG_NO MARK_1 MARK_2 MARK_3 TOTAL

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

Abi 1 98 99 100 297

Poojakumari 2 60 79 80 219

janani 3 45 55 80 180

Dharshini 4 35 86 55 176

6
15. Delete all the records using Truncate in student marklist table.

Query 15:

SQL> truncate table Student_marklist;

Table truncated.

SQL> select*from student_Marklist;

no rows selected.

RESULT:

Thus the above program is executed and the output is verified.

7
EX.NO:3 AGGREGATE FUNCTION

1. Create a Student with the following fields:

name,reg_no,mark_1,mark_2,mark_3.

Query 1:

SQL> create table student(name varchar(20),reg_no number(5),mark_1 number(3),mark_2


number(3),mark_3 number(3));

Table created.

2. Insert 5 rows into the Student table.

Query 2:

SQL> insert into student values('&name','&reg_no',&mark_1,&mark_2,&mark_3);

Enter the value for name:Abi

Enter the value for reg_no:1

Enter the value for mark_1:98

Enter the value for mark_2:99

Enter the value for mark_3:80

1 rows inserted.

…………………

………………….

SQL> select*from student;

8
NAME REG_NO MARK_1 MARK_2 MARK_3

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

Abi 1 98 99 100

Poojakumari 2 60 79 80

janani 3 45 55 80

Dharshini 4 35 12 55

Ayesha 5 75 46 50

3. Add the new field Total to the Student Marklist table.

Query 3:

SQL> Alter table student add(Total number(3),average number(3));

Table altered.

SQL> desc student;

Name Null? Type

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

NAME VARCHAR2(20)

REG_NO NUMBER(5)

MARK_1 NUMBER(3)

MARK_2 NUMBER(3)

MARK_3 NUMBER(3)

TOTAL NUMBER(3)

AVERAGE NUMBER(3)

9
4. To find the total and average of the student table.

SQL>update table student set total=mark_1+ mark_2+ mark_3;


SQL>update table student set average=total/3;

OUTPUT:

NAME REG_NO MARK_1 MARK_2 MARK_3 TOTAL AVERAGE

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

Abi 1 98 99 100 297 99

Poojakumari 2 60 79 80 219 73

Janani 3 45 55 80 180 60

Dharshini 4 35 12 55 176 59

Ayesha 5 75 46 50 102 34

5. To find the number of student in the student table.

SQL>select count(reg_no)from student;

OUTPUT:

COUNT(REG_NO)
-----------------------
5

6. Find the highest total among all in the student table.

SQL>select reg_no,name,max(total)from student;

OUTPUT:

NAME REG_NO TOTAL

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


Abi 1 297

10
7. Find the minimum average among all the student.

SQL>select name,reg_no,total,avg(average)from student;

OUTPUT:

NAME REG_NO TOTAL AVERAGE


--------- ------------- ---------- ----------------
Ayesha 1 102 34

8. Find the total of mark_3 column in the student table.

SQL>select sum(mark_3)from student;

OUTPUT

SUM(MARK_3)
-----------------------
365

9. Display the student name the letter starts from P.

SQL>select*from student where name=’P%’;

OUTPUT:

NAME REG_NO MARK_1 MARK_2 MARK_3 TOTAL AVERAGE

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

Poojakuma 2 60 79 80 219 73

10. Display the records who’s got the average above 90 percent.

SQL>select*from student where average>90;

11
OUTPUT:

NAME REG_NO MARK_1 MARK_2 MARK_3 TOTAL AVERAGE

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

Abi 1 98 99 100 297 99

RESULT:

Thus the above program is executed and the output is verified.

12
EX.NO:4 SUB-QUERY

1. Create a Customer table with the following fields:


(id,name,age,address,salary)

Query 1:

SQL> create table customer(id int not null,,name varchar(20),age number(3),address


varchar(20),salary number(7),primary key(id));

Table created.

2. Insert 5 rows into the Customer table.

Query 2:

SQL> insert into customer values(&id,'&name',&age,’&address’,&salary);


5 rows inserted.

3. Display all the records from the Customer table.

Query 3:

SQL> select*from customer;

ID NAME AGE ADDRESS SALARY

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

1 Abi 21 Madurai 25000

2 Poojakumari 22 Mathur 50000

3 Janani 20 Madurai 35000

4 Dharshini 23 Pudur 27000

5 Ayesha 24 Madurai 37000

13
Query 4:

Select*from customer where id in(select id from customer where salary > 25000);

OUTPUT:

ID NAME AGE ADDRESS SALARY

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

2 Poojakumari 22 Mathur 50000

3 Janani 20 Madurai 35000

4 Dharshini 23 Pudur 27000

5 Ayesha 24 Madurai 37000

Query 5:

SQL> create table customer_new(id int not null,,name varchar(20),age


number(3),address varchar(20),salary number(7),primary key(id));

Table created.

Query 6:

SQL> insert into customer_new select*from customer where id in (select id from customer);

Select*From customer_new;

ID NAME AGE ADDRESS SALARY

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

1 Abi 21 Madurai 25000

2 Poojakumari 22 Mathur 50000

3 Janani 20 Madurai 35000

4 Dharshini 23 Pudur 27000

5 Ayesha 24 Madurai 37000

14
Query 7:

SQL>update customer set salary=salary*0.25 where age in(select age from customer_new where
age >=20);

OUTPUT:

5 rows updated.

Query 8:

select*from customer;

OUTPUT:

ID NAME AGE ADDRESS SALARY

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

1 Abi 21 Madurai 6250

2 Poojakumari 22 Mathur 12500

3 Janani 20 Madurai 8750

4 Dharshini 23 Pudur 6750

5 Ayesha 24 Madurai 9250

Query 9:

SQL>delete from customers where age in(select age from customer_new where age >= 23);

OUTPUT:

2 rows deleted.

Query 10:

select*from customer;

15
OUTPUT:

ID NAME AGE ADDRESS SALARY

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

1 Abi 21 Madurai 6250

2 Poojakumari 22 Mathur 12500

3 Janani 20 Madurai 8750

RESULT:

Thus the above program is executed and the output is verified.

16
EX.NO:5 ROWTYPE

AIM:

To write a PL/SQL Program for Rowtype using employee table.

CODING:

declare

employee customer_Abi%rowtype;

begin

employee.id:=&id;

employee.name:='&name';

employee.age:=&age;

employee.address:='&address';

employee.salary:=&salary;

insert into customer_Abi(id,name,age,address,salary)values(employee.id,employee.name,

employee.age,employee.address,employee.salary);

dbms_output.put_line('ROW INSERTED');

end;

17
OUTPUT:

RESULT:

The given program is run successfully.

18
EX.NO:6 FACTORIAL NUMBER

AIM:

To write a PL/SQL Program for Factorial number using While loop.

CODING:

declare

n number:=&n;

f number:=1;

i number:=1;

begin

while(i<=n)

loop

f:=f*i;

i:=i+1;

end loop;

dbms_output.put_line('The factorial of '||n||' is '||f);

end;

19
OUTPUT:

RESULT:

The given program is run successfully.

20
EX.NO: 7 FIBONACCI SERIES

AIM:

To write a PL/SQL Program for Fibonacci series using For loop.

CODING:

declare

n number:=&n;

a number;

b number;

c number;

i number;

begin

dbms_output.put_line('FIBONACCI SERIES ARE');

a:=0;

b:=1;

dbms_output.put_line(a);

dbms_output.put_line(b);

for i in 2..n

loop

c:=a+b;

dbms_output.put_line(c);

a:=b;

b:=c;

end loop;

end;/

21
OUTPUT:

RESULT:

The given program is run successfully.

22
EX.NO:8 ARMSTRONG NUMBER

AIM:

To write a PL/SQL Program for Armstrong number using while.

CODING:

declare

n number(3);

s number(3):=0;

r number(3);

t number(3);

begin

n:=&n;

t:=n;

while(n>0)

loop

r:=n mod 10;

s:=s+(r*r*r);

n:=trunc(n/10);

end loop;

if(s=t)then

dbms_output.put_line('Given number is artmstrong');

else

dbms_output.put_line('given number is not a armstrong');

end if;

end;/

23
OUTPUT:

RESULT:

The given program is run successfully.

24
EX.NO:9 IMPLICIT CURSOR

AIM:

To write a PL/SQL Program for Implicit cursor using customer table.

CODING:

declare

total_rows number(2);

begin

update customer set salary=salary+5000;

if sql% notfound then

dbms_output.put_line('no customer update');

elsif sql% found then

total_rows:=sql% rowcount;

dbms_output.put_line(total_rows||' number of customer update');

end if;

end;

25
OUTPUT:

RESULT:

The given program is run successfully.

26
EX.NO: 10 EXPLICIT CURSOR

AIM:

To write a PL/SQL Program for Explicit cursor using customer table.

CODING:

declare

c_id customer.id%type;

c_name customer.name%type;

c_address customer.address%type;

cursor c_customer is select id,name,address from customer;

begin

open c_customer;

loop

fetch c_customer into c_id,c_name,c_address;

exit when c_customer% notfound;

dbms_output.put_line(c_id||' '||c_name||' '||c_Address);

end loop;

close c_customer;

end;

27
OUTPUT:

RESULT:

The given program is run successfully.

28
EX.NO:11 STRING MANIPULATION

AIM:

To write a PL/SQL Program for String manipulation.

CODING:

declare

s1 varchar2(15);

s2 varchar2(15);

s3 varchar2(30);

s4 varchar2(30);

s5 varchar2(30);

s6 varchar2(30);

s7 varchar2(30);

s8 varchar2(40);

begin

dbms_output.put_line('Enter the string 1 and 2');

s1:='&s1';

s2:='&s2';

dbms_output.put_line('Given string'||s1||' '||s2);

s3:=upper(s1||''||s2);

dbms_output.put_line('Upper string'||s3);

s4:=lower(s1||' '||s2);

dbms_output.put_line('Lower string'||s4);

s5:=ltrim(s1||s2);

dbms_output.put_line('Ltrim string'||s5);

29
s6:=rtrim(s1||s2);

dbms_output.put_line('Rtrim string'||s6);

s7:=initcap(s1||s2);

dbms_output.put_line('Initcap string'||s7);

s8:=concat(s1,s2);

dbms_output.put_line('Concat string'||s8);

end;

OUTPUT:

RESULT:

The given program is run successfully.

30
EX.NO:12 EMPLOYEE DETAILS

AIM:

To write a PL/SQL Program for showing the how many records in employee detail table
using Function creation.

CODING:

create or replace function totalemp return number is

total number(2):=0;

begin

select count(*)into total from emp_Abi;

return total;

end;

declare

total number(2);

begin

total:=totalemp();

dbms_output.put_line('Total number of records '||total);

end;

31
OUTPUT:

RESULT:

The given program is run successfully.

32
EX.NO:13 GREATER NUMBER

AIM:

To write a PL/SQL Program for Greater number using Procedure creation.

CODING:

create or replace procedure findmax(a in number,b in number)is

begin

dbms_output.put_line('Greater number is: ');

if a>b then

dbms_output.put_line(a);

else

dbms_output.put_line(b);

end if;

end;

declare

x number;

y number;

begin

x:=&x;

y:=&y;

findmax(x,y);

end;

33
OUTPUT:

RESULT:

The given program is run successfully.

34
EX.NO:14 EB BILL PREPARATION

AIM:

To write a PL/SQL Program for EB Bill.

CODING:

declare

eno number(10):=&eno;

ename varchar(10):='&ename';

cr number(10):=&cr;

pr number(10):=&pr;

r number(10);

a number(10);

begin

r:=cr-pr;

dbms_output.put_line('OUTPUT: ');

dbms_output.put_line('Total readings = '||r);

if(r>=700)then

a:=r*5;

dbms_output.put_line('Electric bill amount = '||a);

elsif(r>=500)then

a:=r*3;

dbms_output.put_line('Electric bill amount = '||a);

elsif(r>=300)then

a:=r*2;

dbms_output.put_line('Electric bill amount ='||a);

35
else

dbms_output.put_line('FREE CURRENT');

end if;

end;

OUTPUT:

RESULT:

The given program is run successfully.

36
EX.NO:15 EXCEPTION HANDLING

AIM:

To write a PL/SQL Program for Exception handling using student table.

CODING:

declare

c_id customer_Abi.Id%type;

c_name customer_Abi.Name%type;

c_add customer_Abi.Address%type;

begin

c_id:='&id';

select Name,Address into c_name,c_add from customer_Abi where id=c_id;

dbms_output.put_line('name :'||c_name||' address: '||c_add);

exception

when no_data_found then

dbms_output.put_line('no such customer');

when others then

dbms_output.put_line('error');

end;

37
OUTPUT:

RESULT:

The given program is run successfully.

38

You might also like