Professional Documents
Culture Documents
Experiment Num 1 Record
Experiment Num 1 Record
Experiment Num 1 Record
String Functions
1)UPPER() Function
The SQL UPPER function converts all the letters in a string into uppercase.
Syntax
UPPER(string)
Parameter Values
Parameter Description
o/p:
UPPER('HE
---------
HELLO SQL
2) LOWER() Function
The LOWER() function converts a string to lower-case.
Syntax
LOWER(string)
Parameter Values
Parameter Description
o/p:
LOWER('D
--------
database
3) INITCAP Function
The INITCAP function sets the first character in each word to uppercase and the
rest to lowercase.
Syntax
The syntax for the INITCAP function in Oracle/PLSQL is:
INITCAP( string1 )
Parameters or Arguments
string1
The string argument whose first character in each word will be converted to
uppercase and all remaining characters converted to lowercase.
Returns
The INITCAP function returns a string value.
Select INITCAP(‘database management’) from dual;
o/p:
INITCAP('DATABASEMA
-------------------
Database Management
4) LPAD Function
The LPAD function pads the left-side of a string with a specific set of characters
(when string1 is not null).
Syntax
The syntax for the LPAD function in Oracle/PLSQL is:
Parameters or Arguments
string1
padded_length
pad_string
Optional. This is the string that will be padded to the left-hand side
of string1. If this parameter is omitted, the LPAD function will pad spaces to
the left-side of string1.
Returns
The LPAD function returns a string value.
o/p:
LPAD('TE
--------
****tech
5) RPAD Function
The Oracle/PLSQL RPAD function pads the right-side of a string with a specific
set of characters (when string1 is not null).
Syntax
The syntax for the RPAD function in Oracle/PLSQL is:
Parameters or Arguments
string1
padded_length
The number of characters to return. If the padded_length is smaller than the
original string, the RPAD function will truncate the string to the size
of padded_length.
pad_string
Optional. This is the string that will be padded to the right-hand side
of string1. If this parameter is omitted, the RPAD function will pad spaces
to the right-side of string1.
Returns
The RPAD function returns a string value.
o/p:
RPAD('TE
--------
tech****
o/p:
RPAD('TE
--------
tech
6) LTRIM Function
The LTRIM function removes all specified characters from the left-hand side of a
string.
Syntax
The syntax for the LTRIM function in Oracle/PLSQL is:
Parameters or Arguments
string1
trim_string
Optional. The string that will be removed from the left-hand side of string1.
If this parameter is omitted, the LTRIM function will remove all leading
spaces from string1.
Returns
The LTRIM function returns a string value.
o/p: LTRI
----
tech
o/p:
LTR
---
123
7) RTRIM Function
The Oracle/PLSQL RTRIM function removes all specified characters from the
right-hand side of a string.
Syntax
The syntax for the RTRIM function in Oracle/PLSQL is:
Parameters or Arguments
string1
trim_string
Optional. The string that will be removed from the right-hand side
of string1. If this parameter is omitted, the RTRIM function will remove all
trailing spaces from string1.
Returns
The RTRIM function returns a string value.
o/p:
RTRI
----
tech
o/p:
RTR
---
123
8) REPLACE Function
The REPLACE function replaces a sequence of characters in a string with another
set of characters, not case-sensitive.
Syntax
The syntax for the REPLACE function in SQL is:
Parameters or Arguments
string1
string_to_replace
replacement_string
o/p: REPLACE(
--------
da3abase
o/p:
REPLACE('Database
DataZbaseZManagement
9) TRANSLATE Function
The Oracle/PLSQL TRANSLATE function replaces a sequence of characters in a
string with another set of characters. However, it replaces a single character at a
time.
For example, it will replace the 1st character in the string_to_replace with the 1st
character in the replacement_string. Then it will replace the 2nd character in
the string_to_replace with the 2nd character in the replacement_string, and so on.
Syntax
The syntax for the TRANSLATE function in Oracle/PLSQL is:
Parameters or Arguments
string1
string_to_replace
replacement_string
O/P:
TRANSLA
-------
4tech56
o/p: TRANSLA
-------
333tith
Syntax
The syntax for the SUBSTR function in Oracle/PLSQL is:
Parameters or Arguments
string
start_position
The starting position for extraction. The first position in the string is always
1.
length
Returns
The SUBSTR function returns a string value.
o/p:
SU
--
is
o/p:
SUBSTR('T
---------
is a test
o/p: SUB
---
The
11) INSTR Function
The Oracle/PLSQL INSTR function returns the location of a substring in a string.
Syntax
The syntax for the INSTR function in Oracle/PLSQL is:
Parameters or Arguments
string
substring
start_position
nth_appearance
Returns
The INSTR function returns a numeric value. The first position in the string is 1.
If substring is not found in string, then the INSTR function will return 0.
SELECT INSTR('Tech on the net', 'e') FROM dual;
o/p:
INSTR('TECHONTHENET','E')
-------------------------
o/p:
INSTR('TECHONTHENET','E',1,1)
-----------------------------
o/p:
INSTR('TECHONTHENET','E',1,2)
-----------------------------
11
o/p:
INSTR('TECHONTHENET','E',-3,2)
------------------------------
2
12) CONCAT Function
The CONCAT function allows you to concatenate strings together.
Syntax
The syntax for the CONCAT function in SQL is:
Parameters or Arguments
string1, string2, ... string_n
o/p:
CONCAT('
--------
database
o/p:
CONCAT('
--------
databasemanagement
13) LENGTH() Function
The LENGTH() function returns the length of the specified string (in bytes).
Syntax
LENGTH(string)
Parameter Values
Parameter Description
o/p:
LENGTH('DATA')
--------------
Numeric Functions
1) ABS Function
the ABS function returns the absolute value of a number.
Syntax
The syntax for the ABS function in SQL Server (Transact-SQL) is:
ABS( number )
Parameters or Arguments
number
The number to convert to an absolute value.
o/p:
ABS(-24)
---------
24
o/p:
ABS(24.65*-1)
-------------
24.65
2) MOD Function
MOD function returns the remainder of m divided by n.
Syntax
The syntax for the MOD function in Oracle/PLSQL is:
MOD( m, n )
Parameters or Arguments
m Numeric value used in the calculation.
o/p: MOD(15,4)
---------
o/p:
MOD(11.6,2.1)
-------------
1.1
3) POWER Function
The POWER function returns m raised to the nth power.
Syntax
The syntax for the POW function in SQL is:
POWER( m, n )
Parameters or Arguments
m
POWER(5,2)
----------
25
4) ROUND Function
The ROUND function returns a number rounded to a certain number of decimal
places.
Syntax
The syntax for the ROUND function in SQL is:
Parameters or Arguments
number
decimal_places
The number of decimal places rounded to. This value must be a positive or
negative integer. If this parameter is omitted, the ROUND function will
round the number to 0 decimal places.
SELECT ROUND(125.315) FROM dual;
o/p:
ROUND(125.315)
----------------
125
o/p:
ROUND(125.315,2)
----------------
125.32
o/p: ROUND(125.315,-1)
-----------------
130
o/p: ROUND(125.315,-2)
-----------------
100
5) TRUNC Function
TRUNC function returns a number truncated to a certain number of decimal
places.
Parameters or Arguments
number
decimal_places
Optional. The number of decimal places to truncate to. This value must be
an integer. If this parameter is omitted, the TRUNC function will truncate
the number to 0 decimal places.
Returns
The TRUNC function (as it applies to numbers) returns a numeric value.
o/p: TRUNC(125.815)
--------------
125
o/p:
TRUNC(125.815,1)
----------------
125.8
o/p:
TRUNC(125.815,-1)
-----------------
120
o/p:
TRUNC(125.815,-2)
-----------------
100
6) SQRT Function
SQRT function returns the square root of n.
Syntax
The syntax for the SQRT function in Oracle/PLSQL is:
SQRT( n )
Parameters or Arguments
n
o/p:
SQRT(9)
---------
o/p:
SQRT(5.617)
-----------
2.3700211
Date Functions
1) MONTHS_BETWEEN Function
MONTHS_BETWEEN function returns the number of months
between date1 and date2.
Syntax
The syntax for the MONTHS_BETWEEN function in Oracle/PLSQL is:
Parameters or Arguments
date1
The first date used to calculate the number of months between.
date2
Returns
The MONTHS_BETWEEN function returns a numeric value.
o/p: MONTHS_BETWEEN('11-JAN-09','11-JAN-08')
---------------------------------------
12
o/p:
MONTHS_BETWEEN('11-JAN-08','11-JAN-09')
---------------------------------------
-12
2)LAST_DAY Function
LAST_DAY function returns the last day of the month based on a date value.
Syntax
The syntax for the LAST_DAY function in Oracle/PLSQL is:
LAST_DAY( date )
Parameters or Arguments
date
The date value to use to calculate the last day of the month.
Returns
The LAST_DAY function returns a date value.
O/P:
LAST_DAY(
---------
31-JUL-18
O/P:
LAST_DAY(
---------
31-JAN-09
3) ADD_MONTHS Function
ADD_MONTHS function returns a date with a specified number of months added.
Syntax
The syntax for the ADD_MONTHS function in Oracle/PLSQL is:
number_months
Returns
The ADD_MONTHS function returns a date value.
O/P:
ADD_MONTH
---------
01-NOV-03
O/P:
ADD_MONTH
---------
21-MAY-03
4) NEXT_DAY Function
NEXT_DAY function returns the first weekday that is greater than a date.
Syntax
The syntax for the NEXT_DAY function in Oracle/PLSQL is:
NEXT_DAY( date, weekday )
Parameters or Arguments
date
weekday
The day of the week that you wish to return. It can be one of the following
values:
Returns
The NEXT_DAY function returns a date value.
SELECT NEXT_DAY('01-Aug-03', 'TUESDAY') FROM DUAL;
o/p:NEXT_DAY(
---------
05-AUG-03
O/P:
NEXT_DAY(
---------
27-JUL-18
Conversion Functions
1) TO_CHAR Function
TO_CHAR function converts a number or date to a string.
Syntax
The syntax for the TO_CHAR function in Oracle/PLSQL is:
Parameters or Arguments
value
format_mask
nls_language
Returns
The TO_CHAR function returns a string value.
O/P:
TO_CHAR
-------
1210.7
O/P:
TO_CHAR(1
---------
1,210.73
O/P:
TO_CHAR(12
----------
$1,210.73
O/P:
TO_CHAR(SY
----------
2018/07/27
O/P: TO_CHAR(SYSDAT
--------------
2) TO_NUMBER Function
TO_NUMBER function converts a string to a number.
Syntax
The syntax for the TO_NUMBER function in Oracle/PLSQL is:
TO_NUMBER( string1 [, format_mask] [, nls_language] )
Parameters or Arguments
string1
format_mask
nls_language
Returns
The TO_NUMBER function returns a numeric value.
o/p:
TO_NUMBER('1210.73','9999.99')
------------------------------
1210.73
o/p:
TO_NUMBER('546','999')
----------------------
546
3) TO_DATE Function
TO_DATE function converts a string to a date.
Syntax
The syntax for the TO_DATE function in Oracle/PLSQL is:
Parameters or Arguments
string1
format_mask
Returns
The TO_DATE function returns a date value.
o/p:
TO_DATE('
---------
09-JUL-03
SELECT TO_DATE('070903', 'MMDDYY') FROM dual;
o/p:
TO_DATE('
---------
09-JUL-03
o/p:
TO_DATE('
---------
15-MAR-02
o/p:
TO_DATE('
---------
15-MAY-15