daclive SQL and Advamre
Page No
SAL7
3:1 StainsFunctlans
Chasactex od text functlonsaseused to
manipulate text Staingsthey accept Stain9so&
chanactex as ainput and aeiuan bath chaaactex
and numbeg Values as
autput
Foll.awinsaze the staln4 functlons aae usedL
to find anyStains apexatians
LoWER (Stxin1 value )-Al
the 5taing values aze
canveated to lowea case
Syntax=LoER (slaing);
eample TE youwant to conveat all city colurnrn
values nto louuercasethen me use La WER(Sta1n
funcdions
idcitY table namepeaso
MUMBAI
22 PUNE
Ans SELECT lonER Lcit) ERoM Peasar
r: d
1
city
mumba
Chexe cit
ace
calumn Values
convextecl
tolauedcas ee
Pune neans Small lettex
Page No.
Date
2| UPPER(Slking value):-ALLtheletleas
1S Conveaded to UPpeacase
in stain2 Value
Suntax=_Upp£R(Slaina Value)
i
ex= TE you wantto conneatall CiHy calumn valuo
ues
Lo UPPERCASE2
idcHy table name:Pesson
mum bal
2 fune
Ang UppERCCity)
Quezy SELECT ufpERCCIH) ERom_peasan
id eity
MUMBAI
2 PUNE
3. LTRIM/Staing value taimtext All occussen les
AE aim text isXernavee faam lefL Of Salng value
Syntax-LTRIM( staingvalue,taim text)
aims chaaaciez faom letside
example fyou Want totaim_p chazactesfaom
Pune ity-then weuSe LTRTmU fundion
1 Pune
Page No.
Dato
LTETH('pune 'p)
Queay SELECTLTIRMrunep) FRompexson:
clty
une
TRIMStaina value, tàim iext)- AlLocuaaencesof
faimteat sa is Semaved faom xiaht of staingvalue
SyndaxRTRIM( Staing value,taimiext);.
aample Hyau Want to aemave 'e faam pune Stids
then you Can uSe RTRmO funcdian
>tablename pezsoD-
fune
ueay SELECT RTRTm(eine ('pune' 'e' EROTL-
e/P-id_city
1 Pur
StaingPasition chazackers to
be_eplated
abStaMain
Xetuznthe Substxing fxam the SpeciELed-
E
Positíonmentian în laput
1 2etuan only that Paxt of 5taing Only thaE
Mension in sain9 functja
Page No.
Date
Sundax- SubstaMain Sain9 Pasitian chazackeas to he
Xeplaced)
Era mple:-Tf you want only thnee chaäacteas faam
OHyColumn value then We uSe Substa) fuD
utatSeLEi1 Pune
Pune ablenome-
fesson
3 Mumba
Bansloae
Ans 5ELECTSubsta( cityi3) fom pexson
Staing end
Postlon
Stazlin9
Pos4T
Op id ubslacity)
Pun
2 Pun
3 Mum
Ban
only tharee chaxadeas taom
city column Values lsdisplayed
age No.
Date
LPad(Main staing lengib chaxactesdo bepaddel)-
s uSed fo a foamaHing fxam left Side by
Using anycha2acdex
Medns yau can Pad any chazacderlothe siven
staingfxom lefl side
Synlaxlpad CmainSlain1,lensth,chaxat.exto bepaddal
exampleTfyou wanto pad ¥ chaaaclez to maun Staing
fxam left Side and make -total Stain9 lengh to &
id ciy
Pune tablename: Pegson
2 God
SELECT LPAD( City,8,
*faom peason
ci+y
**Pune (hezet s Podded to city
1efl side
2 * God Co lumn-Va/ues faom
and make stains lensth to 8)
7Racd /Main stain 1,lenslh,chaaacded tobe
padded
aighthandside
S USed foX toamaHinszom
byuSing any chadadea tothe liven
Means you can Pad any,chaXded
i
Stxini f&om aisht 3ide.
Suntax:fad Main 5tain9, len9Hh,chotache
ngth chak
ackex
Kample TF you_Want Ho Pad 'to
*to allcolurmn
all
Vah column
of data valuesExom RHs and make Sxing
xinsof
Valu
leng
id cy
'
Pune ablehame- PeXson
2 Mumbai
Goc
ns ueaySELECT(RPAD(city,7, RomPpes
tRom eXSan
Matn chaxactex
Stai ng Pad fao m RHs
Tota
eng4h
toMode
8 Concotin.ation( Slaing1 Saing Staing n)
THisused to concaten cle seavesal staing
losethex
Synta-CONAT(stain9 L,Stains2 Saingn
ex J you want toconcatenae name and last
homecolumn Value assinale name calumn the
we use Conccelenatefu
fiastname stname
Ravi uma
Rom Shela
Page No.
Date
SELECT cONCATFiks name,lastna me) faom Person,
/P TdnamekumaaRatn i
22 Ram shelaz
LENGTH (staing) His used to find lensh Of 31Venia
Mea ns will siye aunt of chasacte&Pa Psent
Ahe gIVen Slaing
Syntax LENGTH (saina)
to find 4he toal lenrth
of city
xample Ttyau tuont
Column Values
city
Mumbal table hame: Pe3son
2 Goa
Peason
So Quexy SELECT LENGTHCuty) FROM
O/P idity
6 Tetal chasa ct es Psesent into
s1aing
findions
3:2 umeaik oN Aalihmelir
Aaithmelic furclions oxe'used o.
fes
Valties os a
On numheas The y Orcep numeaIC
and 2efuen numenit Values asdutff
Few of numeaic functio.ns dae
ABSCX) Absolude value of-the numbex'x'.
TMeanc if 3iven input is nesalive 1hen.
.aulh
Vill be postive aa vice veasa
Syniax'- ABSCnumeaic value)
eXample:Tr you wand to canveat_nesalive inteae
PasHIve Value 1hen use ABSC)function
Queay-5ELECT AB5(-151) FRom dual
p15:17
CETL -This SQLCEILCT wil'aaunded urany
posHive ox negadive decimalvalue within thefu
uPwoadS
Syndox (EIL('Dumeaicvalue)
Haounded
Upwods means
offthe numeaic Value
27
aOunded tar 2
o the
Page
No.
Date
examplerz ELECT Beti(
SELECT CEIL (36)FRom dua
IP.18 e36 1s
o
) 2
appaoxinmoe
FLOOR C) The SqFlaaa
OAnene9ative unded upany
declmal value dauun posidive
inteaex Value tothenex
least
ueay SELET ELOOR(IH:36)
FRom dual
IP-1E IeTHopPandxi
ximate value Ho lauiex
ideia-
Ttunc(ay
decimal ploceS
Tauncales hevalue af numbexat toy
Exampe:-SEECT
TRuNC (1254561)
af Tzunc (25456) fRomdua
ep 125.4
R Ttwiil give numbex
RoUND(Y)
decimal placeS
upto mensian
decimal
Roundhe Value Of numbed toy
EXamp le-SeLECT
places-
RoUND(14O:282,2)FRam_dual
OP:-_Ho:23
E wll &atmaedoff +he intesex Value to Menstar-
_cdecimal ¢lace
Pago No
Date No
Pago
Dato
6 Exp(x):- Retuan Raiged toxh fawes whe
heae
C 271828 Example SEEa MOD(10,3) ERam dual
fxample
SELEC£xp(5)FRom dua
3 1o isalways
acmindegi
MoDO Fur
P148-412 ie eie 2z1822
/fof
148-412
Powe& (4) Retuans aaised to nhpowex Mus:1:3 Dale ond Time Funcdians=Hake
aae
values thot dats
o
be ileaea value LheseFunctions aetuzn va lues af
a1O yPe DATEas input and
Synax-
O/P-
I 44
=
SELEAPaWER(4,2) FROm dual
16Ax=I6
=644x4Xy= 69
1U
type DATE
ONTHS(dae,
n'
addins mans to the
Suntaxi ADO MONTHS
n) Retuang
date 'Xx
(dade,intéiex
adadevalue atiea
2Nontns
Sat():- Reuan Se4uaxe2oot af - Example
ueay
Ta Jet the today
System
SfLECT ADD_MONTHS/
SysbATE,
day o£ter
2)FRaM DUAL
THeN O/P Nill_be
Syntax SELET SQRT (25 FRam_pesdual
eIrIE Systemdate is 2/10 2022
OP-5
O/ 2/12/20 22
6Mod
he
(ty)- Retuan
divided by second
Secancd numbe
fiest numbex
a
numbes passed pazameleg
is zezohen 3esult:Same
f
thezemindex of a fiastnumber
os ysDATE Cdate):-SyS DATE
(UBdent dale and
funedion isusad
time-at which
tozeluan the
it isinsiadt on nmach
ine
Syniox SysDAT£ (date):
example:- find the sustemeade DUAL
uegy SELECT SyspATE FROm
E
E
E B
D
N
1
T
N
E
-
TE
(D
Page No.
Date
4SEqUENCES
ASeguenceis daahase obitt-ho 3enesche
haaugh unique îneses numbes in o sejuerifal MAXVAIU E
0de enraalo
5CAYIE
Caecdin 1 Sequences Value
eate a Sequmce in you8 Sche ma,you must thes
have CREATE t SEQUENCES Sys System paivillege
Sunl
Syntax fox cXeadtingSeguences
iCREATf SPQUENCEs KsequenLe neme7
STARI WITHstox num
LINCREmENI Ay inaement num
LMAxvALU moaximum num| NoMAXVALUE
RMINVALVE Minimum num |NomINVALUE
CytLEI NOCYCLE
EelancHlon of above eam-
START WITH the staxt Value foxthe
Specifies
Sequent e The default START WTIH fo an aScendins
seguence minimum Valueti) foa descendin9 Sequenre
2:TNCRE MENT By T
Specifiesthe value howthe
SegLuence incxements eachitezation By_defaulta
Sequence incaementsby 1
SMNVALUE must be xeadexthen ox equal -lo
STARI WITH value- T+is mimmum
Valuehat Sequnre
wil 9ernexate
Page No.
Date
MAXyArUE:= LSpec1fy Value the boundS of sesuence
is hiahest value 4ha it 9enesate
eneaatox
5 CAYIE-Sperify cyclE Ho îndioadethe
Value 1s Xeachd the Sequence 1Staais
whenhe maximum
oveg aaln.at
the StatValUe
Suntaxto Caeae SEQUENCE:
CREATESEQUFNCE EID
START TTH d
INCREmENI Byi
MAXVAL UE 1o6
AHeaing Sequences
yau can allea Sequence lo change any Paaan
that definebow it enexates Sequen ce Dumb er
exceptHhe sequence Staat numbes:
Some impoatant pain+ while allesin9 Sequences
To change the Staating Point oE
Sequen te
daop Seguente and then ae-caead iti e
2.Nev MAXVAL Should not less +honslaaxtlng
Vatu'e
Syntaxfoa AlHesing Sequentes
ALTER SEQUENCE KSequeñce name2
TSTART WITHStaal num
INCREMENZ Ry inerem.entNumj
2MAXVALIE maximum num NomEVAL
CMINVALUE minimum Dum NomINyE
Page No
Dato
FX NalHe dQueayo Sel nevy maximum
FID Sequence
uefoxK
Value
ALTER 5EQUENCE EID MAXVALUE 1500
DROPPING SEQUNCES
If a SequenceS 15 nalantex aejuise
sed,
YOu can daop the sejuence usin9 DRoP Se SEQUFNI.
N
stalement-
SundaX- DROP SEQUENCE
EX-DRop SEQUENCE EJD
; Sequence Name
3-5TNOEXES
Tndex azeoptiona Staucdu ae assoiate
Wthloble in s0
Tndex allow SOL Satements mose quikly
yreso INDEX:-
Onique/NoD-Unigue:Based on uniquecalumn
Somelhinglite bank accin
7 Thisindex apply anly bn unique
calumns
Paimoxy lseLondady Paimary
Unigue IndexHhot must indax axe
NULL- hove: yalue,they capnaihe
3Composide Index hatcontain Luao
MoXecolumns O Same lable
Pogo No.
Oato
Caecling of Index:-
Caeae Simple-slnale-column ind ex-
A Sine-calumn index is one thot is caeatec
based an anly one lable column
Syniax
INDEX Îndexname ON table
nameCslu
CREATE name
EXCaeate INDEX emp:1daN employee empid
2 Unigue indext
Unique înclex aae widly used becaUse
does nat allou any duplicate value
inses into.
it
able
SyniaxuniouE
CREATEINDEX indexoame oN tablenamelcalu=
na
CREATE Lnigue index empid an enmplayeeCemplo
3 Compasile Indexi-
Tt adds twood mode olum n ofto
CREATE index fmp indi N employee(emp id
Deplnam
SyntaXi
LREATE INOEX indexncime ON tablo na me
LColumni columh2)
Page No.
Dato
DRopping ndexes ndeXname
Syniax:-
DRoP JNDEX
INDEY em0p indi
EX_D ROP
36 SUNONyMS alable,vIeusju
isallasfox
view,s
Synanyms
pxoceduse, fun.clion touse and
use edu
and tedu
uce
They axe convininent-
LomplexiHy of SL Saements
allas foA anyhing
You on cxeate ass1ah for the
shoat name
5unonyms1s
Lable,view et olar
hat: helps youto Vate eaay s0 em
CREATTNG SUNONyMS
Syniax=
CREATE SUNONm emp FoR emplayee
JF You want to select data fxoam Sunanyms +hen
SELECT * FRom Synonym
DROP SunonymsSuntax
DRaP SNONYM SYnanymname,
ex DRoP Sunonum emf
DeOP SUNONm emP