SQL Functions1
SQL Functions1
Types of Functions
• Numeric Functions
– Single value functions
– List value functions
– Group Value Functions
• Character Functions
• Date functions
DUAL Table
What is a DUAL Table in Oracle?
* This is a single row and single column dummy table provided
by Oracle
* This is used to perform mathematical calculations without
using a table.
Select * from DUAL
DUMMY
-------
X
Select 777 * 888 from Dual
• Output:
• 777 * 888
---------
689976
Numeric Functions
Function Name Examples Return Value
ABS (1) 1
ABS (x)
ABS (-1) -1
CEIL (2.83) 3
CEIL (x) CEIL (2.49) 3
CEIL (-1.6) -1
FLOOR (2.83) 2
FLOOR (x) FLOOR (2.49) 2
FLOOR (-1.6) -2
ADD_MONTHS ('16-Sep-
ADD_MONTHS ( ) 16-Dec-81
81', 3)
MONTHS_BETW MONTHS_BETWEEN ('16-
3
EEN( ) Sep-81', '16-Dec-81')
NEXT_DAY ('01-Jun-08',
NEXT_DAY( ) 04-JUN-08
'Wednesday')
LAST_DAY( ) LAST_DAY ('01-Jun-08') 30-Jun-08
NEW_TIME ('01-Jun-08',
NEW_TIME( ) 31-May-08
'IST', 'EST')
Standard Time Zone
• AST, ADT: Atlantic Standard or Daylight Time
• BST, BDT: Bering Standard or Daylight Time
• CST, CDT: Central Standard or Daylight Time
• EST, EDT: Eastern Standard or Daylight Time
• GMT: Greenwich Mean Time
• HST, HDT: Alaska-Hawaii Standard Time or Daylight Time.
• MST, MDT: Mountain Standard or Daylight Time
• NST: Newfoundland Standard Time
• PST, PDT: Pacific Standard or Daylight Time
• YST, YDT: Yukon Standard or Daylight Time
FROM employee
FROM employee
GROUP BY dept;
Having clause
• Retrieve a list of the highest
paid salaries in each dept having
salry greater than 20000:
SELECT max(salary), dept
FROM employee