Lab Manual 02 (Basics)
Lab Manual 02 (Basics)
Contents:
1. Use of Select Clause (DML/DQL).
2. Use of Column Alias, Concatenation Operator, DISTICNT, ALL keyword and Asterisk
Operator.
3. Use of Row Selection Clause (Where).
4. Sorting Results (Use of Order By).
5. Built in Oracle Functions.
Example: Display the column Employee_ID and Phone_Number from Employees table.
Display the column Phone Number as Contact Number.
Page 1 of 8
CL2005 – Database Systems Lab Lab Manual – 02
Task: Display the first_name, last_name of Employees together in one column named
“FULL NAME”.
Page 2 of 8
CL2005 – Database Systems Lab Lab Manual – 02
There are Five Possible Types of Search Condition and Operators to be Used:
Example: List all employees having monthly salaries greater than 20,000 and
deptno: 100.
SELECT * FROM employees WHERE salary > 20,000 and department_id =100;
(b) Range Search Condition: The range search uses BETWEEN and NOT BETWEEN
operators to filter the rows on the basis of range of elements. The Between operator
includes the endpoints too for search output.
Example: List the staff with the salary between 20,000 and 30,000.
(c) Set Membership Search Condition: The set membership (IN) tests whether a data
value matches one of a list of values.
(d) Pattern Match Search Condition: The search condition involves searching for a
particular character or string within a column value. Like Operator with the help of
pattern matching symbols ( _ , %) are used find patterns in the column’s value. ‘_’
represents a single character while ‘%’ represents a sequence of characters.
Example: List all the employees whose names contains an ‘a’ in their first_names.
SELECT * FROM employees WHERE first_name LIKE ‘%a%’;
(e) NULL Search Condition: The NULL Search Condition uses NULL operator to filter fields
that have NULL values.
Tasks:
1) List all Employees having annual salary greater 20, 000 and lesser than 30,000.
2) List employee_id and first_name of employees from department # 60 todepartment #100.
3) List all the Employees belonging to cities like Toronto, Hiroshima and Sydney.
4) List all the Employees having an ‘ll’ in their first_names.
5) List all the employees with no commission.
Page 3 of 8
CL2005 – Database Systems Lab Lab Manual – 02
• Single-row functions: Single Row or Scalar Functions return a value for every row that
is processed in a query.
• Aggregate Functions: The group functions are used to calculate aggregate values
like total or average, which return just one total or one average value after processing
a group of rows.
• Numeric Functions: These are functions that accept numeric input and return
numeric values.
Page 4 of 8
CL2005 – Database Systems Lab Lab Manual – 02
Character or Text Functions: These are functions that accept character input and can
return both character and number values. Following are some frequently used char
functions:
Page 5 of 8
CL2005 – Database Systems Lab Lab Manual – 02
Date Functions: These are functions that take values that are of data type DATE as input
and return values of data type DATE, except for the MONTHS_BETWEEN function, which
returns a number.
Functions Description
Returns a date value after adding ‘n’
ADD_MONTHS(date, n) months to date ‘x’.
MONTHS_BETWEEN(x1,x2) Returns the number of months between
date 1& date 2
NEXT_DAY(x, week_day) Returns the next date of the date
‘week_day’ on or after the date ’x’
occurs.
LAST_DAY(x) It is used to determine the number of
days remaining in a month from the
date ‘x’ specified
SYSDATE Returns the systems current date and
time.
NEW_TIME(x, zone1, zone2) Returns the date and time in zone2 if
date ‘x’ represents the time in zone1.
Implementation:
Conversion Functions:
These are functions that help us to convert a value in one form to another form.
For Example: a null value into an actual value, or a value from one datatype to
another datatype like NVL, TO_CHAR, TO_NUMBER, TO_DATE etc.
You can combine more than one function together in an expression. This is known as
nesting of functions. Following are few examples of conversion functions available in
oracle.
Page 6 of 8
CL2005 – Database Systems Lab Lab Manual – 02
Implementation:
Tasks:
1) Print an employee name (first letter capital) and job title (lower Case)
2) Display employee name and job title together, length of employee name and thenumeric position of
letter A in employee name, for all employees who are in sales.
Hint: For finding position you need to use string function “instr()”, this function workedas INSTR(string1,
string2)(s1:sreaching string, s2:string/char you’re searching for).
3) Comparing the hire dates for all employees who started in 2003, display the employeenumber, hire date,
and month started using the conversion and date functions.
4) To display the employee number, the month number and year of hiring.
5) To display the employee’s name and hire date for all employees. The hire dateappears as 16
September, 2021.
6) Display the salary of employee Neena with $ sign preceded.
7) Find the next ‘Monday’ considering today’s date as date.
8) List all Employees who have an ‘A’ in their last names.
9) Show all employees’ last three letters of first name.
10) For all employees employed for more than 100 months, display the employee number, hire date,
number of months employed, first Friday after hire date andlastday of the month hired.
Page 7 of 8
CL2005 – Database Systems Lab Lab Manual – 02
Examples:
1) Show the average salary, minimum salary, maximum salary and count of employees
in the organization.
SELECT AVG(salary), MIN(salary), MAX(salary), COUNT(employee_id) FROM
employees;
Tasks:
Page 8 of 8