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

Character Functions : Sample Database

The document discusses various Oracle SQL functions for manipulating character data including INITCAP(), LTRIM(), RTRIM(), TRIM(), UPPER(), LOWER(), and LENGTH(). It provides the syntax and examples of using each function to convert case, trim whitespace, or get string lengths. Sample questions and solutions are given for each function.

Uploaded by

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

Character Functions : Sample Database

The document discusses various Oracle SQL functions for manipulating character data including INITCAP(), LTRIM(), RTRIM(), TRIM(), UPPER(), LOWER(), and LENGTH(). It provides the syntax and examples of using each function to convert case, trim whitespace, or get string lengths. Sample questions and solutions are given for each function.

Uploaded by

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

2/3/2017 CharacterFunctions()Testingpool

CharacterFunctions()
testingpool.com/characterfunctions/

ByShikhaKatariya 9/26/2015

SampleDatabase:

TherearefollowingCharacterFunctions().

1.INITCAP()

ItconvertstheInitialletterofeverywordintoUpperCaseandrestinLowercase.Thischangesareonlytemporaryanddoneonlyinthebuffer.

Syntax:INITCAP(orString)

Example:

Ques:ConvertEnameofEMPTableintoProperCase

http://testingpool.com/characterfunctions/ 1/5
2/3/2017 CharacterFunctions()Testingpool

Ques:ConvertstringuttarpRADESHintopropercase.

Soln:SELECTINITCAP(uttarpRADESH)FROMDUAL

OutputUttarPradesh

2.LTRIM()

Ittrimsthespacesifpresentfromtheleftsideofthestring.

Syntax:LTRIM(orString)

http://testingpool.com/characterfunctions/ 2/5
2/3/2017 CharacterFunctions()Testingpool

Example:

Ques:RemovethespacesfromEnamecolumnofEMPtable

Soln:SELECTLTRIM(ENAME)FROMEMP

Ques:RemovethespaceinApple.

Soln:SELECTLTRIM(Apple)FROMDUAL

OutputApple

3.RTRIM()

Ittrimsthespacesifpresentfromtherightsideofthestring.

Syntax:RTRIM(orString)

Example:

Ques:RemovetherightspacesfromEnamecolumnofEMPtable

Soln:SELECTRTRIM(ENAME)FROMEMP

Ques:RemovethespaceinApple.

Soln:SELECTLTRIM(Apple)FROMDUAL

OutputApple

4.TRIM()

Ittrimsthespacesifpresentfromthebothsidesofthestring.

Syntax:TRIM(orString)

Example:

http://testingpool.com/characterfunctions/ 3/5
2/3/2017 CharacterFunctions()Testingpool

Ques:RemovethespacesfromEnamecolumnofEMPtable

Soln:SELECTTRIM(ENAME)FROMEMP

Ques:RemovethespaceinApple

Soln:SELECTTRIM(Apple)FROMDUAL

OutputApple

5.UPPER()

Itisusedtoconvertallthecharactersofthestringintouppercase.

Syntax:UPPER(<Columnname>orString)

Example:

Ques:Displaythenameofalltheemployeesinuppercase.

Soln:SELECTUPPER(ENAME)FROMEMP

Ques:Convertthestringstrawberryintouppercase.

Soln:SELECTUPPER(strawberry)ROMDUAL

Output:STRAWBERRY

6.LOWER()

Itisusedtoconvertallthecharactersofthestringintolowercase.

Syntax:LOWER(<Columnname>orString)

Example:

Ques:Displaythenameofalltheemployeesinuppercase.

http://testingpool.com/characterfunctions/ 4/5
2/3/2017 CharacterFunctions()Testingpool

Soln:SELECTLOWER(ENAME)FROMEMP

Ques:Convertthestringstrawberryintouppercase.

Soln:SELECTUPPER(STRAWberry)ROMDUAL

Output:strawberry

7.LENGTH()

Itisusedtodeterminethelengthofthespecifiedcolumnorstring.Ifthestringcontainsspaces,thenitisalsocountedasspacehasaASCIIvalue
associatedwithit.

Note:IfthecolumnvalueisofdatatypeCHAR(asCHARisfixedlength)thenitreturnsthefixedlengthdefinedirrespectiveoftheactual
lengthofthevaluepresent.Ontheotherhandifthecolumnvalueisofdatatypevarchar2(varcharisofvariablelength)thenitreturnsthe
actuallengthofthevaluepresent.

Syntax:LENGTH(<Columnname>orString)

Example:

Ques:Displaythelengthofthenamesofalltheemployees.(assumedatatypeofENAMEcolumnisCHAR(10)

Soln:SELECTLENGTH(ENAME)FROMEMP

Ques:Displaythelengthofthenamesofalltheemployees.(assumedatatypeofENAMEcolumnisVARCHAR2(10)

Soln:SELECTUPPER(STRAWberry)ROMDUAL

Output:strawberry

Testingpool2015.AllRightsReserved

http://testingpool.com/characterfunctions/ 5/5

You might also like