Single Row Functions
Single Row Functions
Sql has many built in functions for performing calculations on data and to convert the argument
to the expected datatype before performing the sql function.
Dual table:-
This is a single row and single column dummy table provided by oracle. This used to perform
mathematical calculations without using a table.
String function
Numeric function
Date function
Conversion function
Null function
Conditional function
String function:-
Case function
Character function
Case functions:-
Upper case
Lower case
Initcap
Syntax :-
Example :-
Syntax :-
Example :-
Syntax :-
Example :-
Character functions:-
Length
Replace
Translate
Trim
Ltrim
Rtrim
Lpad
Rpad
Instr
Substr
Example :-
Syntax :-
Example :-
Syntax :-
Example :-
Syntax :-
Syntax :-
Example :-
Syntax :-
Example :-
Syntax :-
Example :-
Syntax :-
Example :-
Syntax :-
Example :-
Syntax :-
Example :-
NUMERIC FUNCTIONS :-
Round
Trunc
Power
Square root
Mod
Floor
Ceil
Abs
Example :-
Syntax :- This function is used to return the value of X truncated to D number of decimal
places.
Example :-
POWER Returns the value of one expression raised to the power of another expression
Syntax :- These two functions return the value of X raised to the power of Y.
Example :-
Example :-
Example :-
FLOOR Returns the largest integer value that is not greater than passed numeric expression.
Syntax :- This function returns the largest integer value that is not greater than X.
CEIL Returns the smallest integer value that is not less than passed numeric expression.
Syntax :- These functions return the smallest integer value that is not smaller than X
Example :-
Example :-
DATE FUNCTIONS :-
Sysdate
Systimestamp
Months_between
Next_day
Last_day
Add_months
SYSDATE The sysdate function is used to retrieve the current database system time in Oracle
Syntax :-
Example :-
Syntax :-
Example :-
MONTHS_BETWEEN Returns number of months between dates date1 and date2.if date1 is
later than date2,then result is positive.if date1 is earlier than date2,then the result is negative.
Syntax :-
Example :-
NEXT_DAY Returns the date of the first weekday named by char that is later than the date.
Syntax :-
Example :-
Syntax :-
Example :-
Syntax :-
Example :-
CONVERSION FUNCTION :
TO_CHAR
TO_DATE
TO_CHAR Converts numeric and date values to a character string value . it cannot be used
for calculations since it is a string value
Syntax :-
Example :-
Syntax :-
Example :-
NULL FUNCTIONS :
Nvl
Nvl2
Nullif
Coalesce
NVL the nvl function substitutes an alternate value for a null value.
Syntax :-
Example :-
NVL2 Oracle introduced a function to substitute value not only for NULL columns values but
also for NOT NULL columns. NVL2 function can be used to substitute an alternate value for
NULL as well as non NULL value.
Syntax :-
SQL > select nvl2(column_name ,’value is not null’ ,’value is null’) from table_name;
Example :-
SQL > select nvl2(name ,’name is not null’ ,’name is null’) from t1;
NULLIF The NULLIF function compares two arguments expr1 and expr2. If expr1 and
expr2 are equal, it returns NULL; else, it returns expr1. Unlike the other null handling function,
first argument can't be NULL.
Syntax :-
Example :-
COALESCE COALESCE function, a more generic form of NVL, returns the first non-null
expression in the argument list. It takes minimum two mandatory parameters but maximum
arguments has no limit.
Syntax :-
Example :-
CONDITIONAL FUNCTIONS :
Decode
Case
DECODE
Syntax :-
Example :-
Syntax :-
End case
From tablename;
Example :-
End case
From t1;
MULTIROW FUNCTIONS :-
Aggregate function
Order by function
Group by function
Having function
Where clauses
AGGERGATE FUNCTIONS :-
Sum
Max
Min
Avg
Count
Distinct
SUM Returns the sum
Syntax :-
Example :-
Syntax :-
Example :-
Syntax :-
Example :-
Syntax :-
Example :-
Syntax :-
Example :-
Syntax :-
Example :-
ORDER BY FUNCTIONS :
Syntax :-
Example :-
Syntax :-
Example :-
GROUP BY FUNCTION :
Group by clause is used along with the group functions to retrieve data grouped according to one
or more columns.
Syntax :-
Example :-
HAVING CLAUSES
Having clause is used to filter data based on the group functions.this is similar to where
condition but is used with group functions.group functions cannot be used in where clause but
can be used in having clause.
Syntax :-
Example :-
WHERE CLAUSE :
Where clause is used when you want to retrieve specific information from a table excluding
other irrelevant data.
Syntax :-
Example :-