SlideShare a Scribd company logo
Ex. No: 2 Performing Insertion, Deletion, Modifying, Altering, Updating and Viewing records based
on conditions.
AIM
To study the various categories of DML commands.
DESCRIPTION
 THE ORACLE TABLE – DUAL - Dual is a small oracle table which consists of only one
row and one column and contains the value X in that column.
 INSERT - This command is used to insert values into the table.
 SELECT - This command is used to display the contents of the table or those of a particular
column.
 RENAME - This command renames the name of the table.
 ARITHMETIC OPERATIONS - Various operations such as addition, multiplication,
subtraction and division can be performed using the numbers available in the table.
 DISTINCT - This keyword is used along with select keyword to display unique values from
the specified column. It avoids duplicates during display.
 ORDER BY CLAUSE - The order by clause arranges the contents of the table in ascending
order (by default) or in descending order (if specified explicitly) according to the specified
column.
 CONCATENATION OPERATOR - This combines information from two or more columns in
a sentence according to the format specified.
LOGICAL OPERATORS
 AND : The oracle engine will process all rows in a table and displays the result only when all
of the conditions specified using the AND operator are specified.
 OR : The oracle engine will process all rows in a table and displays the result only when any
of the conditions specified using the OR operators are satisfied.
 NOT : The oracle engine will process all rows in a table and displays the result only when
none of the conditions specified using the NOT operator are specified.
 BETWEEN : In order to select data that is within a range of values, the between operator is
used. (AND should be included)
PATTERN MATCH
 LIKE PREDICATE :The use of like predicate is that it allows the comparison of one string
value with another string value, which is not identical. This is achieved by using wildcard
characters which are % and _. The purpose of % is that it matches any string and _ matches
any single character.
 IN AND NOT IN PREDICATE :The arithmetic operator = compares a single value to
another single value. In case a value needs to be compared to a list of values then the in
predicate is used. The not in predicate is the opposite of the in predicate. This will select all
the rows whose values do not match all of the values in the list.
AGGREGATE FUNCTIONS
 AVG(N): It returns average value of n ignoring null values.
 MIN (EXPR): It returns minimum value of the expression.
 COUNT (EXPR):It returns the number of rows where expression is not null.
 COUNT (*): It returns the number of rows in the table including the duplicates and those with
null values.
 MAX (EXPR): It returns maximum value
DATE FUNCTIONS
 SYSDATE : The sysdate is a pseudo column that contains the current date and time. It
requires no arguments when selected from the table dual and returns the current date.
GROUP BYCLAUSE
The group by clause is another section of the select statement. This optional class tells oracle to group
rows based on distinct values that exists for specified columns.
HAVING CLAUSE
The having clause can be used in conjunction with the group by clause. Having imposes a condition
on the group by clause, which further filters the groups created by the group by clause.
SQL> create table EMP (EMPNO number(4) not null,
2 ENAME varchar2(30) not null,
3 JOB varchar2(10),
4 MGR number(4),
5 HIREDATE date,
6 SAL number(7,2),
7 DEPTNO number(2));
Table created.
INSERT
Type 1
SQL> insert into emp (empno,ename,job,mgr,hiredate,sal,deptno)
2 values (3737,'Priya','Officer','7777','07-mar-2009',34000,07);
1 row created.
Type 2
SQL> insert into emp values (2323,'Anitha','Officer',5454,'09-jan-08',42000,09);
1 row created.
Type 3
SQL> insert into emp values ('&empno','&ename','&job','&mgr','&hiredate','&sal','&deptno');
Enter value for empno: 7575
Enter value for ename: Karthi
Enter value for job: Officer
Enter value for mgr: 3337
Enter value for hiredate: 07-jul-2007
Enter value for sal: 72000
Enter value for deptno: 07
old 1: insert into emp values ('&empno','&ename','&job','&mgr','&hiredate','&sal','&deptno')
new 1: insert into emp values (' 7575','Karthi','Officer','3337','07-jul-2007','72000',' 07')
1 row created.
SQL> insert into emp values (5352,'Retish','secretary','5555','09-jun-2009','20000',08);
1 row created.
SQL> insert into emp values (5332,'Rocky','assit','5555','08-jan-2008',13000,07);
1 row created.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO
--------- ------------------------------ ---------- ------------------ --------- -----------------------------
3737 Priya Officer 7777 07-MAR-09 34000 7
2323 Anitha Officer 5454 09-JAN-08 42000 9
7575 Karthi Officer 3337 07-JUL-07 72000 7
5352 Retish secretary 5555 09-JUN-09 20000 8
5332 Rocky assit 5555 08-JAN-08 13000 7
UPDATE
TUPLE UPDATE
SQL> update emp set
2 job = 'Manager',deptno=20, sal = sal +3000
3 where ename = 'Karthi';
1 row updated.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO
--------- ------------------------------ ---------- ------------------ --------- ------------------------------
3737 Priya Officer 7777 07-MAR-09 34000 7
2323 Anitha Officer 5454 09-JAN-08 42000 9
7575 Karthi Manager 3337 07-JUL-07 75000 20
5352 Retish secretary 5555 09-JUN-09 20000 8
5332 Rocky assit 5555 08-JAN-08 13000 7
ROWUPDATE
SQL> update emp set
2 sal = sal * 1.5
3 where deptno = 7;
2 rows updated.
SELECT
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO
--------- ------------------------------ ---------- ------------------ --------- -------------------------------
3737 Priya Officer 7777 07-MAR-09 51000 7
2323 Anitha Officer 5454 09-JAN-08 42000 9
7575 Karthi Manager 3337 07-JUL-07 75000 20
5352 Retish secretary 5555 09-JUN-09 20000 8
5332 Rocky assit 5555 08-JAN-08 19500 7
SQL> select ename from emp;
ENAME
------------------------------
Priya
Anitha
Karthi
Retish
Rocky
SQL> select sal * 2 from emp;
SAL*2
---------
102000
84000
150000
40000
39000
SQL> select ename,sal * 2 from emp;
ENAME SAL*2
------------------------------ ---------
Priya 102000
Anitha 84000
Karthi 150000
Retish 40000
Rocky 39000
SQL> select mgr from emp;
MGR
---------
7777
5454
3337
5555
5555
DISTINCT
SQL> select distinct mgr from emp;
MGR
------------
3337
5454
5555
7777
ORDER BY
SQL> select * from emp order by ename;
EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO
--------- ------------------------------ ---------- ------------------ --------- -----------------------------
2323 Anitha Officer 5454 09-JAN-08 42000 9
7575 Karthi Manager 3337 07-JUL-07 75000 20
3737 Priya Officer 7777 07-MAR-09 51000 7
5352 Retish secretary 5555 09-JUN-09 20000 8
5332 Rocky assit 5555 08-JAN-08 19500 7
SQL> select * from emp order by ename asc;
EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO
--------- ------------------------------ ---------- ------------------ --------- ------------------------------
2323 Anitha Officer 5454 09-JAN-08 42000 9
7575 Karthi Manager 3337 07-JUL-07 75000 20
3737 Priya Officer 7777 07-MAR-09 51000 7
5352 Retish secretary 5555 09-JUN-09 20000 8
5332 Rocky assit 5555 08-JAN-08 19500 7
SQL> select * from emp order by ename desc;
EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO
--------- ------------------------------ ---------- ------------------ --------- ------------------------------
5332 Rocky assit 5555 08-JAN-08 19500 7
5352 Retish secretary 5555 09-JUN-09 20000 8
3737 Priya Officer 7777 07-MAR-09 51000 7
7575 Karthi Manager 3337 07-JUL-07 75000 20
2323 Anitha Officer 5454 09-JAN-08 42000 9
OR
SQL> select ename from emp where ( mgr = 5555 or deptno = 07);
ENAME
------------------------------
Priya
Retish
Rocky
AND
SQL> select ename from emp where ( mgr = 5555 and deptno = 07);
ENAME
------------------------------
Rocky
IN
SQL> select ename,sal
2 from emp
3 where empno in
4 (2323,5555);
ENAME SAL
------------------------------ ---------
Anitha 42000
SQL> select ename,sal
2 from emp
3 where empno in
4 (2323,7575);
ENAME SAL
------------------------------ ---------
Anitha 42000
Karthi 75000
BETWEEN
SQL> select ename,sal
2 from emp
3 where salbetween 25000 and 50000;
ENAME SAL
------------------------------ ---------
Anitha 42000
TUPLE DELETION
SQL> delete from emp where empno=2323;
1 row deleted.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO
--------- ------------------------------ ---------- ------------------ --------- -------------------------------
3737 Priya Officer 7777 07-MAR-09 51000 7
7575 Karthi Manager 3337 07-JUL-07 75000 20
5352 Retish secretary 5555 09-JUN-09 20000 8
5332 Rocky assit 5555 08-JAN-08 19500 7
Another Example
Table Name studs
SNAME SID SAGE SAREA SDEPT SPOCKET
ashwin 101 19 anna nagar aeronautical 750
bhavesh 102 18 nungambakkam marine 500
pruthvik 103 20 anna nagar aerospace 250
charith 104 20 kilpauk mechanical 100
CONCATENATION OPERATOR
SQL> select sname || ' is a ' || sdept || ' engineer. ' AS "PROFESSION" from studs;
PROFESSION
ashwin is a aeronautical engineer.
bhavesh is a marine engineer.
pruthvik is a aerospace engineer.
charith is a mechanical engineer.
USING THE WHERE CLAUSE
SQL> select sname,sage from studs where sage<=19;
SNAME SAGE
ashwin 19
PATTERN MATCHING
SQL> select sname, sarea from studs where sarea like '%g%';
SNAME SAREA
ashwin anna nagar
bhavesh nungambakkam
pruthvik anna nagar
NOT IN PREDICATE
SQL> select sname, sid from studs where sid not in(102,104);
SNAME SID
ashwin 101
pruthvik 103
AGGREGATE FUNCTIONS
SQL> select avg( spocket ) result from studs;
RESULT
400
SQL> select min(spocket) result from studs;
RESULT
100
SQL> select count(spocket) result from studs;
RESULT
4
SQL> select count(*) result from studs;
RESULT
4
SQL> select count(spocket) result from studs where sarea='anna nagar';
RESULT
2
SQL> select max(spocket) result from studs;
RESULT
750
SQL> select sum(spocket) result from studs;
RESULT
1600
DATE FUNCTIONS
SQL> select sysdate from dual;
SYSDATE
16-JUL-08
GROUP BYCLAUSE
SQL> select sarea,sum(spocket) result from studs group by sarea;
SAREA RESULT
anna nagar 1000
nungambakkam 500
kilpauk 100
HAVING CLAUSE
SQL> select sarea,sum(spocket) result from studs group by sarea having spocket<600;
SAREA RESULT
nungambakkam 500
kilpauk 100
RESULT
The DML commands were executed and the output was verified.

More Related Content

PPT
PDF
SQL Functions and Operators
PPT
PPT
PPT
Single row functions
PPT
Oracle Sql & PLSQL Complete guide
PPT
SQL Functions and Operators
Single row functions
Oracle Sql & PLSQL Complete guide

What's hot (20)

PPT
PDF
MySQL partitions tutorial
PPT
PPTX
Structured query language constraints
DOCX
Trig
PPTX
Les05 Aggregating Data Using Group Function
PDF
Introduction to oracle functions
PDF
MERGE SQL Statement: Lesser Known Facets
PPTX
Oracle: Functions
DOCX
Functions oracle (pl/sql)
ODP
Mysqlppt
DOCX
Technical
PDF
Powerful Explain in MySQL 5.6
PPTX
MySql: Queries
MySQL partitions tutorial
Structured query language constraints
Trig
Les05 Aggregating Data Using Group Function
Introduction to oracle functions
MERGE SQL Statement: Lesser Known Facets
Oracle: Functions
Functions oracle (pl/sql)
Mysqlppt
Technical
Powerful Explain in MySQL 5.6
MySql: Queries
Ad

Similar to It6312 dbms lab-ex2 (20)

PDF
Database Systems - SQL - DDL Statements (Chapter 3/3)
DOC
ORACLE NOTES
PPT
Sql query [select, sub] 4
PPTX
SQL(NEW).pptx
PPTX
My SQL.pptx
PPT
Sql 2006
DOC
PPTX
Practical 03 (1).pptx
PPSX
Oracle Training in Kochi | Trivandrum |Thrissur
PDF
Structure query language - Data Query language for beginners.pdf
PDF
ILOUG 2019 - SQL features for Developers
PDF
sql language
PPTX
MYSQL-database basic queries for good understanding
PPT
SQL || overview and detailed information about Sql
PPTX
Data Manipulation Language.pptx
PPTX
Sangam 18 - Great Applications with Great SQL
PPT
Les02
PDF
KScope19 - SQL Features
PPTX
PPT
Sqlplus
Database Systems - SQL - DDL Statements (Chapter 3/3)
ORACLE NOTES
Sql query [select, sub] 4
SQL(NEW).pptx
My SQL.pptx
Sql 2006
Practical 03 (1).pptx
Oracle Training in Kochi | Trivandrum |Thrissur
Structure query language - Data Query language for beginners.pdf
ILOUG 2019 - SQL features for Developers
sql language
MYSQL-database basic queries for good understanding
SQL || overview and detailed information about Sql
Data Manipulation Language.pptx
Sangam 18 - Great Applications with Great SQL
Les02
KScope19 - SQL Features
Sqlplus
Ad

More from MNM Jain Engineering College (17)

DOCX
IT8602 MOBILE COMMUNICATION.docx
PDF
IT8602 Syllabus.pdf
DOC
PDF
DOC
Distributed Mutual exclusion algorithms
DOC
Task assignment approach
PPT
Process Management-Process Migration
DOC
Naming in Distributed System
PPT
Peer to Peer services and File systems
PPT
Remote method invocation
PPT
Remote Procedure Call
PPT
Engineering Ethics
PPT
Distributed System-Multicast & Indirect communication
DOCX
Expected questions in Artificial Intelligence
PDF
Qp mobile &amp; pervasive 2015
DOC
It6611 mobile application development laboratory l t p c0 0 3 2
PDF
Instruction formats-in-8086
IT8602 MOBILE COMMUNICATION.docx
IT8602 Syllabus.pdf
Distributed Mutual exclusion algorithms
Task assignment approach
Process Management-Process Migration
Naming in Distributed System
Peer to Peer services and File systems
Remote method invocation
Remote Procedure Call
Engineering Ethics
Distributed System-Multicast & Indirect communication
Expected questions in Artificial Intelligence
Qp mobile &amp; pervasive 2015
It6611 mobile application development laboratory l t p c0 0 3 2
Instruction formats-in-8086

Recently uploaded (20)

PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Current and future trends in Computer Vision.pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
737-MAX_SRG.pdf student reference guides
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Sustainable Sites - Green Building Construction
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPT
Total quality management ppt for engineering students
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
additive manufacturing of ss316l using mig welding
Current and future trends in Computer Vision.pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
737-MAX_SRG.pdf student reference guides
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
CYBER-CRIMES AND SECURITY A guide to understanding
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Foundation to blockchain - A guide to Blockchain Tech
Sustainable Sites - Green Building Construction
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Total quality management ppt for engineering students
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Categorization of Factors Affecting Classification Algorithms Selection
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf

It6312 dbms lab-ex2

  • 1. Ex. No: 2 Performing Insertion, Deletion, Modifying, Altering, Updating and Viewing records based on conditions. AIM To study the various categories of DML commands. DESCRIPTION  THE ORACLE TABLE – DUAL - Dual is a small oracle table which consists of only one row and one column and contains the value X in that column.  INSERT - This command is used to insert values into the table.  SELECT - This command is used to display the contents of the table or those of a particular column.  RENAME - This command renames the name of the table.  ARITHMETIC OPERATIONS - Various operations such as addition, multiplication, subtraction and division can be performed using the numbers available in the table.  DISTINCT - This keyword is used along with select keyword to display unique values from the specified column. It avoids duplicates during display.  ORDER BY CLAUSE - The order by clause arranges the contents of the table in ascending order (by default) or in descending order (if specified explicitly) according to the specified column.  CONCATENATION OPERATOR - This combines information from two or more columns in a sentence according to the format specified. LOGICAL OPERATORS  AND : The oracle engine will process all rows in a table and displays the result only when all of the conditions specified using the AND operator are specified.  OR : The oracle engine will process all rows in a table and displays the result only when any of the conditions specified using the OR operators are satisfied.  NOT : The oracle engine will process all rows in a table and displays the result only when none of the conditions specified using the NOT operator are specified.  BETWEEN : In order to select data that is within a range of values, the between operator is used. (AND should be included) PATTERN MATCH  LIKE PREDICATE :The use of like predicate is that it allows the comparison of one string value with another string value, which is not identical. This is achieved by using wildcard characters which are % and _. The purpose of % is that it matches any string and _ matches any single character.
  • 2.  IN AND NOT IN PREDICATE :The arithmetic operator = compares a single value to another single value. In case a value needs to be compared to a list of values then the in predicate is used. The not in predicate is the opposite of the in predicate. This will select all the rows whose values do not match all of the values in the list. AGGREGATE FUNCTIONS  AVG(N): It returns average value of n ignoring null values.  MIN (EXPR): It returns minimum value of the expression.  COUNT (EXPR):It returns the number of rows where expression is not null.  COUNT (*): It returns the number of rows in the table including the duplicates and those with null values.  MAX (EXPR): It returns maximum value DATE FUNCTIONS  SYSDATE : The sysdate is a pseudo column that contains the current date and time. It requires no arguments when selected from the table dual and returns the current date. GROUP BYCLAUSE The group by clause is another section of the select statement. This optional class tells oracle to group rows based on distinct values that exists for specified columns. HAVING CLAUSE The having clause can be used in conjunction with the group by clause. Having imposes a condition on the group by clause, which further filters the groups created by the group by clause.
  • 3. SQL> create table EMP (EMPNO number(4) not null, 2 ENAME varchar2(30) not null, 3 JOB varchar2(10), 4 MGR number(4), 5 HIREDATE date, 6 SAL number(7,2), 7 DEPTNO number(2)); Table created. INSERT Type 1 SQL> insert into emp (empno,ename,job,mgr,hiredate,sal,deptno) 2 values (3737,'Priya','Officer','7777','07-mar-2009',34000,07); 1 row created. Type 2 SQL> insert into emp values (2323,'Anitha','Officer',5454,'09-jan-08',42000,09); 1 row created. Type 3 SQL> insert into emp values ('&empno','&ename','&job','&mgr','&hiredate','&sal','&deptno'); Enter value for empno: 7575 Enter value for ename: Karthi Enter value for job: Officer Enter value for mgr: 3337 Enter value for hiredate: 07-jul-2007 Enter value for sal: 72000 Enter value for deptno: 07 old 1: insert into emp values ('&empno','&ename','&job','&mgr','&hiredate','&sal','&deptno') new 1: insert into emp values (' 7575','Karthi','Officer','3337','07-jul-2007','72000',' 07')
  • 4. 1 row created. SQL> insert into emp values (5352,'Retish','secretary','5555','09-jun-2009','20000',08); 1 row created. SQL> insert into emp values (5332,'Rocky','assit','5555','08-jan-2008',13000,07); 1 row created. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO --------- ------------------------------ ---------- ------------------ --------- ----------------------------- 3737 Priya Officer 7777 07-MAR-09 34000 7 2323 Anitha Officer 5454 09-JAN-08 42000 9 7575 Karthi Officer 3337 07-JUL-07 72000 7 5352 Retish secretary 5555 09-JUN-09 20000 8 5332 Rocky assit 5555 08-JAN-08 13000 7 UPDATE TUPLE UPDATE SQL> update emp set 2 job = 'Manager',deptno=20, sal = sal +3000 3 where ename = 'Karthi'; 1 row updated. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO --------- ------------------------------ ---------- ------------------ --------- ------------------------------ 3737 Priya Officer 7777 07-MAR-09 34000 7 2323 Anitha Officer 5454 09-JAN-08 42000 9 7575 Karthi Manager 3337 07-JUL-07 75000 20
  • 5. 5352 Retish secretary 5555 09-JUN-09 20000 8 5332 Rocky assit 5555 08-JAN-08 13000 7 ROWUPDATE SQL> update emp set 2 sal = sal * 1.5 3 where deptno = 7; 2 rows updated. SELECT SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO --------- ------------------------------ ---------- ------------------ --------- ------------------------------- 3737 Priya Officer 7777 07-MAR-09 51000 7 2323 Anitha Officer 5454 09-JAN-08 42000 9 7575 Karthi Manager 3337 07-JUL-07 75000 20 5352 Retish secretary 5555 09-JUN-09 20000 8 5332 Rocky assit 5555 08-JAN-08 19500 7 SQL> select ename from emp; ENAME ------------------------------ Priya Anitha Karthi Retish Rocky SQL> select sal * 2 from emp; SAL*2
  • 6. --------- 102000 84000 150000 40000 39000 SQL> select ename,sal * 2 from emp; ENAME SAL*2 ------------------------------ --------- Priya 102000 Anitha 84000 Karthi 150000 Retish 40000 Rocky 39000 SQL> select mgr from emp; MGR --------- 7777 5454 3337 5555 5555 DISTINCT SQL> select distinct mgr from emp; MGR
  • 7. ------------ 3337 5454 5555 7777 ORDER BY SQL> select * from emp order by ename; EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO --------- ------------------------------ ---------- ------------------ --------- ----------------------------- 2323 Anitha Officer 5454 09-JAN-08 42000 9 7575 Karthi Manager 3337 07-JUL-07 75000 20 3737 Priya Officer 7777 07-MAR-09 51000 7 5352 Retish secretary 5555 09-JUN-09 20000 8 5332 Rocky assit 5555 08-JAN-08 19500 7 SQL> select * from emp order by ename asc; EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO --------- ------------------------------ ---------- ------------------ --------- ------------------------------ 2323 Anitha Officer 5454 09-JAN-08 42000 9 7575 Karthi Manager 3337 07-JUL-07 75000 20 3737 Priya Officer 7777 07-MAR-09 51000 7 5352 Retish secretary 5555 09-JUN-09 20000 8 5332 Rocky assit 5555 08-JAN-08 19500 7 SQL> select * from emp order by ename desc; EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO --------- ------------------------------ ---------- ------------------ --------- ------------------------------ 5332 Rocky assit 5555 08-JAN-08 19500 7 5352 Retish secretary 5555 09-JUN-09 20000 8
  • 8. 3737 Priya Officer 7777 07-MAR-09 51000 7 7575 Karthi Manager 3337 07-JUL-07 75000 20 2323 Anitha Officer 5454 09-JAN-08 42000 9 OR SQL> select ename from emp where ( mgr = 5555 or deptno = 07); ENAME ------------------------------ Priya Retish Rocky AND SQL> select ename from emp where ( mgr = 5555 and deptno = 07); ENAME ------------------------------ Rocky IN SQL> select ename,sal 2 from emp 3 where empno in 4 (2323,5555); ENAME SAL ------------------------------ --------- Anitha 42000 SQL> select ename,sal 2 from emp 3 where empno in
  • 9. 4 (2323,7575); ENAME SAL ------------------------------ --------- Anitha 42000 Karthi 75000 BETWEEN SQL> select ename,sal 2 from emp 3 where salbetween 25000 and 50000; ENAME SAL ------------------------------ --------- Anitha 42000 TUPLE DELETION SQL> delete from emp where empno=2323; 1 row deleted. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO --------- ------------------------------ ---------- ------------------ --------- ------------------------------- 3737 Priya Officer 7777 07-MAR-09 51000 7 7575 Karthi Manager 3337 07-JUL-07 75000 20 5352 Retish secretary 5555 09-JUN-09 20000 8 5332 Rocky assit 5555 08-JAN-08 19500 7
  • 10. Another Example Table Name studs SNAME SID SAGE SAREA SDEPT SPOCKET ashwin 101 19 anna nagar aeronautical 750 bhavesh 102 18 nungambakkam marine 500 pruthvik 103 20 anna nagar aerospace 250 charith 104 20 kilpauk mechanical 100 CONCATENATION OPERATOR SQL> select sname || ' is a ' || sdept || ' engineer. ' AS "PROFESSION" from studs; PROFESSION ashwin is a aeronautical engineer. bhavesh is a marine engineer. pruthvik is a aerospace engineer. charith is a mechanical engineer. USING THE WHERE CLAUSE SQL> select sname,sage from studs where sage<=19; SNAME SAGE ashwin 19 PATTERN MATCHING SQL> select sname, sarea from studs where sarea like '%g%'; SNAME SAREA ashwin anna nagar bhavesh nungambakkam pruthvik anna nagar NOT IN PREDICATE SQL> select sname, sid from studs where sid not in(102,104);
  • 11. SNAME SID ashwin 101 pruthvik 103 AGGREGATE FUNCTIONS SQL> select avg( spocket ) result from studs; RESULT 400 SQL> select min(spocket) result from studs; RESULT 100 SQL> select count(spocket) result from studs; RESULT 4 SQL> select count(*) result from studs; RESULT 4 SQL> select count(spocket) result from studs where sarea='anna nagar'; RESULT 2 SQL> select max(spocket) result from studs; RESULT 750 SQL> select sum(spocket) result from studs; RESULT 1600 DATE FUNCTIONS SQL> select sysdate from dual;
  • 12. SYSDATE 16-JUL-08 GROUP BYCLAUSE SQL> select sarea,sum(spocket) result from studs group by sarea; SAREA RESULT anna nagar 1000 nungambakkam 500 kilpauk 100 HAVING CLAUSE SQL> select sarea,sum(spocket) result from studs group by sarea having spocket<600; SAREA RESULT nungambakkam 500 kilpauk 100 RESULT The DML commands were executed and the output was verified.