Академический Документы
Профессиональный Документы
Культура Документы
PRACTICAL FILE
(CS-700 )
Name: Year:
Section: subject:
Semester:
Approved by:
CS5003
Database Management System
Practical file
LAB OBJECTIVE
Upon successful completion of this Lab the student will be able to:
Introduction
SQL is structure query language.
SQL contains different data types those are
1. char(size)
2. varchar(size)
3. varchar2(size)
4. date
5. number(p,s) //** P-PRECISION S-SCALE **//
6. number(size)
7. raw(size)
8. raw/long raw(size)
Different types of commands in SQL:
A).DDL commands: - To create a database objects
B).DML commands: - To manipulate data of a database objects
C).DQL command: - To retrieve the data from a database.
D).DCL/DTL commands: - To control the data of a database…
EXPERIMENT NO. 1
DDL commands:
AIM:
To create a DDL to perform creation of table, alter, modify and drop column.
CREATION OF TABLE:
SYNTAX:
EXAMPLE:
Table created.
1 row created.
1 row created.
OUTPUT:
Table created.
SQL>insert into student values(1,’mercy’,’cricket’);
1 row created.
SYNTAX:
EXAMPLE:
OUTPUT:
ID NAME GAME
1 Mercy Cricket
SYNTAX:
EXAMPLE:
OUTPUT:
MODIFY
desc student;
NAME NULL? TYPE
Id Number(6)
Name Varchar(20)
Game Varchar(25)
Age Number(4)
DROP:
EXAMPLE:
SQL>Table dropped.
RESULT:
1. The Create Table Command: - it defines each column of the table uniquely. Each column has
minimum of three attributes, a name , data type and size.
Syntax:
Create table <table name> (<col1> <datatype>(<size>),<col2>
<datatype><size>));
Ex:
create table emp(empno number(4) primary key, ename char(10));
2. Modifying the structure of tables.
a) Add new columns
Syntax:
Alter table <tablename> add(<new col><datatype(size),<new
col>datatype(size));
Ex:
alter table emp add(sal number(7,2));
7. Destroying tables.
Syntax:
Drop table <tablename>;
Ex:
drop table emp;
EXPERIMENT NO. 3
DML COMMANDS
AIM:
To create a view for the purpose of display in order to hide the data.
VIEW:
A view is a logical data table that allows us to view data from other tables and values.
SYNTAX:
TABLE:
SPOID GAME
1 Cricket
2 Basketball
4 Tennis
QUERIES:
SQL>select std.sno,std.sname,sport.game from std,sport where std.sno=sport.spoid;
OUTPUT:
4 Amri Tennis
View created.
OUTPUT:
DROP VIEW:
To remove a view from the database, one has to use drop view.
view dropped;
RESULT:
1. Inserting Data into Tables: - once a table is created the most natural thing to do is load this table
with data to be manipulated later.
Syntax:
insert into <tablename> (<col1>,<col2>) values(<exp>,<exp>);
2. Delete operations.
b) unique constraint
Syntax:
Unique constraint at column level.
<col><datatype>(size)unique;
c) unique constraint at table level:
Syntax:
Create table tablename(col=format,col=format,unique(<col1>,<col2>);
h) Check constraint
check constraint constraint at column level.
Syntax: <col><datatype>(size) check(<logical expression>)
DCL commands
Oracle provides extensive feature in order to safeguard information stored in its tables from unauthoraised
viewing and damage. The rights that allow the user of some or all oracle resources on the server are called
privileges.
The grant statement provides various types of access to database objects such as tables, views and
sequences and so on.
Syntax:
GRANT <object privileges>
ON <objectname>
TO<username>
[WITH GRANT OPTION];
Syntax:
REVOKE<object privilege> ON FROM<user name>;
Result:
Thus the DCL commands have been successfully executed and the results are verified.
EXPERIMENT NO. 6
AIM:
QUERY:
CHARACTER FUNCTIONS:
SYNTAX:
ascii (string)
OUTPUT:
ASCII(‘A’)
65
INSTR:
SYNTAX:
i) instr(string/column name,x)
OUTPUT:
POSITION
2
POSITION
2
LENGTH:
SYNTAX:
i) length(string)
OUTPUT:
LENGTH(‘INDIA’)
5
OUTPUT:
LENGTH(NAME)
3
4
6
LPAD:
It pads the leading space to the left side of the column and fill with given character to the total
width of n.
SYNTAX:
i) lpad(char1,n,[,char2])
Ex: SQL>select lpad(‘abc’,10,’*’) from dual;
OUTPUT:
LPAD(‘ABC’)
*******ABC
OUTPUT:
LPAD(DEPTNAME,10,’*’)
*****sales
***account
****manager
CONCAT:
SYNTAX:
i) concat(x1,x2)
OUTPUT:
CONCAT(‘GOOD’,’EVENING’)
Goodevening
OUTPUT:
CONCAT(DEPTNO,DEPTNAME)
101sales
102account
103manager
CHR:
SYNTAX:
i) chr(x)
OUTPUT:
CHR(‘97’)
a
OUTPUT:
CHR(DEPTNO)
e
f
g
RPAD:
It pads the leading space to the right side of the column and fills with blank space to the width
of n.
SYNTAX:
i) rpad(char1,n,[,char2])
OUTPUT:
RPAD(‘ABC’)
abc*******
OUTPUT:
RPAD(DEPTN AME,10,’*’)
Sales*****
Account***
Manager****
LTRIM:
It removes the leading occurrences of that character from the string from left side position.
SYNTAX:
i) ltrim(string[,char(s)])
OUTPUT:
LTRIM(‘ABC’,’A’)
bc
ii) select ltrim(colname,[,char(s)]) from <tablename>;
OUTPUT:
LTRIM(DEPTNAME,’A’)
Sales
ccount
Manager
RTRIM:
It removes the leading occurrences of the character from the string from right side position.
SYNTAX:
i) rtrim(string,[,char(s)])
OUTPUT:
RTRIM(‘ABC’,’A’)
ab
OUTPUT:
RTRIM(DEPTNAME,’T’)
Sales
Accoun
Manager
REPLACE:
It replaces the character c2 with a given string c3 and returns the character c1.
SYNTAX:
i) replace(<c1>,<c2>[<c3>])
OUTPUT:
REPLACE(‘MADURAI’)
ijdurai
OUTPUT:
REPLACE(DEPTNAME,’A’,’C’)
Scles
ccount
Mcncger
SUBSTRING:
It returns the substring from string z, the length equal to y starting at position x.
SYNTAX:
i) substr(z,x[,y])
OUTPUT:
SUBSTR(MADURAI)
adur
OUTPUT:
SUBSTR(DEPTNAME)
le
co
na
EXPERIMENT NO. 7
NUMERIC FUNCTIONS:
ABS:
SYNTAX:
abs(x)
OUTPUT:
ABS(-8)
8
OUTPUT: ABS(DEPTNO)
101
102
103
SIN:
SYNTAX:
sin(x)
OUTPUT:
SIN(45)
.850903525
OUTPUT:
SIN(DEPTNO)
.452025787
.994826791
.622988631
COS:
SYNTAX:
cos(x)
OUTPUT:
COS(60)
-.95241298
OUTPUT:
COS(DEPTNO)
.89200487
.101585704
-.78223089
MOD:
SYNTAX:
mod(x,y)
OUTPUT:
OUTPUT:
MOD
1
0
1
POWER:
SYNTAX:
power(x,y)
OUTPUT:
POWER(3,5)
243
OUTPUT:
POWER
10201
10404
10609
EXP:
SYNTAX:
exp(x)
OUTPUT:
EXP(5)
148.413159
OUTPUT:
EXP(DEPTNO)
7.3071E+43
1.9863E+44
5.3992E+44
SQRT:
SYNTAX:
sqrt(x)
OUTPUT:
square_root
8
OUTPUT:
SQUARE_ROOT(DEPTNO)
10.0498756
10.0995049
10.1488916
TRUNC:
SYNTAX:
trunc(x,n)
OUTPUT:
OUTPUT:
TRUNC(DEPTNO,3)
101
102
103
RESULT:
EXPERIMENT NO. 8
PL/SQL
PROGRAM:
declare
n number(10);
i number(10);
m number(10);
f number(10):=0;
begin
n:=&n;
m:=n;
for i in 2..m/2
loop
f:=f+1;
end if;
end loop;
if(f=0) then
else
dbms_output.put_line('the given number is not
prime');
end if;
end;
OUTPUT:
RESULT:
EXPERINMENT NO. 9
2.CHECK PALINDROME OF A GIVEN NUMBER
PROGRAM:
declare
n number(10);
m number(10);
s number(10);
r number(10);
begin
n:=&n;
m:=n;
s:=0;
while(n>0)
loop
s:=(s*10)+r;
n:=floor(n/10);
end loop;
if(m=s) then
palindrome');
else
palindrome');
end if;
end;
OUTPUT:
RESULT:
EXPERIMENT NO. 10
NO_DATA_FOUND EXCEPTION
TABLE:
Table created.
PROGRAM:
declare
veno emp5.empno%type:=&empno;
vename emp5.ename%type:='&ename';
vdeptno emp5.deptno%type;
begin
exception
end;
OUTPUT:
deptno is1
no records found
RESULT:
PRACTICAL FILE
CGMM (CS-5004)
Name: Year:
Section: subject:
Semester:
Approved by: