0% found this document useful (0 votes)
111 views44 pages

Experiment No 1 .1

This document describes experiments performed on database management systems using SQL. It introduces the creation of tables, insertion of data, querying data, updating records, deleting records, and modifying table structures. The key tasks covered include creating a student table with attributes like name, roll number and branch, populating it with data, querying the table to select, filter and sort records, updating records by modifying names and adding to roll numbers, deleting selected and all records, and adding a new column to the table.

Uploaded by

du_anjali
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views44 pages

Experiment No 1 .1

This document describes experiments performed on database management systems using SQL. It introduces the creation of tables, insertion of data, querying data, updating records, deleting records, and modifying table structures. The key tasks covered include creating a student table with attributes like name, roll number and branch, populating it with data, querying the table to select, filter and sort records, updating records by modifying names and adding to roll numbers, deleting selected and all records, and adding a new column to the table.

Uploaded by

du_anjali
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 44

DATABASE MANAGEMENT

SYSTEM LAB

(Subject Code: ETCS-357)

FACULTY NAME: Mrs. Neetu Gupta STUDENT NAME : Ashish Chaudhary


ROLL NO :0361482808
SEMESTER :V
BATCH :ECE 123

MAHARAJA AGRESEN INSTECEUTE OF


TECHNOLOGY
PSP AREA,SECTOR-22,
ROHINI,NEW DELHI-110085
Experiment no- 1
Table creation-
SQL> connect

Enter user-name: system

Enter password:

Connected.

SQL> create table student ( name varchar2(10),roll_no number(3),branch varchar2(10));

Table created.

Adding data into tables-


Add data to all attributes in the order mentioned during table
creation:add a record in student table-
SQL> insert into student values('ashish','101','ECE');

1 row created.

Add data to all the attributes in the different order:add a record in


student table
SQL> insert into student(roll_no,branch,name) values('102','ECE','vinay');

1 row created.

Add data to few attributes:add a record to student table (only to


roll_no and name)
SQL> insert into student(roll_no,name) values(103,'mayank');

1 row created.
Adding multiple rows using one query-
SQL> insert into student values('&name','&roll','&branch');

Enter value for name: smith

Enter value for roll: 104

Enter value for branch: ECE

old 1: insert into student values('&name','&roll','&branch')

new 1: insert into student values('smith','104','ECE')

1 row created.

SQL> /

Enter value for name: siya

Enter value for roll: 201

Enter value for branch: CSE

old 1: insert into student values('&name','&roll','&branch')

new 1: insert into student values('siya','201','CSE')

1 row created.

SQL> /

Enter value for name: amit

Enter value for roll: 202

Enter value for branch: CSE

old 1: insert into student values('&name','&roll','&branch')

new 1: insert into student values('amit','202','CSE')


1 row created.

SQL> /

Enter value for name: tripti

Enter value for roll: 203

Enter value for branch: CSE

old 1: insert into student values('&name','&roll','&branch')

new 1: insert into student values('tripti','203','CSE')

1 row created.

SQL> /

Enter value for name: tripti

Enter value for roll: 203

Enter value for branch: CSE

old 1: insert into student values('&name','&roll','&branch')

new 1: insert into student values('tripti','203','CSE')

1 row created.

Viewing data of a table-


All columns and all rows - to view all the details of all the students
from student table

SQL> select * from student;


NAME ROLL_NO BRANCH

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

ashish 101 ECE

vinay 102 ECE

mayank 103

smith 104 ECE

siya 201 CSE

amit 202 CSE

tripti 203 CSE

tripti 203 CSE

8 rows selected.

All columns and selected rows - to view all the details of all the
students in ECE branch from student table-
SQL> select * from student where branch='ECE';

NAME ROLL_NO BRANCH

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

ashish 101 ECE

vinay 102 ECE

smith 104 ECE

selected columns and all rows – to view roll_no and name of all the
students from student table-

SQL> select roll_no,name from student;


ROLL_NO NAME

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

101 ashish

102 vinay

103 mayank

104 smith

201 siya

202 amit

203 tripti

203 tripti

8 rows selected.

Selected columns and selected rows – to view roll number and


name of all the students in ECE branch from student table
SQL> select roll_no,name from student where branch='ECE';

ROLL_NO NAME

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

101 ashish

102 vinay

104 smith

Eliminating duplicate rows when using select


statement:
To view the distinct branch names from student table
SQL> select distinct(branch) from student;
BRANCH

----------

ECE

CSE

To view the data in sorted form-


Sorted in ascending order – to view the details of all the students
order by name in ascending order:
SQL> select * from student order by name;

NAME ROLL_NO BRANCH

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

amit 202 CSE

ashish 101 ECE

mayank 103

vinay 102 ECE

siya 201 CSE

smith 104 ECE

tripti 203 CSE

tripti 203 CSE

8 rows selected.

OR

SQL> select * from student order by name asc;


NAME ROLL_NO BRANCH

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

amit 202 CSE

ashish 101 ECE

mayank 103

vinay 102 ECE

siya 201 CSE

smith 104 ECE

tripti 203 CSE

tripti 203 CSE

8 rows selected.

Sorted in descending order – to view the details of all the students


order by name in ascending order:
SQL> select * from student order by name desc;

NAME ROLL_NO BRANCH

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

tripti 203 CSE

tripti 203 CSE

smith 104 ECE

siya 201 CSE

vinay 102 ECE

mayank 103

ashish 101 ECE

amit 202 CSE

8 rows selected.
Creating table from an existing table:
SQL> create table student1(sname,sroll,sbranch) as select name,roll_no,branch
from student;

Table created.

Adding data into a table from an existing table:


SQL> create table student2(s_name varchar2(10),s_roll number(3),s_branch
varchar2(10));

Table created.

Query to add data from existing table:


SQL> insert into student2 select name,roll_no,branch from student;

8 rows created.
Experiment No – 2
Deleting records or rows from a table
Deleting few rows:

Status before deleting

SQL> select * from student2;

S_NAME S_ROLL S_BRANCH

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

ashish 101 ECE

vinay 102 ECE

mayank 103

smith 104 ECE

siya 201 CSE

amit 202 CSE

tripti 203 CSE

tripti 203 CSE

8 rows selected.

Delete all the details of roll number 101 from student2 table:
SQL> delete from student2 where s_roll=101;

1 row deleted.
Status after deletion
SQL> select * from student2;

S_NAME S_ROLL S_BRANCH

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

vinay 102 ECE

mayank 103

smith 104 ECE

siya 201 CSE

amit 202 CSE

tripti 203 CSE

tripti 203 CSE

7 rows selected.

Deleting all the rows:

Status before deletion


SQL> select * from student2;

S_NAME S_ROLL S_BRANCH

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

vinay 102 ECE

mayank 103

smith 104 ECE

siya 201 CSE

amit 202 CSE

tripti 203 CSE

tripti 203 CSE

7 rows selected.
To delete all the records of student2 table
SQL> delete from student2;

7 rows deleted.

Status after deletion


SQL> select * from student2;

no rows selected

updating the contents of a table:


updation using where clause:update the name of a student from
Riya to Siya in student table:

status of student table before updation:


SQL> select * from student;

NAME ROLL_NO BRANCH

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

ashish 101 ECE

vinay 102 ECE

mayank 103

smith 104 ECE

siya 201 CSE

amit 202 CSE

tripti 203 CSE

tripti 203 CSE

8 rows selected.

Update query
SQL> update student set name ='riya'where name ='siya';
1 row updated.

Status of student table after updation


SQL> select * from student;

NAME ROLL_NO BRANCH

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

ashish 101 ECE

vinay 102 ECE

mayank 103

smith 104 ECE

riya 201 CSE

amit 202 CSE

tripti 203 CSE

tripti 203 CSE

8 rows selected.

Update without where clause: add 100 to roll number of all the
studemts in student table:
SQL> update student set roll_no=roll_no+100;

8 rows updated.

Status of student table after updation:


SQL> select * from student;

NAME ROLL_NO BRANCH

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

ashish 201 ECE

vinay 202 ECE

mayank 203

smith 204 ECE


riya 301 CSE

amit 302 CSE

tripti 303 CSE

tripti 303 CSE

8 rows selected.

Modifying structure of a table


Adding new columns to a table: add contact (numeric size-10) to
student table
SQL> alter table student add (contact number(10));

Table altered.

Status of student table after adding new column:


SQL> select * from student;

NAME ROLL_NO BRANCH CONTACT

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

ashish 201 ECE

vinay 202 ECE

mayank 203

smith 204 ECE

riya 301 CSE

amit 302 CSE

tripti 303 CSE

tripti 303 CSE

8 rows selected.
Deleting existence column of a table : delete the contact
attribute from student table
SQL> alter table student drop column contact;

Table altered.

Status of student table after droping contact attribute:


SQL> select * from student;

NAME ROLL_NO BRANCH

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

ashish 201 ECE

vinay 202 ECE

mayank 203

smith 204 ECE

riya 301 CSE

amit 302 CSE

tripti 303 CSE

tripti 303 CSE

8 rows selected.
Modifying the column datatype or size: change the branch attribute
datatype from varchar2 to char and size from 10 to 12
SQL> alter table student modify (branch char(12));

Table altered.

Renaming a table
Change the name of the table student1 to s1:
SQL> rename student1 to s1;

Table renamed.

Truncating a table:
Status of s1 before truncate command

SQL> select * from s1;

SNAME SROLL SBRANCH

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

ashish 101 ECE

vinay 102 ECE

mayank 103

smith 104 ECE

siya 201 CSE

amit 202 CSE

tripti 203 CSE


tripti 203 CSE

8 rows selected.

Query:
SQL> truncate table s1;

Table truncated.

Status of s1 after truncate command


SQL> select * from s1;

no rows selected

destroying table: destroy s1 table:


SQL> drop table s1;

Table dropped.

Finding out the table/s created by a user


TNAME TABTYPE CLUSTERID

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

STUDENT TABLE

STUDENT2 TABLE

SQLPLUS_PRODUCT_PROFILE TABLE

PRODUCT_PRIVS VIEW

PRODUCT_USER_PROFILE SYNONYM

HELP TABLE
6 rows selected.

Displaying the table structure:


SQL> desc student;

Name Null? Type

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

NAME VARCHAR2(10)

ROLL_NO NUMBER(3)

BRANCH CHAR(12)

OR
SQL> describe student;

Name Null? Type

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

NAME VARCHAR2(10)

ROLL_NO NUMBER(3)

BRANCH CHAR(12)
Experiment no-3
Primary key
Primary key declaration at column level
SQL> create table student(roll_no number(3)primary key,name varchar2(10),branch
varchar2(10));

Table created.

Primary key declaration at table level


SQL> create table student1(roll_no number(3),name varchar2(10),branch varchar2(1

0),primary key (roll_no));

Table created.

Foreign key
Foreign key declaration at column level
SQL> create table result1(roll_no number(3)references student(roll_no),maths num

ber(3),science number(3),english number (3));

Table created.

Foreign key declaration at the table level


SQL> create table result(roll_no number(3),maths number(3),science number(3),eng

lish number(3),foreign key(roll_no)references student1(roll_no));

Table created.

Unique constraint
Unique constraint declaration at column level
SQL> create table emp(e_id varchar2(4)primary key,e_name varchar2(10),e_contact

number(10) unique);

Table created.
Unique constraint declaration at table level
SQL> create table emp1(e_id varchar2(4) primary key,e_name varchar2(10),e_contact
number(10),unique(e_contact));

Table created.

Not null constraint(can only be declared at column level)


SQL> create table emp2(e_id varchar2(4) primary key,e_name varchar2(10)not
null,e_contact number(10));

Table created.

Check constraint
Check constraint declaration at column level

SQL> create table emp3(e_id varchar2(4)primary key check(e_id like 'E%'),e_name


varchar2(10)not null check(e_name=upper(e_name)),e_deptt varchar2(3) check(e_deptt
in('ECE','CSE','EEE','ECE','MAE')));

Table created.

Check constraint declaration at table level


SQL> create table emp4(e_id varchar2(4) primary key,e_name varchar2(10) not
null,e_deptt varchar2(3),check(e_id like 'E
%'),check(e_name=upper(e_name)),check(e_deptt in('ECE','CSE','EEE','ECE','MAE')));

Table created.

Naming the constraints during table level creation


Assigning names to primary key,not null,unique,check at column
level
SQL> create table students(roll number(3) constraint pk primary key,name varchar2(10)
constraint ck check(name=initcap(name)),branch varchar2(10) constraint nn not
null,contact number(10)constraint u unique);

Table created.

Assigning names to primary key,unique,check at table level


SQL> create table students1(roll number(3),name varchar2(10),branch
varchar2(10),contact number(10),constraint pk1 primary key(roll),constraint ck1 check
(name=initcap(name)) , constraint u1 unique(contact));

Table created.

Assigning name to foreign key at column level


SQL> create table result (roll number (3) constraint fk references student(roll_no),math
number(3),science number(3),english number(3));

Table created.

Assigning name to foreign key at table level


SQL> create table result1(roll number(3),maths number(3),science number(3),english
number(3),constraint fk1 foreign key(roll)references student(roll_no));

Table created.

Setting constraints using alter command


First of all tables student,student1,result,result1 are created as
follows
SQL> create table student(roll number(3),name varchar2(10),branch varchar2(10),contact
number(10));

Table created.
SQL> create table student1(roll number(3),name varchar2(10),branch
varchar2(10),contact number(10));

Table created.

Query to create result table:


SQL> create table result(roll number(3),maths number(3),science number(3),english
number(3));

Table created.

SQL> create table result1(roll number(3),maths number(3),science number(3),english


number(3));

Table created.

Primary key,unique and check constraints


SQL> alter table student add (primary
key(roll),check(name=upper(name)),unique(contact));

Table altered.

Adding constraints with name


SQL> alter table student1 add(constraint pk2 primary key (roll),constraint ck2
check(name=upper(name)),constraint u2 unique(contact));

Table altered.
Not null
Adding null constraint without name
SQL> alter table student modify(branch not null);

Table altered.

Adding null constraint with name


SQL> alter table student1 modify(branch constraint nn1 not null);

Table altered.

Foreign key
Adding foreign key constraint without name
SQL> alter table result add foreign key(roll) references student(roll);

Table altered.

Adding foreign key constraint with name


SQL> alter table result1 add constraint fk2 foreign key(roll) references student(roll);

Table altered.

Droping constraints
Foreign key

Dropping foreign key using constraint name


SQL> alter table result1 drop constraint fk2;

Table altered
Experiment no-4
Computation done on table data:
Created a table employee and add data to it as follows:
SQL> create table employee(e_name varchar2(10),e_id varchar2(4) primary key,e_deptt
varchar2(3),e_salary number(10));

Table created

SQL> insert into employee values('&e_name','&e_id','&e_deptt','&salary');

Enter value for e_name: amar

Enter value for e_id: E101

Enter value for e_deptt: ECE

Enter value for salary: 20000

old 1: insert into employee values('&e_name','&e_id','&e_deptt','&salary')

new 1: insert into employee values('amar','E101','ECE','20000')

1 row created.

SQL> /

Enter value for e_name: ashish

Enter value for e_id: E102

Enter value for e_deptt: ECE

Enter value for salary: 30000

old 1: insert into employee values('&e_name','&e_id','&e_deptt','&salary')

new 1: insert into employee values('ashish','E102','ECE','30000')


1 row created.

SQL> /

Enter value for e_name: sonali

Enter value for e_id: E103

Enter value for e_deptt: ECE

Enter value for salary: 25000

old 1: insert into employee values('&e_name','&e_id','&e_deptt','&salary')

new 1: insert into employee values('sonali','E103','ECE','25000')

1 row created.

SQL> /

Enter value for e_name: dinesh

Enter value for e_id: E104

Enter value for e_deptt: ECE

Enter value for salary: 28000

old 1: insert into employee values('&e_name','&e_id','&e_deptt','&salary')

new 1: insert into employee values('dinesh','E104','ECE','28000')

1 row created.

SQL> /

Enter value for e_name: neha

Enter value for e_id: E105

Enter value for e_deptt: ECE


Enter value for salary: 45000

old 1: insert into employee values('&e_name','&e_id','&e_deptt','&salary')

new 1: insert into employee values('neha','E105','ECE','45000')

1 row created.

SQL> /

Enter value for e_name: kanika

Enter value for e_id: E106

Enter value for e_deptt: CSE

Enter value for salary: 30000

old 1: insert into employee values('&e_name','&e_id','&e_deptt','&salary')

new 1: insert into employee values('kanika','E106','CSE','30000')

1 row created.

SQL> /

Enter value for e_name: mohit

Enter value for e_id: E107

Enter value for e_deptt: CSE

Enter value for salary: 19000

old 1: insert into employee values('&e_name','&e_id','&e_deptt','&salary')

new 1: insert into employee values('mohit','E107','CSE','19000')

1 row created.
SQL> /

Enter value for e_name: smith

Enter value for e_id: E108

Enter value for e_deptt: CSE

Enter value for salary: 45000

old 1: insert into employee values('&e_name','&e_id','&e_deptt','&salary')

new 1: insert into employee values('smith','E108','CSE','45000')

1 row created.

SQL> /

Enter value for e_name: mayank

Enter value for e_id: E109

Enter value for e_deptt: CSE

Enter value for salary: 20000

old 1: insert into employee values('&e_name','&e_id','&e_deptt','&salary')

new 1: insert into employee values('mayank','E109','CSE','20000')

1 row created.

SQL> /

Enter value for e_name: ramesh

Enter value for e_id: E110

Enter value for e_deptt: CSE

Enter value for salary: 33000

old 1: insert into employee values('&e_name','&e_id','&e_deptt','&salary')


new 1: insert into employee values('ramesh','E110','CSE','33000')

1 row created.

SQL> select * from employee;

E_NAME E_ID E_D E_SALARY

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

amar E101 ECE 20000

ashish E102 ECE 30000

sonali E103 ECE 25000

dinesh E104 ECE 28000

neha E105 ECE 45000

kanika E106 CSE 30000

mohit E107 CSE 19000

smith E108 CSE 45000

mayank E109 CSE 20000

ramesh E110 CSE 33000

10 rows selected.

Arithmatic operators:
To find annual income of all the employees with employee name
from employee table
SQL> select e_name,e_salary*12 "annual" from employee;
E_NAME annual

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

amar 240000

ashish 360000

sonali 300000

dinesh 336000

neha 540000

kanika 360000

mohit 228000

smith 540000

mayank 240000

ramesh 396000

10 rows selected.

OR
SQL> select e_name,e_salary*12 as annual from employee;

E_NAME annual

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

amar 240000

ashish 360000

sonali 300000

dinesh 336000

neha 540000

kanika 360000

mohit 228000

smith 540000
mayank 240000

ramesh 396000

10 rows selected.

Logical operators
To display the details of employee having salary ranging between
20000 to 35000
SQL> select * from employee where e_salary>=20000 and e_salary<=35000;

E_NAME E_ID E_D E_SALARY

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

amar E101 ECE 20000

ashish E102 ECE 30000

sonali E103 ECE 25000

dinesh E104 ECE 28000

kanika E106 CSE 30000

mayank E109 CSE 20000

ramesh E110 CSE 33000

7 rows selected.

To display details of ECE department employees having salary


greater than 25000
SQL> select * from employee where e_salary>25000 and e_deptt='ECE';
E_NAME E_ID E_D E_SALARY

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

ashish E102 ECE 30000

dinesh E104 ECE 28000

neha E105 ECE 45000

To display details of employees having salary >=30000


department=CSE
SQL> select * from employee where e_salary>=30000 or e_deptt='CSE';

E_NAME E_ID E_D E_SALARY

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

ashish E102 ECE 30000

neha E105 ECE 45000

kanika E106 CSE 30000

mohit E107 CSE 19000

smith E108 CSE 45000

mayank E109 CSE 20000

ramesh E110 CSE 33000

7 rows selected.

To display details of employees where salary is not ranging


between 20000 to 35000
SQL> select * from employee where NOT(e_salary>=2000 and e_salary<=35000);
E_NAME E_ID E_D E_SALARY

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

neha E105 ECE 45000

smith E108 CSE 45000

Pattern matching
To find details of all the employee where name begins with A
character
SQL> select * from employee where e_name like 'a%';

E_NAME E_ID E_D E_SALARY

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

amar E101 ECE 20000

ashish E102 ECE 30000

To find details of all the employees where second character of the


name is o
SQL> select * from employee where e_name like '_o%';

E_NAME E_ID E_D E_SALARY

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

sonali E103 ECE 25000

mohit E107 CSE 19000

mayank E109 CSE 20000

To find the details of all the employees where third character of the
name is h:
SQL> select * from employee where e_name like '__h%';
E_NAME E_ID E_D E_SALARY

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

neha E105 ECE 45000

mohit E107 CSE 19000

mayank E109 CSE 20000

To find details of all the employees where name ends with t


character:
SQL> select * from employee where e_name like '%t';

E_NAME E_ID E_D E_SALARY

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

mohit E107 CSE 19000

To find detailos of all the employees where second character of the


name is o or n:
SQL> select * from employee where e_name like '_o%' or e_name like '_n%';

E_NAME E_ID E_D E_SALARY

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

ashish E102 ECE 30000

sonali E103 ECE 25000

mohit E107 CSE 19000

mayank E109 CSE 20000

To find details of all the employees where second character of the


name is o and name is of total four characters:
SQL> select * from employee where e_name like '_o__';
E_NAME E_ID E_D E_SALARY

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

mayank E109 CSE 20000

in and not in
To find na,e and salary of employees with enployee
id=E101,E103,E105,E106(using in):
SQL> select e_name,e_salary from employee where e_id in ('E101','E103','E105','E

106');

E_NAME E_SALARY

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

amar 20000

sonali 25000

neha 45000

kanika 30000

To find id and salary of employees named ashish,smith,ramsh(using


in):
SQL> select e_id,e_salary from employee where e_name in('ashish','smith','ramesh');

E_ID E_SALARY

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

E102 30000

E108 45000

E110 33000

To find id and salary of employees other than ashish,


smith,ramesh(using not in):
SQL> select e_id,e_salary from employee where e_name not in ('ashish','smith','r
amesh');

E_ID E_SALARY

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

E101 20000

E103 25000

E104 28000

E105 45000

E106 30000

E107 19000

E109 20000

7 rows selected.

Aggregate functions:
AVG (averege)
To find average of salary of all employees in employee table:
SQL> select avg(e_salary) from employee;

AVG(E_SALARY)

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

29500

SUM (Sumation)

To find sum of salary of all employees in employee table:


SQL> select sum(e_salary) from employee;
SUM(E_SALARY)

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

295000

To display maximum salary from employee table:


SQL> select max(e_salary)from employee;

MAX(E_SALARY)

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

45000

MIN (Minimum)

To display minimum salary from employee table:


SQL> select min(e_salary) from employee;

MIN(E_SALARY)

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

19000

COUNT

To find the number of rows in table employee


SQL> select count(*) from employee;

COUNT(*)

----------

10

To find the number of employees in table employee having salary


greater than 25000
SQL> select count(*) from employee where e_salary>25000;

COUNT(*)

----------

Oracle functions using dual table:

ABS(n):returns absolute of n
SQL> SELECT ABS(-15)"Absolute"FROM DUAL;

Absolute

----------

15

POWER(m,n):returns m raised to the nth power


SQL> SELECT POWER(3,2)"Raised"FROM DUAL;

Raised

----------

ROUND(n,m):Returns n,rounded to m places


SQL> SELECT ROUND(15.19,1)"Round"FROM DUAL;

Round

----------
15.2

SQL> select ROUND(10/3,1)"Round"FROM DUAL;

Round

----------

3.3

SORT(n):Returns square root of n


SQL> SELECT SQRT(25)"Square Root"FROM DUAL;

Square Root

-----------

SQL> SELECT SQRT(3)"Square root"FROM DUAL;

Square root

-----------

1.73205081

EXP(n): Returns e raised to nth power(where e=2.71828183)


SQL> SELECT EXP(5)"Exponent" FROM DUAL;

Exponent

----------

148.413159

GREATEST(expr1,exp2,expr3,.....expr n): To find the greatest of


given expressions or numbers.
SQL> SELECT GREATEST(4,5,17)"Num" FROM DUAL;
Num

----------

17

SQL> SELECT GREATEST(10/4,10+5,20*17)"Num" FROM DUAL;

Num

----------

340

LEAST(exp1,exp2,exp3.....exp n): To find the smallest of given


expressions or numbers
SQL> SELECT LEAST(10/4,10+5,20*17)"Num"FROM DUAL;

Num

----------

2.5

SQL> SELECT LEAST(4,5,17)"Num" FROM DUAL;

Num

----------

MOD(m,n):Returns remainder of m/n


SQL> SELECT MOD(15,7)"Mod1",MOD(15.7,7)"Mod2" FROM DUAL;

Mod1 Mod2

---------- ----------
1 1.7

FLOOR(n): Returns the largest integer value that is equal tp less


than a number
SQL> SELECT FLOOR(24.8)"Flrl",FLOOR(13.15)"FLr2"FROM DUAL;

Flrl FLr2

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

24 13

CEIL(n): Returns the smallest integer value that is greater than


or equal to a number
SQL> SELECT CEIL(24.8)"Ceil",CEIL(13.15)"Ceil" FROM DUAL;

Ceil Ceil

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

25 14

LOWER(char):Returns char,with all the letters in lowercase


SQL> SELECT LOWER('DBMS lAB')"Lower"FROM DUAL;

Lower

--------

dbms lab

INECECAP(char): Returns char,with the first letter of each word


in uppercase
SQL> SELECT INECECAP('DBMS LAB')"initcap"FROM DUAL;

initcap
--------

Dbms Lab

UPPER(char): Returns char,with all the letters in uppercase


SQL> SELECT upper('dbms lab')"upper"FROM DUAL;

upper

--------

DBMS LAB

SUBSTR(string,start_posiyion,length); Returns a portion of


characters,beginning at character m,and going upto character n
SQL> SELECT SUBSTR('this is a test',6,2)"Extracted"FROM DUAL;

Ex

--

is

SQL> SELECT SUBSTR('this is a test',6,5)"Extracted" FROM DUAL;

Extra

-----

is a

SQL> SELECT SUBSTR('this is a test',6,7)"Extracted"FROM DUAL;

Extract

-------

is a te
ASCII(single-character):Returns ASCII value of a single character
SQL> SELECT ASCII('A')"ASCII"from dual;

ASCII

----------

65

SQL> SELECT ASCII('a')"ASCII"from dual;

ASCII

----------

97

SQL> SELECT ASCII('a')"ASCII_a",ASCII('z')"ASCII_z"from dual;

ASCII_a ASCII_z

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

97 122

LENGTH(word): Returns the length of a word


SQL> SELECT LENGTH('HELLO WORLD')"length"FROM DUAL;

length

----------

11

LTRIM(char,set): Removes from left of char with initial


characters removed upto the first character not in set
SQL> SELECT LTRIM('NISHA','N')"Length"FROM DUAL;

Leng

----

ISHA

SQL> SELECT LTRIM('NISHA','NI')"Length"FROM DUAL;


Len

---

SHA

SQL> SELECT LTRIM('NISHA','NIS')"Length"FROM DUAL;

Le

--

HA

SQL> SELECT LTRIM('NISHA','NISH')"Length"FROM DUAL;

SQL> SELECT LTRIM('NISHA','NISHA')"Length"FROM DUAL;

RTRIM(char,set):Returns char,with final characters removed


after the last character not in set
SQL> SELECT RTRIM('NISHA','NISHA')"Length"FROM DUAL;

SQL> SELECT RTRIM('NISHA','ISHA')"Length"FROM DUAL;

-
N

SQL> SELECT RTRIM('NISHA','SHA')"Length"FROM DUAL;

Le

--

NI

SQL> SELECT RTRIM('NISHA','HA')"Length"FROM DUAL;

Len

---

NIS

SQL> SELECT RTRIM('NISHA','A')"Length"FROM DUAL;

Leng

----

NISH

You might also like