0% found this document useful (0 votes)
2 views

SQL

The document outlines the types of built-in functions in Oracle SQL, categorizing them into Single Row Functions and Group Functions. It details four types of Single Row Functions: Numeric, Character or Text, Date, and Conversion Functions, providing examples for each. Additionally, it explains the purpose and usage of various functions within these categories, including their return values.

Uploaded by

prabhuvaibhav173
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL

The document outlines the types of built-in functions in Oracle SQL, categorizing them into Single Row Functions and Group Functions. It details four types of Single Row Functions: Numeric, Character or Text, Date, and Conversion Functions, providing examples for each. Additionally, it explains the purpose and usage of various functions within these categories, including their return values.

Uploaded by

prabhuvaibhav173
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL built-in functions

There are two types of funclions in Oracle sql version.


Single Row Functions: Single row or Scalar functions return a
row that is processed in query. value for every
Group Functions: These functions group the rows of data
returned bythe query. based on the values
There are four types of single row functions. They
1. Numeric Functions: These are are:
numeriC values.
functions that accept numeric input and return
2. Character or Text Functions: These are
and can return both character and number functions that accept character input
values.
3. Date Functions: These are functions
that take values that are of data type
DATE as input and returns values of data type DATE, except for the
BETWEEN functions, which return a number. MONTHS
4. Conversion Functions: These are
functions that help us to convert a value in
one from to another form. For Example: a null value into
an
value from one data type to another data types like NVL, TOactual value, or a
NUMBER, TO DATE etc. CHAR, TO_

Function Return Value


Name
ABS(X) Absolute value of the number 'x
CEIL(X) Integer value that is Greater than or equal to the number 'x'
FLOOR(x) Integer value that is Less than or equal to the number 'x'
TRUNC(%) Truncates value of the number 'x' up to 'y' decimal places
ROUND(x) Rounded off value of the number x' up to the number 'y' decimal
places

Function Name Example Return value


ABS(X) ABS(1) 1

ABS(-1) -1
CEIL(X) CEIL(2.83) 3
CEIL(2.49) 3
CEIL(-1.6) -1
FLOOR(X) FLOOR(2.83) 2
FLOOR(2.49) 2
FLOOR(-1.6) -2
TRUNC(x, y) TRUNC(140.234,2) 140.23
TRUNC(-54,1) -54
TRUNC(5.7) 5
TRUNC(142, -1) 140
ROUND(x, y) ROUND(125.456, 1) 125.5
ROUND(125.456,0) 125
ROUND(124.456,-1)| 120

1
Character or Text Functions:
Character or text functions are used to manipulate text strings. They accept stringS or
characters input and can return both character and number values as output.
Few of the character or text functions are as given
below:
LOWER(string_ value) All the letters in 'string_ value' is
converted to lowercase.
UPPER( string_ value) All the letters in 'string value' is
Converted to uppercase.
INITCAP(string_ value) Allthe letters in 'string value' is
Converted to mixed case.
LTRIM(string_ value, trim_ text) Alloccurrence of 'trim text'is removed
from the left of 'string value'
RTRIM( string value, trim_ text) Alloccurrence of 'trim text' is removed
from the right of 'string value'
TRIM(trim_ text from string_ value) Alloccurrence of 'trim text' is removed
from the left of 'string_ value'; 'trim_ text'
can also be only one character long.
SUBSTR( string value, m, n) Returns 'n' number of characters
from 'string_ value' starting from the 'm'
position.
LENGTH(string_ value) Number of characters in the 'string value'
in returned.
LPAD(String_ value, n, pad_value) Returns 'string value' left- padded with
'pad_ value'. the length of the whole
string will be of 'n' character.
RPAD( string value, n, pad_value) Returns 'string_ value' right- padded with
'pad value'. the length of the whole
string
For Example, we can use the above UPPER () will be of 'n' character.
follows. text function with the column value as
SELECT UPPER (product_ name) FROM product;
The following examples explains is the usage of the above character or text functions
Function Name
LOWER(string value) Examples Returns Value
UPPER(string_ value) LOWER(Good Morning') good morning
UPPER(Good Morning') GOOD
INITCAP(string_ value) MORNING
LTRIM(string value, trim_ text) INITCAP(good morning)
LTRIM(Good Morning',
Good Morning
'Good') Morning
RTRIM(string value, trim_ text) RTRIM(Good Morning', Good
'Morning')from 'Good
TRIM (trim_ text from string value TIRIM(o'
Gd Mrning
SUBSTR( string value, m, n Morning')
LENGTH(string_ value) SUBSTR(Good Morning',6,7) Morning
LPAD( string_ value, n, pad value) LENGTH(Good Morning')
LPAD(Good', 6, *")
12
RPAD ( string_value, n, pad value) **Good
RPAD(Good',6, *") Good**
2
Date functions:
These are functions that take values that are of
values of data types DATE,e cept for the date type DATE as input and return
returns a number as MONTHS BETWEEN function, which
output.
Function Name
ADD MONTHS(date,n) Returns Value
Returns adate value after adding 'n' months to the
MONTHS BETVWEEN (X1,x2) | Returns the number of date x
ROUND (x, date format) months between date x1 and x2
Returns the date 'x' rounded off to the
year, month, date, hour, minute, or nearest century
the date format'!. second as specified by
TRUNC (x, date_format) Returns the date 'x' lesser then or equal to the
nearest
century, year, month, date, hour, minute, or second as
NEXT DAY (X, week_ day) specified by the 'date format'
Returns the next date of the 'week day' on after the
'x ocCurs date
LAST DAY(X) It is used to
determine the number of days remaining in a
month from the date 'x' specified.
NEW TIME(X, zone1, zone2)| Returns the
date and time in zone2 if date 'x
the time in zone1 represents
Now() Returns the current date and time.
sysdate Returns the systems current date
Function Name Examples Returns
ADD MONTHS() Value
ADD MONTHS(21-FEB-24'9) 21-Nov-24
MONTHS MONTHS BETWEEN(16-Sep-24',16
BETWEEN() DEC-24)
NEXT_DAY() NEXT_DAY(02-sep-24', 'Friday') 06-sep-24
LAST DAY()
SYSDATE LAST_DAY(01-sep-24')
SYSDATE 30-sep-24
CURRENT DATE
Conversion Function:
These are functions that help us to convert avalue in one
Ex: a null value into an actual value form one form to another form For
TO CHAR, TO NUMBER, TO DATE. data type another data type Iike NVL
to
Few of the conversion
functions available in oracle are:
Function Name Return value
TO CHAR (x [.yl) Converts Numeric and Date values to a
string value. It cannot be used for character
is a string value. calculation since it
TO DATE(X[, date format)
Converts a Numeric and character values to adate
value. Date is formatted to the format
'date format. specified by
NVL(X,y) If 'x' is NULL, replace it with
'y'. 'x' and 'y' must be of
the same data types.
DECODE (a, b, c, d, e, Checks the value of 'a', if a =b, then
default value) d, then returns 'e', Else, returns 'c. if a =
returns default value
The belowtable provides the
Function Name Examplesexamples the above functions
for
TO CHAR (3000, $9999) Returns Value
TO_CHAR() TO CHAR(SYSDATE, 'Day, $3000
YYYY) Month, WEDNEDAY,
TO DATE) TO DATE (19- MARCH 2014
NVL() NVL (null, 1) MAR-2014') 19-MAR-14
DECODE 1
DECODE(1,2,'T, F') F

You might also like