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

Oracle Function

The document describes various string functions in Oracle including functions to concatenate, format, search, extract substrings, and convert case of strings. Examples are given showing how each function can be used along with the output. The functions allow manipulating strings for tasks like finding locations, extracting parts, standardizing formatting and more.

Uploaded by

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

Oracle Function

The document describes various string functions in Oracle including functions to concatenate, format, search, extract substrings, and convert case of strings. Examples are given showing how each function can be used along with the output. The functions allow manipulating strings for tasks like finding locations, extracting parts, standardizing formatting and more.

Uploaded by

Pankaj Sangale
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

● Character Functions

Functions Description Example Output

|| or Concatenates Select ‘CompU’ || ‘Learn’, ‘COMPU’ ||


CONCAT two strings Concat (‘CompU’,’Learn’) ‘CONCAT(‘CO
together from dual
-----------
-----------------------------
-----

CompU Learn

CompULearn

INITCAP Changes the Select initcap(‘compulearn’) INITCAP(‘C


first letter of a from dual
word or series of ------------------------
words into Compulearn
uppercase

INSTR Finds the Select instr(‘compulearn’,’l’) INSTR


location of a “Instr” from dual;
character iin a ---------------
string otherwise 6
return 0

LENGTH Return the Select length (‘compulearn’) Length


length of a “length” from dual;
string ---------------

10

LOWER Converts every Select LOWER


letter in a string lower( ’COMPULeARN’)
to lower case “lower” from dual; ---------------

Compulearn

UPPER Converts every Select upper (‘compULearn’) UPPER


letter in a string “UPPER” from dual;
to upper case ----------------------

COMPULEARN

LPAD Makes a string a Select Lpad


certain length by lpad(‘compulearn’,20,’xxxx’)
adding a certain “Lpad” from dual; ---------------------------
Functions Description Example Output

|| or Concatenates Select ‘CompU’ || ‘Learn’, ‘COMPU’ ||


CONCAT two strings Concat (‘CompU’,’Learn’) ‘CONCAT(‘CO
together from dual
-----------
-----------------------------
-----

CompU Learn

CompULearn

INITCAP Changes the Select initcap(‘compulearn’) INITCAP(‘C


first letter of a from dual
word or series of ------------------------
words into Compulearn
uppercase

INSTR Finds the Select instr(‘compulearn’,’l’) INSTR


location of a “Instr” from dual;
character iin a ---------------
string otherwise 6
return 0

set of characters ---------


to the left
xxxxxxxxxxcompulearn

RPAD Makes a string a Select Rpad


certain length by Rpad(‘compulearn’,20,’xxxx’
adding a certain ) ----------------------------
set of characters -------
to the right “Rpad” from dual;
compulearnxxxxxxxxxx

RTRIM Trims all the Select RTRIM


occurrences of rtrim(‘compulearn’,’learn’)
any one of a set from dual; -----------------------------
of characters off -----
the right side of ----------
a string
Co-Lmpu

LTRIM Trims all the Select LTRIM


occurrences of Ltrim(‘compulearn’,’compu’)
any one of a set from dual; -----------------------------
of characters off
Functions Description Example Output

|| or Concatenates Select ‘CompU’ || ‘Learn’, ‘COMPU’ ||


CONCAT two strings Concat (‘CompU’,’Learn’) ‘CONCAT(‘CO
together from dual
-----------
-----------------------------
-----

CompU Learn

CompULearn

INITCAP Changes the Select initcap(‘compulearn’) INITCAP(‘C


first letter of a from dual
word or series of ------------------------
words into Compulearn
uppercase

INSTR Finds the Select instr(‘compulearn’,’l’) INSTR


location of a “Instr” from dual;
character iin a ---------------
string otherwise 6
return 0

the left side of a -


string
-----------------

learn

SOUNDEX Finds words that Select ename, ENAME SOUN


sound like soundex(ename) from emp
examples where sounde(ename) like ------------
SOUNDEX(‘FRED’); -----------------

------

FORD F630

SUBSTR Clips out a piece Select SUBST


of a string substr(‘Compulearn’,6,5)
from dual; -----------------------------
----

---------

Learn

CHR Returns the Select CCC


Functions Description Example Output

|| or Concatenates Select ‘CompU’ || ‘Learn’, ‘COMPU’ ||


CONCAT two strings Concat (‘CompU’,’Learn’) ‘CONCAT(‘CO
together from dual
-----------
-----------------------------
-----

CompU Learn

CompULearn

INITCAP Changes the Select initcap(‘compulearn’) INITCAP(‘C


first letter of a from dual
word or series of ------------------------
words into Compulearn
uppercase

INSTR Finds the Select instr(‘compulearn’,’l’) INSTR


location of a “Instr” from dual;
character iin a ---------------
string otherwise 6
return 0

character of the CHR(65),CHR(97),CHR(66)


specified ASCII from dual;
value - - ------------------------

A a B

ASCII Returns the Select ASCII(‘A’), ASCII(‘A’)


ASCII value of ASCII(‘B’), ASCII(‘a’) from
the specified dual ASCII(‘B’)
character ASCII(‘a’)

-------------
--------------------------

65 66

97

TRANSLATE Replaces the Select TRAN


character by Translate(‘Hary’,’y’,’i’) from
character dual ------

Hari
Functions Description Example Output

|| or Concatenates Select ‘CompU’ || ‘Learn’, ‘COMPU’ ||


CONCAT two strings Concat (‘CompU’,’Learn’) ‘CONCAT(‘CO
together from dual
-----------
-----------------------------
-----

CompU Learn

CompULearn

INITCAP Changes the Select initcap(‘compulearn’) INITCAP(‘C


first letter of a from dual
word or series of ------------------------
words into Compulearn
uppercase

INSTR Finds the Select instr(‘compulearn’,’l’) INSTR


location of a “Instr” from dual;
character iin a ---------------
string otherwise 6
return 0

REPLACE Replaces the Select Replaces(‘This and Replace


specified string That’,’Th’,’B’) “Replace”
or character by from dual ---------------
the existing Bis and Bat
string or
character if that
strings is found,
Case sensitive

● Number Function

Function Description Example Output

ABS Return Returns absolute Select abs(- ABS(-25) ABS(25)


Value value 25),abs(25),abs(0) from ABS(0)
dual; ------- ----------- --------
-----
25 25 0
CEIL Smallest integer Select ceil(12.8) “Ceil” Ceil
larger than or from dual -------
equal to value 13

FLOOR Largest integer Select Floor(12.8) Floor


smaller than or “Floor” from dual -------
equal to value 12

SQRT Returns Sqauare Select SQRT(16), SQRT(16) SQRT(25)


root of the SQRT(25) from dual; -------- -------------
specified Number 4 5

Returns
POWERpower specified by the Select Power(3,2), POWER(3,2) POWER910,3)
Power(10,3) from dual; ---------- --------------------
9 1000

SIGN Returns_1 if the Select Sign(-10), SIGN(-10) SIGN(0)


number is Sign(0), Sign(10) from SIGN(10)
negative, 1 if the dual; --------- --------- ----------------
number is ---------
positive and 0 if -1 0 1
the number is 0

TRUNC Truncates the Select trunk(20.345,1), TRUNC(20.345,1) ,(20.345,-


numbers after the Trunc(20.345,-1), 1),(20.345)
decimal Trunc(20.345) from -------------- -------------- ----
depending on the dual; --------
specified integer 20.3 20
20

ROUND Rounds the Select round(65.824,1), ROUND (65.824,1),(65.824,-


expression to the Round(65.824,-1), 1),ROUND(65.824)
specified number Round(65.824) from -------------- ------------------ --
of decimals dual; -----------
65.8 70
66

EXP Returns e raised Select exp(4) from EXP(4)


to n power dual; ----------
54.59815

MOD Returns Modulo Select Mod(10,3) MOD(10,3)


Value From dual; -----------
1
LN Natural Select Ln(10,2) from LN(10)
Logarithm value dual; ---------
2.3025851

LOG Base 10 Select Log(10,2) LOG(10,2)


Logarithm value From dual ------------
.30103

VSIZE Storage size of a Select Vsize(10) from VSIZE(10)


value dual; -----------
2

GREATE Greatest Value of Select GREATEST(10,30,20,50)


ST a List greatest(10,30,20,50) -----------------------
from dual; 50

Least value of a Select least LEAST(10,20,30,40)


list (10,20,30,40) from
LEAST dual; -------------------

10

● Date Function

Function Description Example Output

SYSDATE Returns System Select Sysdate from SYSDATE


Date dual; ---------------
31-JUL-99

ADD_MONTHS Adds or Subtracts Select ADD_MONTH


months to or from a Add_months(Sysda ADD_MONTH
date, Returns date as te,4), ------- -------------------
result Add_months(Sysda 30-NOV-99 31-MAR-99
te,-4) from dual;

LAST_DAY Returns the date of Select Sysdate, SYSDATE LAST_DAY(


the Last day of the Last_Day (Sysdate) ------- -------------------
month specified from dual; 31-JUL-99 31-JUL-99
NEXT_DAY Returns the date of Select SYSDATE
next specified day Sysdate,Next_day(S NEXT_DAY(
of the week after the ysdate,’Wednesday’ --------- ------------------
date ) from dual; 31-JUL-99 4-AUG-99

MONTHS_BET Return number of Select MONTHS BETWEEN


WEEN months between Months_Between(S ---------------------------
dates ysdate,’10-feb-98’) 17.701131
from dual;

ROUND Rounds the date d Select round ROUND(TO_


by the specified (to_date(’09-Oct- --------------------------
format, if format is 74’), 01-Oct-74
not specified it ‘MM’)
defaults to ‘DD’, From dual;
which rounds date
to the nearest day

TRUNC Returns the date d Select TRUNC(TO_


truncated to the unit trunc(To_Date (’09- --------------------------
specified by format, OCT-74 01-JAN-74
if format is omitted, 13:20:30’,’DD-
it defaults to ‘DD’ MON-YY
which truncates to HH24:MI:SS’),’Ye
the nearest day ar’)
FROM DUAL;

● Conversion Function

Function Description Example Output

TO-CHAR Converts the date Select Sysdate, SYSDATE TO_ CHAR(S


‘d’ to character To_char(Sysdate,’DAY --------------- ------------
format ‘f’ ’) 31-JUL-99 SATURDAY
from dual;

TO-DATE Converts the date Select to_date(’09-Oct- TO_DATE(‘ ‘R


‘d’ to character 74’),’RM’ from dual; -------- --------------
format ‘f’ 09-OCT-74 RM

DECODE Decodes the Select sname, ENAME DECODE(JO


specified data to decode(job,’CLERK’,’ ----------- ----------------
another EXECUTIVE’) SMITH EXECUTIVE
representation From emp where ADAMS EXECUTIVE
job=’CLERK’; JAMES EXECUTIVE
MILLER EXECUTIVE

TO_NUM Conversion of Select TO_NUMBER(‘100’)


BER character to a to_number(‘100’) from ---------------------------
number dual; 100

You might also like