Professional Documents
Culture Documents
CL 203
Lab 02
Functions, Dates And Operators
ORACLE BUILT-IN FUNCTIONS
Functions are a very powerful feature of SQL and can be used to do the following:
3) Date Functions
These are functions that take values that are of datatype DATE as input and
return values of datatype DATE, except for the MONTHS_BETWEEN function,
which returns a number.
4) 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.
Numeric Functions
select abs(sal) from emp
Numeric Functions Example
Character Functions
Character Functions Example
Date Functions
Conversion Functions
Conversion Functions Example
Count Operator
• To count No of Rows in a Table using COUNT()
• Date Arithmetic:
• Select TO_DATE (’31-jul-2012’) + 2 FROM DUAL;
• Select TO_DATE (’02-AUG-2012’) – TO_DATE (’31-JUL-2012’)
FROM dual;
• Result ?
Using Column aliases
• Optional Keyword: AS
• Syntax:
• Select column_name1 AS Column_Alias1, Column_name2
Column_Alias2 FROM TABLE_NAME;
Distinct Keyword
• Used to refrain from duplicate rows/records
= Equal
• Syntax:
• SELECT column_name(s) FROM table_name WHERE
column_name LIKE pattern
Like Operator (Continued..)
• List the employee names starting with ‘K’ and ending with
‘S’.
• SELECT ENAME FROM EMP WHERE ENAME LIKE ’K%S’
• Syntax:
• SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
• List the emps Who Annual sal ranging from 30000 and 50000.
• SELECT * FROM EMP WHERE SAL*12 BETWEEN 30000 AND
50000;
Order By Clause
• To sort the retrieved rows based on a column value