InThesesyntaxes:
char_value
representsihesinglecharacterwhoso
case haslobechanged string value
represents(hecompletesiringpassedtochangethecase.Thefollowinglistingdemonstrate
how
theLOWER
andUPPER
functionswork.Listing 3.5:Using
LOWER
andUPPER
(unctionsInListing3.5,firs!
we
havedeclaredtwovariablesnaro.and namlof IheVAPCHAR2
datatype.After declarihg all variables,
we
have used iheSELECT
slalemenT to fetch theDNAME
(departmentname)intonam
from IhelabfeDEPT,whereDEPTNO
(departmenlnumber)isequal 1020.Then,we
haveapplied IheLOWER
funcliononIhesiringstoredinthe naipvariable,and usedTheSELECT
statementlofetchIheDNAME
intovarrablenaml whereDEPTNO
isequalto 50. ATlasi,we
haveappliediheupper
functiononihestring slorcdinIhenaml variable.Theoutput,
when we
execuie theprogramshown
inLining3.5,appears asfollows;Output:
In Ihisoutout, Ihefirstoulpul(research) isinlowercaselettersbecauseof the
LOWER
function, whereasthesecondoulpulihuman RESOURCE)
isinuppercaseletters,whichisiheresultofiheUPPER
funclion.INSTH Function
This functionisusedId findIhe position ofasubstringinthemainsiring.This function returns zeroincase ihesubstringisnot presentinthemainstring
SyntaxforIheTtJSTR functionis:
INSTR Cstringl_VB7ue, stn"ngZ_value, itarring_posit!on, nth_pre«nce)
;
53
In(hisiynla\:
u
.-r.ri!-..;1 vi_i:chthemainstringinwhichthe.1position of[hesubstringhastohi.'lound..u- "
.- i-,ihh' Mil>sinr)j>vUi^seposiliunhast<>be t,u(hedin(hemain^trui^
;.--]>-r:]q c:--.-irr.representsthepositioninmainstringfromwhichtheseardi hasto bestarled. It an optionalHr^urrient,liyou don't1specit\ the ..rt r.g po.;:ri tile 'e,ir<!>wi|!-btiirifrom[heI jr^.t(h,ira<ltjrnllhtjiii.iinsiting.
:,-.n_fj:c
-
r.-'-representsthenthposition ot thesubstringm
the m.iin stringIi-s [ i r i
j.* i.ltsho^s hm%Ihe I!'SI-hinttioiiworks.
ListingJ,f>:l
f
LSQL
propram(ouseINJ7R kmc
(ionInfisiinj; !h.lustivehave dellared,1variable
uli:
ofthe'.'A!<l\ data^pe,andthenwe haw
letdied ihe L " :(topartmen
r location^ into lhat variable irom Ihe (able where.I- ikOfjki.ilii>r'O
\nw.T:i."T"' iiinclinnhasbeenappliedonIhe ]i-variablethreetimesknthreerc-suils^
li.tin-tirsiins(an<r.tm\\ !^<>parameters
—
:hemainstringond^jhstnn^--have-beenpasser!ItvvjIIshow1hefirsl
ok
urreru.e uf suhslrrnjJm
Shemam
string.J
Setondlv.we haw
parsed 4p.iramelerv.Thislimeuo
hateaddedHie positionIroniwhere.1sedirhim ihe KubstrirtjJ haslahe started in ihe main string. Ik-re die ihirdand laurth parametersan1 i,\.whichmetingthattheseardihast(jbeslarledTrom ihefirstletteroiIhe slnne.and uptothelirs;occurrenceotthe substringinthemainstring.
_J AlllnriSin-t.ir'ci Iliep.nariieler pass.nl,iresameasthein set"oridoneelu eptth.ithere
we
are searthiim The^ubMNrYu;dpJoilsi'"'occurrenceinthemainstring.
TlieriLdfuiiniIMuni i'ii'.Hisictllnivs:
Output:
DALLAS
£
PL/SQL
In lhiL ouifiLti, \<ia<hiu -ee that (here *irtx four results. The firsl result, .ai
'^
showsihe department Irn^llriri. whir hue
usehlsllif in.nii slnnj;m
this Iehktion. Tfie sero^nrlresuN .' inrlil.iles(heI i L<H<inrenreotihe 'so^lj^triri^iirl(henlaiiri^1111114. 1heihirdresultiss.htk1,ls54
3: Butlt-in Fnttctiotw
thesecondone becauseof thefourthparameterduoiowhichthesubstringhasbeensearched uptoiBfirstoccurrence.Inthefourthresult,thepositionreturned bythisfunctionis!j, which represents(hesecond occurrenceof'A'inthe
mam
string.functions
arcusedtotrimthestringentered as aparameter.The
LTRIM
functiontrimsthe stringfromtheleftsideby removingthecharacterspecifiedas parameterin thisfunction.TheRTRIM
function,onthe otherhand,trimsthestringfrom therightside.Syntaxforthe
LTRIM
functionis:. . LTRltf(str1ng_valtie, str1ng_tr1m)
;
Syntaxforthe
RTRIM
functionis:, KTR1H (3triflQ_valtie» stMng^trlm]
;
Inboth of thepreceding syntaxes
stcingvslue
represents Themainstring,whichhaslobetrimmed.scring_trim
specifiesthestringthat willberemovedfromtheleftside or right side ofthe mainstringdependingonthe functionyouuse.Inboth[hefunctions thesecondargumentisoptionalandifyoudon'tspecifythesecondparameter thenall leading(LTRIMfunction)or trailing(RTRtMfunction)spaceswillberemovedfrom thesiring.
The
followinglistingshowshow
thisfundtonworks.Listing 3,7:Using
LTRIM
andRTRIM
functionsIn Listing 3.7, first,
we
havedeclared fourvariables,nam,d_nam, namZ, and d naml. The variablenam
hasbeen initializedwith a stringhaving some[railingblankspaces while the variablenam2
hasbeeninitializedwith astring,whichhas leadingblank spaces.Afterthis,theDNAME
hasbeenfetched intothed_nam
andd_naml
variables fromthe tableDEFT
whereDEPTNO
isequalto50. Atlast,we
haveapplied theLTRIM
andRTRIM
functionsonthestringsindifferentvariables.
55
Theoutput ofLisling3.7isasfollows:
The
outpulofLining 3.7showsfourresults. Inthefirstresull,youcan seelhatall thetrailing spaceshavebeenremoved fromthestringbecauseoftheLTRIM
function,tntheihird resultyou canseelhatallleadingspaceshavebeenremoved bythe
RTRIM
function,tn(hesecondresull,thedepartment