Professional Documents
Culture Documents
Name
Father name
Roll No
Semester 1 st
Class MSC(IT)
Subject Database system
Submitted To Mam Nosheen
Ashraf
Submitted by
Government College
Women University Faisalabad
Lab 1
DML (DATA MANIPULATION LANGUAGE ) QUERIES.
1- SQL> Select * from cat;
TABLE_NAME TABLE_TYPE
------------------------------ -----------
DEPT TABLE
EMP TABLE
BONUS TABLE
SALGRADE TABLE
DEPTNO
----------
20
30
30
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
----------
20
30
30
DEPTNO
----------
10
20
10
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
----------
30
20
30
DEPTNO
----------
20
10
14 rows selected.
3- SQL> Describe Emp;
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
14 rows selected.
JOB
---------
CLERK
SALESMAN
SALESMAN
MANAGER
SALESMAN
MANAGER
MANAGER
ANALYST
PRESIDENT
SALESMAN
CLERK
JOB
---------
CLERK
ANALYST
CLERK
14 rows selected.
JOB
---------
CLERK
SALESMAN
PRESIDENT
MANAGER
ANALYST
EMPNO JOB
---------- ----------
7902 FORD
EMPNO JOB
---------- ----------
7902 FORD
no rows selected
Operators in SQL
Different types of operators in SQL are as follows:
1- Comparison Operator
A comparison (or relational) operator is a mathematical symbol which is used to compare two
values. Comparison operators are used in conditions that compares one expression with
another. The result of a comparison can be true or false.
2- Between Operator
The between operator selects values within a given range. The values can be numbers, text, or
dates. Between operator is inclusive: begin and end values are included.
SQL> select empno, ename, sal from emp where sal between 1000 and 1500;
3- IN Operator
The IN operator is used to test for values in a specified list. It can be used with any data type.
SQL> select empno, job from emp where job in ('CLERK', 'MANAGER');
EMPNO JOB
---------- ---------
7369 CLERK
7566 MANAGER
7698 MANAGER
7782 MANAGER
7876 CLERK
7900 CLERK
7934 CLERK
7 rows selected.
Logical Operator
There are three logical operators are as follows:
1- NOT Operator
The SQL NOT condition (sometimes called the NOT Operator) is used to negate a condition in
the WHERE clause of a SELECT, INSERT, UPDATE, or DELETE statement.
Query:
SQL> select empno, job from emp where job NOT in ('CLERK', 'MANAGER');
EMPNO JOB
---------- ---------
7499 SALESMAN
7521 SALESMAN
7654 SALESMAN
7788 ANALYST
7839 PRESIDENT
7844 SALESMAN
7902 ANALYST
7 rows selected.
2- AND Operator
The AND operator displays a row if ALL condition listed are true.
Query
SQL> select EMPNO, ename, job, sal from emp where sal<=1500 AND job = 'CLERK';
3- OR Operator
The OR operator displays a row if ANY of the conditions listed are true.
Query
SQL> select EMPNO, ename, job, sal from emp where sal<=1500 OR job = 'MANAGER';
10 rows selected.
LIKE Operator
The LIKE operator is used to specify a search for a pattern in a column. The character pattern
matching operation may be referred to as “Wild Card” search. Two symbols can be used to
construct the search string.
Query
SQL> select empno, ename, job from emp where ename Like 'A%';
SQL> select empno, ename, job from emp where ename like '%A%';
Operator Precedence
Operator precedence describes the order in which operations are performed when an
expression is evaluated. Operations with a higher precedence are performed before those with
a lower precedence. Parentheses has the highest precedence and OR has the lowest.
14 rows selected.
1- Descending Order
SQL> select empno, ename, deptno from emp order by deptno, sal DESC;
7839 KING 10
7782 CLARK 10
7934 MILLER 10
7788 SCOTT 20
7902 FORD 20
7566 JONES 20
7876 ADAMS 20
7369 SMITH 20
7698 BLAKE 30
7499 ALLEN 30
7844 TURNER 30
7654 MARTIN 30
7521 WARD 30
7900 JAMES 30
14 rows selected.
2- Ascending Order
SQL> select empno, ename, deptno from emp order by deptno, sal;
7934 MILLER 10
7782 CLARK 10
7839 KING 10
7369 SMITH 20
7876 ADAMS 20
7566 JONES 20
7788 SCOTT 20
7902 FORD 20
7900 JAMES 30
7654 MARTIN 30
7521 WARD 30
7844 TURNER 30
7499 ALLEN 30
7698 BLAKE 30
14 rows selected.
SQL> select empno, sal, job, LOWER(ename) from emp where ename = 'MILLER';
EMPNO SAL JOB LOWER(ENAM
SQL> select empno, job, sal, INITCAP(ename) from emp where LOWER(ename) ='blake';
SUBSTR
Length
InSTR