Lab 4
Lab 4
Faculty of Computing
Database Systems
Lab 4: Introduction to Oracle and SQL
Learning Objective
After completing this lab the student should be able to:
Discuss Logical operator and their use.
Difference between single row function and multiple row function.
Describe various types of functions that are available in SQL.
Tools and Technologies
Oracle 11g Express edition / enterprise edition
HR Schema for Reference
You can use several conditions in one WHERE clause using the AND and OR
operators.
Syntax
Select column_name, all
From table Name
Where column_name=value and column_name=value;
Example:
Write a query to display employee number, first name, job id ,salary form those
employees whose salary is greater than equal to 1100 and job_id is ‘IT_PROG’
Write a query to show job start date and job end date of those employees
whose department id is 110 and job title is ‘AC_ACCOUNT’
OR operator
Example:
Write a query to display employee number, first name, job title ,salary form
those employees whose salary is greater than equal to 1100 or job_id is
‘IT_PROG’
SELECT employee_id,first_name, job_id ,salary from employees where
salary>=1100
or job_id =’IT_PROG’;
Lab Task 1:
Write a query to display salary and job tile of those employee whose salary is
greater than 4000 or job title IT_PROG
Write a query to show country code, country name of those employees
whose country name ‘Argentina’ or region id 4
Order by clause
The order by clause can be used to sort the rows. If it is used then it must be
placed in last. The default sort order is ascending. To reverse the order you
specify the keyword DESC after column name in ORDER BY clause.
e.g
Syntax
Select comlumn_name
From Table_name
Order by column_name
Lab Task 3:
Write a query to show all country name is descending order Sorting by multiple
columns
You can sort query results by more than one column. The sort limit is the
number of columns in the given table.
e.g
SELECT first_name,department_id,salary from employees order by
department_id , salary desc;
Functions are a very powerful feature of SQL and can be used to do the following:
Perform calculation on data
Modify individual data items
Manipulate output for groups of rows
Format dates and numbers for display
Convert column data types
Lab Task 4:
Write a query to display full name of that employees whose first name contains ‘a’
and salary is 6000, 8400, 8600 and 6100.
Display the full name of each employee, and please note each name is right
justified.