Experiment No 1 .1
Experiment No 1 .1
SYSTEM LAB
Enter password:
Connected.
Table created.
1 row created.
1 row created.
1 row created.
Adding multiple rows using one query-
SQL> insert into student values('&name','&roll','&branch');
1 row created.
SQL> /
1 row created.
SQL> /
SQL> /
1 row created.
SQL> /
1 row created.
mayank 103
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';
selected columns and all rows – to view roll_no and name of all the
students from student table-
---------- ----------
101 ashish
102 vinay
103 mayank
104 smith
201 siya
202 amit
203 tripti
203 tripti
8 rows selected.
ROLL_NO NAME
---------- ----------
101 ashish
102 vinay
104 smith
----------
ECE
CSE
mayank 103
8 rows selected.
OR
mayank 103
8 rows selected.
mayank 103
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.
Table created.
8 rows created.
Experiment No – 2
Deleting records or rows from a table
Deleting few rows:
mayank 103
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;
mayank 103
7 rows selected.
mayank 103
7 rows selected.
To delete all the records of student2 table
SQL> delete from student2;
7 rows deleted.
no rows selected
mayank 103
8 rows selected.
Update query
SQL> update student set name ='riya'where name ='siya';
1 row updated.
mayank 103
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.
mayank 203
8 rows selected.
Table altered.
mayank 203
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.
mayank 203
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
mayank 103
8 rows selected.
Query:
SQL> truncate table s1;
Table truncated.
no rows selected
Table dropped.
STUDENT TABLE
STUDENT2 TABLE
SQLPLUS_PRODUCT_PROFILE TABLE
PRODUCT_PRIVS VIEW
PRODUCT_USER_PROFILE SYNONYM
HELP TABLE
6 rows selected.
NAME VARCHAR2(10)
ROLL_NO NUMBER(3)
BRANCH CHAR(12)
OR
SQL> describe student;
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.
Table created.
Foreign key
Foreign key declaration at column level
SQL> create table result1(roll_no number(3)references student(roll_no),maths num
Table created.
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.
Table created.
Check constraint
Check constraint declaration at column level
Table created.
Table created.
Table created.
Table created.
Table created.
Table created.
Table created.
SQL> create table student1(roll number(3),name varchar2(10),branch
varchar2(10),contact number(10));
Table created.
Table created.
Table created.
Table altered.
Table altered.
Not null
Adding null constraint without name
SQL> alter table student modify(branch not null);
Table altered.
Table altered.
Foreign key
Adding foreign key constraint without name
SQL> alter table result add foreign key(roll) references student(roll);
Table altered.
Table altered.
Droping constraints
Foreign key
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
1 row created.
SQL> /
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
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;
7 rows selected.
7 rows selected.
Pattern matching
To find details of all the employee where name begins with A
character
SQL> select * from employee where e_name like 'a%';
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
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
E_ID E_SALARY
---- ----------
E102 30000
E108 45000
E110 33000
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)
-------------
295000
MAX(E_SALARY)
-------------
45000
MIN (Minimum)
MIN(E_SALARY)
-------------
19000
COUNT
COUNT(*)
----------
10
COUNT(*)
----------
ABS(n):returns absolute of n
SQL> SELECT ABS(-15)"Absolute"FROM DUAL;
Absolute
----------
15
Raised
----------
Round
----------
15.2
Round
----------
3.3
Square Root
-----------
Square root
-----------
1.73205081
Exponent
----------
148.413159
----------
17
Num
----------
340
Num
----------
2.5
Num
----------
Mod1 Mod2
---------- ----------
1 1.7
Flrl FLr2
---------- ----------
24 13
Ceil Ceil
---------- ----------
25 14
Lower
--------
dbms lab
initcap
--------
Dbms Lab
upper
--------
DBMS LAB
Ex
--
is
Extra
-----
is a
Extract
-------
is a te
ASCII(single-character):Returns ASCII value of a single character
SQL> SELECT ASCII('A')"ASCII"from dual;
ASCII
----------
65
ASCII
----------
97
ASCII_a ASCII_z
---------- ----------
97 122
length
----------
11
Leng
----
ISHA
---
SHA
Le
--
HA
-
N
Le
--
NI
Len
---
NIS
Leng
----
NISH