Professional Documents
Culture Documents
FALLSEM2021-22 SWE1004 ELA VL2021220100875 Reference Material I 02-Aug-2021 SQL STATEMENTS
FALLSEM2021-22 SWE1004 ELA VL2021220100875 Reference Material I 02-Aug-2021 SQL STATEMENTS
Ex. No : 01
Date :
SQL STATEMENTS
Basic Select Statement:
SYNTAX
EMP TABLE
14 rows selected.
4. Increment the salary of every employee by 300 and display their names and original
salary.
14 rows selected.
OPERATOR PRECEDENCE:
Note:
Parenthesis can form precedence.
5. a).Display the annual salary of all employees with additional sum of $100 added to annual
salary as Bonus to them.
14 rows selected.
5. b).Display the annual salary of all employees with additional sum of $100 added to
monthly salary as Bonus to them.
NULL is a special data type. It is an unavailable / unassigned /unknown /inapplicable value. A NULL
value is not a blank or space or a zero.
6. Display the annual salary with commission for employee named 'KING'.
7. Retrieve the name and salary of all employees and label it as NAME and SALARY.
NAME SALARY
---------- ----------
JAMES 950
FORD 3000
MILLER 1300
14 rows selected.
Concatenation Operator( || ):
SHASHIKIRAN V., ASSISTANT PROFESSOR (SENIOR), SITE, VIT VELLORE.
SQL Statements
EMPLOYEES
-------------------
JAMESCLERK
FORDANALYST
MILLERCLERK
14 rows selected.
9 rows selected.
SYNTAX
11. Retrieve the employee from emp table whose job is clerk.
NOTE:
Character strings and dates used in the WHERE clause are enclosed in the single quotation marks.
Character literals are case sensitive and dates are not.
12. Retrieve the job and deptno of the employee whose name is James.
Comparison Operator:
All the above operators can be used in the expression specified in the WHERE clause.
OPERATOR DESCRIPTION
BETWEEN…AND Between two values inclusive
IN Match any of a list values
LIKE Match a character pattern
IS NULL Is a NULL value
14. Display the names of the employee whose salary between 1000 and 1500.
SQL> select ename,sal from emp where sal between 1000 and 1500;
ENAME SAL
---------- ----------
WARD 1250
MARTIN 1250
TURNER 1500
ADAMS 1100
MILLER 1300
15. Display the names of the employees Born between 01-JAN-1980 and 01-JAN-
1982.Assume different dates.
SQL> select ename from emp where hiredate between '01-jan-80' and '01-jan-82';
SHASHIKIRAN V., ASSISTANT PROFESSOR (SENIOR), SITE, VIT VELLORE.
SQL Statements
ENAME
----------
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
KING
TURNER
JAMES
FORD
Using IN Operator:
16. List the employee whose manager ids are 7902, 7566, 7788.
17. List the employee number, name and manager id of SUNIL, ANAND and VIMAL.
If underscore or percentage or literal characters in the string, they should be preceded with an
escape character, which is specified after the string.
Example:
AB\_CD\%EF results in AB_CD%EF
18. List the names of the employee whose name starts with 'S'.
19. List the names of the employee whose name has a second character A.
10 rows selected.
Logical Operators:
AND OR NOT
22. List the employee whose salary is less than 1100 and their job is 'clerk'.
23. List the employee whose salary is greater than or equal to 1100 and/or their job 'clerk'
14 rows selected.
24. List the names of the employee whose job is not "Clerk, Manager, Analyst".
SYNTAX:
SELECT <column name> FROM <table name> WHERE <Condition> [ORDER BY {column,
expression} [ASC/DESC]];
25. List the names of the employee according to their date of joining in the increasing
chorological order.
ENAME HIREDATE
---------- ---------
MILLER 23-JAN-82
SCOTT 19-APR-87
ADAMS 23-MAY-87
14 rows selected.
ENAME HIREDATE
---------- ---------
MILLER 23-JAN-82
SCOTT 19-APR-87
ADAMS 23-MAY-87
14 rows selected.
26. List the names of the employee according to their date of joining in the descending
chorological order.
ENAME HIREDATE
---------- ---------
WARD 22-FEB-81
ALLEN 20-FEB-81
SMITH 17-DEC-80
14 rows selected.
14 rows selected.
28. Sort the deptno in the Ascending order, sal in the each dept should be sorted in
Descending order.
14 rows selected.
29. List the name and salary of employee earning more than $2850.
30. List the name and deptno of the employee whose empno is 7566.
31. Display the names of all employees where the third letter name is an A.
32. Display the name of all employee that have two 'L' in their name and are in department
30 or their manager is 7782.
SQL> select ename,deptno,mgr from emp where deptno=30 and ename like '%L%L%' or
mgr=7782;
ENAME DEPTNO MGR
---------- ---------- ----------
ALLEN 30 7698
MILLER 10 7782
33. Display the name, job and salary for all employee whose job is clerk or analyst and their
salary is not equal to $1000,$3000,or $5000.