Top Banner

of 116

bestsqlplsqlmaterial-140617143256-phpapp02

Aug 07, 2018

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    1/326

    INTRODUCTION

    SQL is divided into the following

    1 Data Definition Language (DDL)

    2 Data Manipulation Language (DML)

    3 Data Retieval Language (DRL)

    4 Tansa!tion Contol Language (TCL)

    5 Data Contol Language (DCL)

    DDL "" !eate# alte# dop# tun!ate# ena$eDML "" inset# update# deleteDRL "" sele!tTCL "" !o$$it# oll%a! savepointDCL "" gant# evo&e

    CR'T' TL' S*NT+

    Ceate ta%le ,table_name- (col1 datatype1, col2 datatype2 …coln datatypen).

    '/0

    SQL- !eate ta%le student (no nu$%e (1)# na$e va!ha (23)# $a&s nu$%e (4)).

    INS'RT

    This will %e used to inset the e!ods into ta%le5

    6e have two $ethods to inset5

    1 7 value $ethod

    2 7 addess $ethod

    a) USIN8 9LU' M'T:OD

     

    S7nta/0

      inset into ,table_name- values (value1, value2, value3 …. Valuen).

     

    '/0

    SQL- inset into student values (2# ;sudha;# 233).

      SQL- inset into student values (1# ;sað# 133).

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    2/326

     

    To inset a new e!od again 7ou have to t7pe entie inset !o$$and# if thee ae lot of

    e!ods this will %e diffi!ult5

      This will %e avoided %7 using addess $ethod5

     %) USIN8 DDR'SS M'T:OD

     

    S7nta/0

      inset into ,table_name) values (&col1, &col2, &col3 …. &coln).

      This will po$pt 7ou fo the values %ut fo eve7 inset 7ou have to use fowad slash5

     

    '/0

    SQL- inset into student values (agan

    'nte value fo $a&s0 433

    old 20 inset into student values(

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    3/326

      SQL- inset into student (no# na$e) values (@# ;Madhu;).

    d) INS'RTIN8 DT INTO SA'CIBI'D COLUMNS USIN8 DDR'SS M'T:OD

     

    S7nta/0

      inset into ,table_name)(col1, col2, col3 … coln) values (&col1, &col2 ….&coln);

    This will po$pt 7ou fo the values %ut fo eve7 inset 7ou have to use fowad slash5

     

    '/0

    SQL- inset into student (no# na$e) values (

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    4/326

      1 Sa&eth 133

      2 >agan 433

      1 Naen @33

      4 Ra$esh

      @ Madhu

      9isu

      Rattu

      SQL- sele!t no# na$e# $a&s fo$ student.

      NO NM' MRFS

      """ """""" """"""""

      2 Sudha 233

      1 Sa&eth 133

      2 >agan 433

      1 Naen @33

      4 Ra$esh

      @ Madhu

      9isu

      Rattu

      SQL- sele!t no# na$e fo$ student.

      NO NM'

      """ """""""

      2 Sudha

      1 Sa&eth

      2 >agan

      1 Naen  4 Ra$esh

      @ Madhu

      9isu

      Rattu

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    5/326

      CONDITIONL S'L'CTIONS ND OA'RTORS

    6e have two !lauses used in this

    1 6hee

    2 Ode %7

    USIN8 6:'R'

    S7nta/0

      sele!t E fo$ ,table_name- whee ,condition-.

     

    the following ae the diffeent t7pes of opeatos used in whee !lause5

    1 ith$eti! opeatos

    2 Co$paison opeatos

    3 Logi!al opeatos

    1 ith$eti! opeatos "" highest pe!eden!e

    G# "# E# ?

    2 Co$paison opeatos

    H# H# -# ,# -H# ,H# ,-

    1  %etween# not %etween

    3 in# not in

    3 null# not null

    4 li&e

    5 Logi!al opeatos

    2 nd

    4 O "" lowest pe!eden!e

    4 not

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    6/326

    a) USIN8 H# -# ,# -H# ,H# H# ,-

     

    '/0

      SQL- sele!t E fo$ student whee no H 1.

      NO NM' MRFS

      """ """"""" """""""""

      1 Sa&eth 133

      1 Naen @33

     

    SQL- sele!t E fo$ student whee no , 1.

      NO NM' MRFS

      """ """"""" """"""""""

    2 Sudha 233

      2 >agan 433

      SQL- sele!t E fo$ student whee no - 1.

      NO NM' MRFS

      """ """"""" """"""""""

      4 Ra$esh

      @ Madhu

      9isu

      Rattu

      SQL- sele!t E fo$ student whee no ,H 1.

      NO NM' MRFS

      """ """"""" """"""""""

      2 Sudha 233

      1 Sa&eth 133

      2 >agan 433

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    7/326

      1 Naen @33

     

    SQL- sele!t E fo$ student whee no -H 1.

      NO NM' MRFS

      """ """"""" """""""""

      1 Sa&eth 133

      1 Naen @33

      4 Ra$esh

      @ Madhu

      9isu

      Rattu

      SQL- sele!t E fo$ student whee no H 1.

      NO NM' MRFS

      """ """"""" """"""""""

      2 Sudha 233

      2 >agan 433

      4 Ra$esh

      @ Madhu

      9isu

      Rattu

      SQL- sele!t E fo$ student whee no ,- 1.

      NO NM' MRFS

      """ """"""" """"""""""

      2 Sudha 233  2 >agan 433

      4 Ra$esh

      @ Madhu

      9isu

      Rattu

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    8/326

     %) USIN8 ND

      This will gives the output when all the !onditions %e!o$e tue5

     

    S7nta/0

      sele!t E fo$ ,table_name- whee ,condition1- and ,condition2- and 55 ,conditionn-.

      '/0

      SQL- sele!t E fo$ student whee no H 1 and $a&s -H 133.

      NO NM' MRFS

      """ """"""" """"""""

      1 Sa&eth 133

      1 Naen @33

    !) USIN8 OR 

      This will gives the output when eithe of the !ondition %e!o$es tue5

      S7nta/0

      Sele!t E fo$ ,table_name- whee ,condition1- and ,condition2- o55 ,condition-.

      '/0

    SQL- sele!t E fo$ student whee no H 1 o $a&s -H 133.

      NO NM' MRFS

      """ """"""" """""""""

      1 Sa&eth 133

      2 >agan 433

      1 Naen @33

    d) USIN8 'T6''N

      This will gives the output %ased on the !olu$n and its lowe %ound# uppe %ound5

      S7nta/0

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    9/326

      sele!t E fo$ ,table_name- whee ,col - %etween ,lower bound - and ,upper bound -.

      '/0

    SQL- sele!t E fo$ student whee $a&s %etween 133 and @33.

      NO NM' MRFS

      """ """"""" """""""""

      1 Sa&eth 133

      2 >agan 433

      1 Naen @33

    e) USIN8 NOT 'T6''N

      This will gives the output %ased on the !olu$n whi!h values ae not in its lowe %ound# uppe%ound5

      S7nta/0

      sele!t E fo$ ,table_name- whee ,col - not %etween ,lower bound - and ,upper bound -.

    '/0

    SQL- sele!t E fo$ student whee $a&s not %etween 133 and @33.

      NO NM' MRFS

      """ """"""" """""""""

    2 Sudha 233

    f) USIN8 IN

      This will gives the output %ased on the !olu$n and its list of values spe!ified5

      S7nta/0

      sele!t E fo$ ,table_name- whee ,col - in ( value1, value2, value3 … valuen).

      '/0

    SQL- sele!t E fo$ student whee no in (2# 1# 4).  NO NM' MRFS  """ """"""" """""""""  2 Sudha 233  1 Sa&eth 133  2 >agan 433  1 Naen @33  4 Ra$esh

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    10/326

    g) USIN8 NOT IN

    This will gives the output %ased on the !olu$n whi!h values ae not in the list of values spe!ified5

      S7nta/0

      sele!t E fo$ ,table_name- whee ,col - not in ( value1, value2, value3 … valuen).

      '/0

    SQL- sele!t E fo$ student whee no not in (2# 1# 4).

      NO NM' MRFS

      """ """"""" """""""""

      @ Madhu

      9isu

      Rattu

    h) USIN8 NULL

      This will gives the output %ased on the null values in the spe!ified !olu$n5

      S7nta/0

      sele!t E fo$ ,table_name- whee ,col - is null.

      '/0

    SQL- sele!t E fo$ student whee $a&s is null.

      NO NM' MRFS

      """ """"""" """""""""

      4 Ra$esh  @ Madhu

      9isu

      Rattu

    i) USIN8 NOT NULL

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    11/326

      This will gives the output %ased on the not null values in the spe!ified !olu$n5

      S7nta/0

      sele!t E fo$ ,table_name- whee ,col - is not null.

      '/0

    SQL- sele!t E fo$ student whee $a&s is not null.

      NO NM' MRFS

      """ """"""" """""""""

      2 Sudha 233

      1 Sa&eth 133

      2 >agan 433

      1 Naen @33

     J) USIN8 LIF'

      This will %e used to sea!h though the ows of data%ase !olu$n %ased on the patten 7ou spe!if75

      S7nta/0

      sele!t E fo$ ,table_name- whee ,col - li&e , pattern-.

     

    '/0

    i) This will give the ows whose $a&s ae 2335

    SQL- sele!t E fo$ student whee $a&s li&e 233.

      NO NM' MRFS

      """ """"""" """""""""  2 Sudha 233

      ii) This will give the ows whose na$e stat with KS;5

    SQL- sele!t E fo$ student whee na$e li&e =S=.

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    12/326

      NO NM' MRFS

      """ """"""" """""""""

      2 Sudha 233

      1 Sa&eth 133

      iii) This will give the ows whose na$e ends with Kh;5

      SQL- sele!t E fo$ student whee na$e li&e =h=.

     

     NO NM' MRFS

      """ """"""" """""""""

      1 Sa&eth 133

      4 Ra$esh

      i9) This will give the ows whose na$e;s se!ond lette stat with Ka;5

      SQL- sele!t E fo$ student whee na$e li&e =a=.

      NO NM' MRFS

      """ """"""" """"""""

      1 Sa&eth 133

      2 >agan 433

      1 Naen @33

      4 Ra$esh

      @ Madhu

      Rattu

     

    9) This will give the ows whose na$e;s thid lette stat with Kd;5

      SQL- sele!t E fo$ student whee na$e li&e =d=.

      NO NM' MRFS

      """ """"""" """""""""

      2 Sudha 233

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    13/326

      @ Madhu

      9i) This will give the ows whose na$e;s se!ond lette stat with Kt; fo$ ending5

      SQL- sele!t E fo$ student whee na$e li&e =t=.

      NO NM' MRFS

      """ """"""" """""""""

      1 Sa&eth 133

      Rattu

     

    9ii) This will give the ows whose na$e;s thid lette stat with Ke; fo$ ending5

      SQL- sele!t E fo$ student whee na$e li&e =e=.

      NO NM' MRFS

      """ """"""" """""""""

      1 Sa&eth 133

      4 Ra$esh

      9iii) This will give the ows whose na$e !otains 1 a;s5

      SQL- sele!t E fo$ student whee na$e li&e =a a =.

      NO NM' MRFS

      """ """"""" """"""""""

    2 >agan 433

    E *ou have to spe!if7 the pattens in lie using undes!oe ( )5

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    14/326

    USIN8 ORD'R *

    This will %e used to odeing the !olu$ns data (as!ending o des!ending)5

    S7nta/0

      Sele!t E fo$ ,table_name- ode %7 ,col - des!.

    7 default oa!le will use as!ending ode5

    If 7ou want output in des!ending ode 7ou have to use de!c &e7wod afte the !olu$n5

    '/0

      SQL- sele!t E fo$ student ode %7 no.

      NO NM' MRFS

      """ """"""" """""""""

      2 Sudha 233

      2 >agan 433

      1 Sa&eth 133s

      1 Naen @33

      4 Ra$esh

      @ Madhu

      9isu

      Rattu

      SQL- sele!t E fo$ student ode %7 no des!.

      NO NM' MRFS

      """ """"""" """""""""

      Rattu

      9isu

      @ Madhu  4 Ra$esh

      1 Sa&eth 133

      1 Naen @33

      2 Sudha 233

      2 >agan 433

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    15/326

    USIN8 DML

    USIN8 UADT'

    This !an %e used to $odif7 the ta%le data5

    S7nta/0

      Update ,table_name- set ,col1- H value2# ,col2- H value1 whee ,condition-.

    '/0

      SQL- update student set $a&s H 33.

      If 7ou ae not spe!if7ing an7 !ondition this update entie ta%le will5

      SQL- update student set $a&s H 33 whee no H 1.

      SQL- update student set $a&s H 33# na$e H =9enu= whee no H 2.

    USIN8 D'L'T'

    This !an %e used to delete the ta%le data te$poail75

    S7nta/0

      Delete ,table_name- whee ,condition-.

    '/0

      SQL- delete student.

      If 7ou ae not spe!if7ing an7 !ondition this will delete entie ta%le5

      SQL- delete student whee no H 1.

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    16/326

    USIN8 DDL

    USIN8 LT'R 

    This !an %e used to add o e$ove !olu$ns and to $odif7 the pe!ision of the datat7pe5

    a) DDIN8 COLUMN

      S7nta/0

      alte ta%le ,table_name- add ,col datatype-.

      '/0

      SQL- alte ta%le student add sdo% date.

     %) R'MO9IN8 COLUMN

      S7nta/0

      alte ta%le ,table_name- dop ,col datatype-.

      '/0

      SQL- alte ta%le student dop !olu$n sdo%.

    !) INCR'SIN8 OR D'CR'SIN8 AR'CISION OB COLUMN

      S7nta/0

      alte ta%le ,table_name- $odif7 ,col datatype-.

      '/0

      SQL- alte ta%le student $odif7 $a&s nu$%e().

      E To de!ease pe!ision the !olu$n should %e e$pt75

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    17/326

    d) MFIN8 COLUMN UNUS'D

      S7nta/0

      alte ta%le ,table_name- set unused !olu$n ,col -.

      '/0

      SQL- alte ta%le student set unused !olu$n $a&s.

     

    'ven though the !olu$n is unused still it will o!!up7 $e$o75

    d) DROAAIN8 UNUS'D COLUMNS

      S7nta/0

      alte ta%le ,table_name- dop unused !olu$ns.

      '/0

      SQL- alte ta%le student dop unused !olu$ns.

    E *ou !an not dop individual unused !olu$ns of a ta%le5

    e) R'NMIN8 COLUMN

      S7nta/0

      alte ta%le ,table_name- ena$e !olu$n ,old_col_name- to ,new_col_name-.

      '/0

      SQL- alte ta%le student ena$e !olu$n $a&s to s$a&s.

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    18/326

    USIN8 TRUNCT'

    This !an %e used to delete the entie ta%le data pe$anentl75

    S7nta/0

      tun!ate ta%le ,table_name-.

    '/0

      SQL- tun!ate ta%le student.

    USIN8 DROA

    This will %e used to dop the data%ase o%Je!t.

    S7nta/0

      Dop ta%le ,table_name-.

    '/0

      SQL- dop ta%le student.

    USIN8 R'NM'

    This will %e used to ena$e the data%ase o%Je!t.

    S7nta/0

      ena$e ,old table_name- to ,new_table_name-.

    '/0

      SQL- ena$e student to stud.

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    19/326

    USIN8 TCL

    USIN8 COMMIT

    This will %e used to save the wo&5

    Co$$it is of two t7pes5

    1 I$pli!it

    2 '/pli!it

    a) IMALICIT

    This will %e issued %7 oa!le intenall7 in two situations5

    1 6hen an7 DDL opeation is pefo$ed5

    2 6hen 7ou ae e/iting fo$ SQL E ALUS5

     %) '+ALICIT

      This will %e issued %7 the use5

      S7nta/0

      Co$$it o !o$$it wo&.

      E 6hen eve 7ou !o$$itted then the tansa!tion was !o$pleted5

    USIN8 ROLLCF 

    This will undo the opeation5

    This will %e applied in two $ethods5

    1 Upto pevious !o$$it

    2 Upto pevious oll%a!& 

    S7nta/0

    Roll o oll wo&.

    O

    Roll%a!& o oll%a!& wo&.

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    20/326

    E 6hile po!ess is going on# if suddenl7 powe goes then oa!le will oll%a!& the tansa!tion5

    USIN8 S9'AOINT

    *ou !an use savepoints to oll%a!& potions of 7ou !uent set of tansa!tions5

    S7nta/0

      Savepoint , !avepoint_name-.

    '/0

      SQL- savepoint s2.

      SQL- inset into student values(2# Ka;# 233).

      SQL- savepoint s1.

      SQL- inset into student values(1# K%;# 133).

      SQL- savepoint s4.

      SQL- inset into student values(4# K!;# 433).

      SQL- savepoint s@.

      SQL- inset into student values(@# Kd;# @33).

      efoe oll%a!&

    SQL- sele!t E fo$ student.

      NO NM' MRFS

      """ """"""" """"""""""

      2 a 233

      1 % 133

      4 ! 433

      @ d @33

      SQL- oll%a!& to savepoint s4.

      O 

      SQL- oll%a!& to s4.

     

    This will oll%a!& last two e!ods5

      SQL- sele!t E fo$ student.

      NO NM' MRFS

      """ """"""" """"""""""

      2 a 233

      1 % 133

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    21/326

    USIN8 DCL

    DCL !o$$ands ae used to ganting and evo&ing the pe$issions5

    USIN8 8RNT

    This is used to gant the pivileges to othe uses5

    S7nta/0

      8ant , privile"e!- on ,ob#ect_name- to ,u!er_name- with gant option.

    '/0

      SQL- gant sele!t on student to sudha. "" 7ou !an give individual pivilege

      SQL- gant sele!t# inset on student to sudha. "" 7ou !an give set of pivileges

      SQL- gant all on student to sudha. "" 7ou !an give all pivileges

     

    The sudha use has to use dot $ethod to a!!ess the o%Je!t5

      SQL- sele!t E fo$ sa&eth5student.

      The sudha use !an not gant pe$ission on student ta%le to othe uses5 To get this

    t7pe of option use the following5

      SQL- gant all on student to sudha with gant option.

      Now sudha use also gant pe$issions on student ta%le5

    USIN8 R'9OF'

    This is used to evo&e the pivileges fo$ the uses to whi!h 7ou ganted the pivileges5

    S7nta/0

      Revo&e , privile"e!- on ,ob#ect_name- fo$ ,u!er_name-.

    '/0

      SQL- evo&e sele!t on student fo$ sudha. "" 7ou !an evo&e individual pivilege

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    22/326

      SQL- evo&e sele!t# inset on student fo$ sudha. "" 7ou !an evo&e set of pivileges

      SQL- evo&e all on student fo$ sudha. "" 7ou !an evo&e all pivileges

     

    USIN8 LIS'S

    CR'T' 6IT: S'L'CT

    6e !an !eate a ta%le using e/isting ta%le along with data5

    S7nta/0

      Ceate ta%le ,new_table_name- col1, col2, col3 ... coln as sele!t E fo$

    ,old_table_name-.

    '/0

      SQL- !eate ta%le student2 as sele!t E fo$ student.

     

    Ceating ta%le with 7ou own !olu$n na$es5

      SQL- !eate ta%le student1(sno# sna$e# s$a&s) as sele!t E fo$ student.

     

    Ceating ta%le with spe!ified !olu$ns5

      SQL- !eate ta%le student4 as sele!t no#na$e fo$ student.

     

    Ceating ta%le with out ta%le data5

      SQL- !eate ta%le student1(sno# sna$e# s$a&s) as sele!t E fo$ student whee 2 H 1.

      In the a%ove whee !lause give an7 !ondition whi!h does not satisf75

     

    INS'RT 6IT: S'L'CT

    Using this we !an inset e/isting ta%le data to a anothe ta%le in a single tip5 ut the ta%le stu!tue

    should %e sa$e5

    S7nta/0  Inset into ,table1- sele!t E fo$ ,table2-.

    '/0

      SQL- inset into student2 sele!t E fo$ student.

      Inseting data into spe!ified !olu$ns

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    23/326

      SQL- inset into student2(no# na$e) sele!t no# na$e fo$ student.

    COLUMN LIS'S

    S7nta/0

      $elect %or"inal_col %alia!_name 'rom %table na$e-.

    '/0

      SQL- sele!t no sno fo$ student.

      SQL- sele!t no Psno fo$ student.

    TL' LIS'S

    If 7ou ae using ta%le aliases 7ou !an use dot $ethod to the !olu$ns5

    S7nta/0

      Sele!t ,alia!_name-5,col1-# ,alia!_name-5,col2- ,alia!_name-5,coln- fo$

    ,table_name- ,alia!_name-.

    '/0

      SQL- sele!t s5no# s5na$e fo$ student s.

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    24/326

    USIN8 M'R8'

    M'R8'

    *ou !an use $ege !o$$and to pefo$ inset and update in a single !o$$and5

    '/0

    SQL- Mege into student2 s2

      Using (sele!t EBo$ student1) s1

      On(s25noHs15no)

      6hen $at!hed then

      Update set $a&s H s15$a&s

      6hen not $at!hed then

      Inset (s25no#s25na$e#s25$a&s)

      9alues(s15no#s15na$e#s15$a&s).

    In the a%ove the two ta%les ae with the sa$e stu!tue %ut we !an $ege diffeent stu!tued ta%les also

     %ut the datat7pe of the !olu$ns should $at!h5

    ssu$e that student2 has !olu$ns li&e no#na$e#$a&s and student1 has !olu$ns li&e no#

    na$e# hno# !it75

    SQL- Mege into student2 s2

      Using (sele!t EBo$ student1) s1

      On(s25noHs15no)

      6hen $at!hed then

      Update set $a&s H s15hno

      6hen not $at!hed then

      Inset (s25no#s25na$e#s25$a&s)

      9alues(s15no#s15na$e#s15hno).

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    25/326

    MULTIAL' INS'RTS

    6e have ta%le !alled D'AT with the following !olu$ns and data

    D'ATNO DNM' LOC

    """""""" """""""" """"

    23 a!!ounting new 7o&  

    13 esea!h dallas

    43 sales Chi!ago

    @3 opeations %oston

    a) CR'T' STUD'NT TL'

      SQL- Ceate ta%le student(no nu$%e(1)#na$e va!ha(1)#$a&s nu$%e(4)).

     %) MULTI INS'RT 6IT: LL BI'LDS

      SQL- Inset all

      Into student values(2#;a;#233)

      Into student values(1#;%;#133)

      Into student values(4#;!;#433)

      Sele!t Efo$ dept whee deptnoH23.

      "" This insets 4 ows

    !) MULTI INS'RT 6IT: SA'CIBI'D BI'LDS

      SQL- inset all

      Into student (no#na$e) values(@#;d;)

      Intostudent(na$e#$a&s)values(;e;#@33)

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    26/326

      Into student values(4#;!;#433)

      Sele!t Efo$ dept whee deptnoH23.

      "" This insets 4 ows

    d) MULTI INS'RT 6IT: DUALICT' RO6S

      SQL- inset all

      Into student values(2#;a;#233)

      Into student values(1#;%;#133)

      Into student values(4#;!;#433)

      Sele!t Efo$ dept whee deptno - 23.

      "" This insets ows %e!ause in the sele!t state$ent etieves 4 e!ods (4 insets fo

    ea!h ow etieved)

    e) MULTI INS'RT 6IT: CONDITIONS S'D

      SQL- Inset all

      6hen deptno - 23 then

      Into student2 values(2#;a;#233)

      6hen dna$e H KSL'S; then

      Into student1 values(1#;%;#133)

      6hen lo! H KN'6 *ORF; then

      Into student4 values(4#;!;#433)

      Sele!t Efo$ dept whee deptno-23.

      "" This insets @ ows %e!ause the fist !ondition satisfied 4 ti$es# se!ond !ondition

    satisfied on!e and the last none5

    f) MULTI INS'RT 6IT: CONDITIONS S'D ND 'LS'

      SQL- Inset all

      6hen deptno - 233 then

      Into student2 values(2#;a;#233)

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    27/326

      6hen dna$e H KS; then

      Into student1 values(1#;%;#133)

      6hen lo! H KN'6 *ORF; then

      Into student4 values(4#;!;#433)

      'lse

    Into student values(@#;d;#@33)

      Sele!t Efo$ dept whee deptno-23.

      "" This insets 4 e!ods %e!ause the else satisfied 4 ti$es

    g) MULTI INS'RT 6IT: CONDITIONS S'D ND BIRST

      SQL- Inset fist

      6hen deptno H 13 then

      Into student2 values(2#;a;#233)

      6hen dna$e H KR'S'RC:; then

      Into student1 values(1#;%;#133)

      6hen lo! H KN'6 *ORF; then

      Into student4 values(4#;!;#433)

      Sele!t Efo$ dept whee deptnoH13.

     

    "" This insets 2 e!od %e!ause the fist !lause avoid to !he!& the e$aining

    !onditions on!e the !ondition is satisfied5

    h) MULTI INS'RT 6IT: CONDITIONS S'D# BIRST ND 'LS'

      SQL- Inset fist

      6hen deptno H 43 then

      Into student2 values(2#;a;#233)  6hen dna$e H KR; then

      Into student1 values(1#;%;#133)

      6hen lo! H KN'6 *ORF; then

      Into student4 values(4#;!;#433)

      'lse

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    28/326

      Into student values(@#;d;#@33)

      Sele!t Efo$ dept whee deptnoH13.

      "" This insets 2 e!od %e!ause the else !lause satisfied on!e

    i) MULTI INS'RT 6IT: MULTIL' TL'S

      SQL- Inset all

      Into student2 values(2#;a;#233)

      Into student1 values(1#;%;#133)

      Into student4 values(4#;!;#433)

      Sele!t Efo$ dept whee deptnoH23.

      "" This insets 4 ows

      EE *ou !an use $ulti ta%les with spe!ified fields# with dupli!ate ows# with !onditions#

    with fist and else !lauses5

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    29/326

    BUNCTIONS

    Bun!tions !an %e !ategoied as follows5

    1 Single ow fun!tions

    2 8oup fun!tions

    SIN8L' RO6 BUNCTIONS

    Single ow fun!tions !an %e !ategoied into five5 These will %e applied fo ea!h ow and podu!esindividual output fo ea!h ow5

    1  Nu$ei! fun!tions

    2 Sting fun!tions

    3 Date fun!tions

    4 Mis!ellaneous fun!tions

    5 Convesion fun!tions

     NUM'RIC BUNCTIONS

    1 %s

    2 Sign

    3 St

    4 Mod

    5  Nvl

    6 Aowe 7 '/p

    8 Ln

    9 Log

    10 Ceil

    11 Bloo 

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    30/326

    12 Round

    13 Tun& 

    14 itand

    15 8eatest

    16 Least

    17 Coales!e

    a) S

      %solute value is the $easue of the $agnitude of value5

    %solute value is alwa7s a positive nu$%e5

      S7nta/0 a%s (value)

      '/0

      SQL- sele!t a%s()# a%s(")# a%s(3)# a%s(null) fo$ dual.

      S() S(") S(3) S(NULL)

      """""""""" """""""""" """""""""" """""""""""""

      3

     %) SI8N

      Sign gives the sign of a value5

      S7nta/0 sign (value)

      '/0

      SQL- sele!t sign()# sign(")# sign(3)# sign(null) fo$ dual.

      SI8N() SI8N(") SI8N(3) SI8N(NULL)

    """""""""" """""""""" """""""""" """"""""""""""

      2 "2 3

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    31/326

    !) SQRT

      This will give the suae oot of the given value5

    S7nta/0 st (value) "" hee value $ust %e positive5

      '/0

      SQL- sele!t st(@)# st(3)# st(null)# st(2) fo$ dual.

      SQRT(@) SQRT(3) SQRT(NULL) SQRT(2)

    """""""""" """""""""" """"""""""""""" """"""""""

      1 3 2

    d) MOD

      This will give the e$ainde5

    S7nta/0 $od (value, divi!or )

      '/0

      SQL- sele!t $od(V#@)# $od(2#)# $od(null#null)# $od(3#3)# $od("V#@) fo$ dual.

      MOD(V#@) MOD(2#) MOD(NULL#NULL) MOD(3#3) MOD("V#@)

    """""""""""" """""""""" """"""""""""""""""""" """"""""""" """""""""""""

      4 2 3 "4

    e) N9L

      This will su%stitutes the spe!ified value in the pla!e of null values5

    S7nta/0 nvl (null_col, replacement_value)

      '/0

      SQL- sele!t E fo$ student. "" hee fo 4d ow $a&s value is null

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    32/326

      NO NM' MRFS

     """ """"""" """""""""

      2 a 233

      1 % 133

      4 !

    SQL- sele!t no# na$e# nvl($a&s#433) fo$ student.

     NO NM' N9L(MRFS#433)

    """ """"""" """""""""""""""""""""

      2 a 233

      1 % 133

      4 ! 433

    SQL- sele!t nvl(2#1)# nvl(1#4)# nvl(@#4)# nvl(#@) fo$ dual.

      N9L(2#1) N9L(1#4) N9L(@#4) N9L(#@)

      """""""""" """""""""" """""""""" """"""""""

      2 1 @

    SQL- sele!t nvl(3#3)# nvl(2#2)# nvl(null#null)# nvl(@#@) fo$ dual.

     

     N9L(3#3) N9L(2#2) N9L(null#null) N9L(@#@)

      """""""""" """""""""" """"""""""""""""" """"""""""

      3 2 @

    f) AO6'R 

      Aowe is the a%ilit7 to aise a value to a given e/ponent5

    S7nta/0 powe (value, eponent )

      '/0

      SQL- sele!t powe(1#)# powe(3#3)# powe(2#2)# powe(null#null)# powe(1#")

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    33/326

      fo$ dual.

     

    AO6'R(1#) AO6'R(3#3) AO6'R(2#2) AO6'R(NULL#NULL) AO6'R(1#")

    """""""""""""" """""""""""""" """"" """"""""" """"""""""""""""""""""" """""""""""""""

      41 2 2 53421

    g) '+A

      This will aise e value to the give powe5

      S7nta/0 e/p (value)

      '/0

      SQL- sele!t e/p(2)# e/p(1)# e/p(3)# e/p(null)# e/p("1) fo$ dual.

      '+A(2) '+A(1) '+A(3) '+A(NULL) '+A("1)

    """""""" """"""""" """""""" """"""""""""" """"""""""

    15V2W1W2W4 V54W32 2 524441W4

    h) LN

      This is %ased on natual o %ase e logaith$5

      S7nta/0 ln (value) "" hee value $ust %e geate than eo whi!h is positive onl75

      '/0

      SQL- sele!t ln(2)# ln(1)# ln(null) fo$ dual.

      LN(2) LN(1) LN(NULL)

    """"""" """"""" """"""""""""  3 542@V2W2

      Ln and '/p ae e!ipo!al to ea!h othe5

      '+A (4) H 1353W4

      LN (1353W4) H 4

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    34/326

    i) LO8

      This is %ased on 23 %ased logaith$5

      S7nta/0 log (23# value) "" hee value $ust %e geate than eo whi!h is positive onl75

      '/0

      SQL- sele!t log(23#233)# log(23#1)# log(23#2)# log(23#null) fo$ dual.

    LO8(23#233) LO8(23#1) LO8(23#2) LO8(23#NULL)

    """"""""""""""" """"""""""" """""""""""" """""""""""""""""

      1 543231 3

    LN (value) H LO8 ('+A(2)# value)

    SQL- sele!t ln(4)# log(e/p(2)#4) fo$ dual.

      LN(4) LO8('+A(2)#4)

    """"""" """""""""""""""""

    253W211 253W211

     J) C'IL

      This will podu!e a whole nu$%e that is geate than o eual to the spe!ified value5

      S7nta/0 !eil (value)

      '/0  SQL- sele!t !eil()# !eil(52)# !eil(")# !eil( "52)# !eil(3)# !eil(null) fo$ dual.

      C'IL() C'IL(52) C'IL(") C'IL("52) C'IL(3) C'IL(NULL)

    """"""""" """"""""""" """""""""" """""""""""" """""""" """"""""""""""

      " " 3

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    35/326

    &) BLOOR 

      This will podu!e a whole nu$%e that is less than o eual to the spe!ified value5

      S7nta/0 floo (value)

      '/0

      SQL- sele!t floo()# floo(52)# floo(")# floo( "52)# floo(3)# floo(null) fo$

    dual.

      BLOOR() BLOOR(52) BLOOR(") BLOOR("52) BLOOR(3) BLOOR(NULL)

    """"""""""" """"""""""""" """""""""""" """""""""""""" """"""""""" """"""""""""""""

    " " 3

    l) ROUND

      This will ounds nu$%es to a given nu$%e of digits of pe!ision5

      S7nta/0 ound (value, preci!ion)

      '/0

      SQL- sele!t ound(214514@)# ound(214514@#1)# ound(214514@#1) fo$ dual.

      ROUND(214514@) ROUND(214514@#3) ROUND(214514@#1) ROUND(214514@#1)

      """"""""""""""""""""" """""""""""""""""""""""" """"""""""""""""""""""" """""""""""""""""""""""

      214 214 214514 21451@

      SQL- sele!t ound(214514@#"2)# ound(214514@#"1)# ound(214514@#"4)#

    ound(214514@#"@) fo$ dual.

     ROUND(214514@#"2) ROUND(214514@#"1) ROUND(214514@#"4) ROUND(214514@#"@)

    """""""""""""""""""""""" """"""""""""""""""""""""" """""""""""""""""""""""" """"""""""""""""""""""""

      213 233 3 3

    SQL- sele!t ound(214#3)# ound(214#2)# ound(214#1) fo$ dual.

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    36/326

    ROUND(214#3) ROUND(214#2) ROUND(214#1)

    """"""""""""""""" """"""""""""""""" """"""""""""""""

      214 214 214

    SQL- sele!t ound("214#3)# ound("214#2)# ound("214#1) fo$ dual.

    ROUND("214#3) ROUND("214#2) ROUND("214#1)

    """""""""""""""""" """"""""""""""""" """""""""""""""""""

      "214 "214 "214

    SQL- sele!t ound(214#"2)# ound(214#"1)# ound(214#"4)# ound("214#"2)# ound(

      "214#"1)# ound("214#"4) fo$ dual.

    ROUND(214#"2) ROUND(214#"1) ROUND(214#"4) ROUND("214#"2) ROUND("214#"1)

    ROUND("214#"4)

      """"""""""""" """"""""""""" """"""""""""" """""""""""""" """""""""""""" """"""""""""""""""""""""""

      213 233 3 "213 "233 3

    SQL- sele!t ound(null#null)# ound(3#3)# ound(2#2)# ound("2#"2)# ound("1#"1)

    fo$ dual.

    ROUND(NULL#NULL) ROUND(3#3) ROUND(2#2) ROUND("2#"2) ROUND("1#"1)

    """"""""""""""""""""""" """""""""""""" """""""""""""" """""""""""""""" """"""""""""""""

      3 2 3 3

     

    $) TRUNC

    This will tun!ates o !hops off digits of pe!ision fo$ a nu$%e5

      S7nta/0 tun! (value, preci!ion)

      '/0

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    37/326

      SQL- sele!t tun!(214514@)# tun!(214514@#1)# tun!(214514@#1) fo$ dual.

    TRUNC(214514@) TRUNC(214514@#1) TRUNC(214514@#1)

    """"""""""""""""""""" """"""""""""""""""""""" """""""""""""""""""""""

      214 214514 214514

    SQL- sele!t tun!(214514@#"2)# tun!(214514@#"1)# tun!(214514@#"4)#

    tun!(214514@#"@) fo$ dual.

    TRUNC(214514@#"2) TRUNC(214514@#"1) TRUNC(214514@#"4) TRUNC(214514@#"@)

    """""""""""""""""""""""" """""""""""""""""""""""" """"""""""""""""""""""" """"""""""""""""""""""""

      213 233 3 3

    SQL- sele!t tun!(214#3)# tun!(214#2)# tun!(214#1) fo$ dual.

    TRUNC(214#3) TRUNC(214#2) TRUNC(214#1)

    """""""""""""""" """""""""""""""" """""""""""""""""

      214 214 214

    SQL- sele!t tun!("214#3)# tun!("214#2)# tun!("214#1) fo$ dual.

    TRUNC("214#3) TRUNC("214#2) TRUNC("214#1)

    """"""""""""""""" """"""""""""""""" """""""""""""""""

      "214 "214 "214

    SQL- sele!t tun!(214#"2)# tun!(214#"1)# tun!(214#"4)# tun!("214#"2)# tun!(

      "214#1)# tun!("214#"4) fo$ dual.

    TRUNC(214#"2) TRUNC(214#"1) TRUNC(214#"4) TRUNC("214#"2) TRUNC("214#1) TRUNC("

    214#"4)

    """"""""""""" """"""""""""" """"""""""""" """""""""""""" """"""""""""" """""""""""""""""""""""""""""""""

      213 233 3 "213 "214 3

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    38/326

    SQL- sele!t tun!(null#null)# tun!(3#3)# tun!(2#2)# tun!("2#"2)# tun!("1#"1) fo$

    dual.

    TRUNC(NULL#NULL) TRUNC(3#3) TRUNC(2#2) TRUNC("2#"2) TRUNC("1#"1)

    """"""""""""""""""""""" """"""""""""" """"""""""""" """"""""""""""" """"""""""""""""

      3 2 3 3

    n) ITND

      This will pefo$ %itwise and opeation5

      S7nta/0 %itand (value1, value2)

      '/0

      SQL- sele!t %itand(1#4)# %itand(3#3)# %itand(2#2)# %itand(null#null)# %itand("1#"4)

    fo$ dual.

    ITND(1#4) ITND(3#3) ITND(2#2) ITND(NULL#NULL) ITND("1#"4)

    """""""""""""" """"""""""""""" """""""""""""" """""""""""""""""""""""" """""""""""""""""

      1 3 2 "@

    o) 8R'T'ST

      This will give the geatest nu$%e5

      S7nta/0 geatest (value1, value2, value3 … valuen)

      '/0

      SQL- sele!t geatest(2# 1# 4)# geatest("2# "1# "4) fo$ dual.

    8R'T'ST(2#1#4) 8R'T'ST("2#"1#"4)

    """""""""""""""""""" """""""""""""""""""""""

      4 "2

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    39/326

    1 If all the values ae eos then it will displa7 eo5

    2 If all the paa$etes ae nulls then it will displa7 nothing5

    3 If an7 of the paa$etes is null it will displa7 nothing5

     p) L'ST

      This will give the least nu$%e5

      S7nta/0 least (value1, value2, value3 … valuen)

      '/0

      SQL- sele!t least(2# 1# 4)# least("2# "1# "4) fo$ dual.

    L'ST(2#1#4) L'ST("2#"1#"4)

    """""""""""""""""""" """""""""""""""""""""""

      2 "4

    4 If all the values ae eos then it will displa7 eo5

    5 If all the paa$etes ae nulls then it will displa7 nothing5

    6 If an7 of the paa$etes is null it will displa7 nothing5

    ) COL'SC'

      This will etun fist non"null value5

      S7nta/0 !oales!e (value1, value2, value3 … valuen)

      '/0

      SQL- sele!t !oales!e(2#1#4)# !oales!e(null#1#null#) fo$ dual.

    COL'SC'(2#1#4) COL'SC'(NULL#1#NULL#)

    """"""""""""""""""" """""""""""""""""""""""""""""""

      2 1

    STRIN8 BUNCTIONS

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    40/326

    18 Init!ap

    19 Uppe 

    20 Lowe 

    21 Length

    22 Rpad

    23 Lpad

    24 Lti$

    25 Rti$

    26 Ti$

    27 Tanslate

    28 Repla!e

    29 Sounde/

    30 Con!at ( K XX K Con!atenation opeato)

    31 s!ii

    32 Ch 

    33 Su%st 

    34 Inst 

    35 De!ode

    36 8eatest

    37 Least

    38 Coales!e

    a) INITCA

      This will !apitalie the initial lette of the sting5

      S7nta/0 init!ap ( !trin" )

      '/0

      SQL- sele!t init!ap(=!o$pute=) fo$ dual.

    INITCA

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    41/326

    """""""""""

    Co$pute 

     %) UAA'R 

      This will !onvet the sting into uppe!ase5

      S7nta/0 uppe ( !trin" )

      '/0

      SQL- sele!t uppe(=!o$pute=) fo$ dual.

    UAA'R 

    """""""""""

    COMAUT'R 

    !) LO6'R 

      This will !onvet the sting into lowe!ase5

      S7nta/0 lowe ( !trin" )

      '/0

      SQL- sele!t lowe(=COMAUT'R=) fo$ dual.

    LO6'R 

    """""""""""

    !o$pute 

    d) L'N8T:

      This will give length of the sting5

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    42/326

      S7nta/0 length ( !trin" )

      '/0

      SQL- sele!t length(=!o$pute=) fo$ dual.

    L'N8T:

    """""""""""

      W

    e) RAD

      This will allows 7ou to pad the ight side of a !olu$n with an7 set of !haa!tes5

      S7nta/0 pad ( !trin", len"t *, paddin"_car+)

      '/0

      SQL- sele!t pad(=!o$pute=#2#=E=)# pad(=!o$pute=#2#=EY=) fo$ dual.

    RAD(=COMAUT'R= RAD(=COMAUT'R=

    """""""""""""""""""""" """"""""""""""""""""""

    !o$puteEEEEEEE !o$puteEYEYEYE

    "" Default padding !haa!te was %lan& spa!e5

    f) LAD

      This will allows 7ou to pad the left side of a !olu$n with an7 set of !haa!tes5

      S7nta/0 lpad ( !trin", len"t *, paddin"_car+)

      '/0

      SQL- sele!t lpad(=!o$pute=#2#=E=)# lpad(=!o$pute=#2#=EY=) fo$ dual.

    LAD(=COMAUT'R= LAD(=COMAUT'R=

    """"""""""""""""""""" """""""""""""""""""""

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    43/326

    EEEEEEE!o$pute EYEYEYE!o$pute 

    "" Default padding !haa!te was %lan& spa!e5

    g) LTRIM

      This will ti$ off unwanted !haa!tes fo$ the left end of sting5

      S7nta/0 lti$ ( !trin" *,unwanted_car!+)

      '/0

      SQL- sele!t lti$(=!o$pute=#=!o=)# lti$(=!o$pute=#=!o$=) fo$ dual.

    LTRIM( LTRIM

    """""""" """""""""

    $pute pute 

    SQL- sele!t lti$(=!o$pute=#=pute=)# lti$(=!o$pute=#=o$pute=) fo$ dual.

    LTRIM(=C LTRIM(=C

    """""""""" """"""""""

    !o$pute !o$pute 

     

    "" If 7ou haven;t spe!if7 an7 unwanted !haa!tes it will displa7 entie sting5

    h) RTRIM

      This will ti$ off unwanted !haa!tes fo$ the ight end of sting5

      S7nta/0 ti$ ( !trin", * unwanted_car!+)

      '/0

      SQL- sele!t ti$(=!o$pute=#=e=)# ti$(=!o$pute=#=te=) fo$ dual.

    RTRIM( RTRIM

    """""""" """""""""

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    44/326

    !o$put !o$pu

    SQL- sele!t ti$(=!o$pute=#=!o$put;)# ti$(=!o$pute=#=!o$pute=) fo$ dual.

    RTRIM(=C RTRIM(=C

    """""""""" """"""""""

    !o$pute !o$pute 

      "" If 7ou haven;t spe!if7 an7 unwanted !haa!tes it will displa7 entie sting5

    i) TRIM

      This will ti$ off unwanted !haa!tes fo$ the %oth sides of sting5

      S7nta/0 ti$ (unwanted_car! fo$ !trin" )

      '/0

      SQL- sele!t ti$( =i= fo$ =indiani=) fo$ dual.

    TRIM(

    """""

    ndian

     

    SQL- sele!t ti$( leading=i= fo$ =indiani=) fo$ dual. "" this will wo& as LTRIM

    TRIM(L

    """"""

    ndiani

    SQL- sele!t ti$( tailing=i= fo$ =indiani=) fo$ dual. "" this will wo& as RTRIM

    TRIM(T

    """"""

    Indian

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    45/326

     J) TRNSLT'

      This will epla!e the set of !haa!tes# !haa!te %7 !haa!te5

      S7nta/0 tanslate ( !trin", old_car!, new_car!)

      '/0

      SQL- sele!t tanslate(=india=#=in=#=/7=) fo$ dual.

    TRNS

    """"""""

    /7d/a

    &) R'ALC'

      This will epla!e the set of !haa!tes# sting %7 sting5

      S7nta/0 epla!e ( !trin", old_car! *, new_car!+)

      '/0

      SQL- sele!t epla!e(=india=#=in=#=/7=)# epla!e(Kindia;#;in;) fo$ dual.

    R'ALC' R'ALC'

    """"""""""" """""""""""

    +7dia dia

    l) SOUND'+

      This will %e used to find wods that sound li&e othe wods# e/!lusivel7 used in whee

    !lause5

      S7nta/0 sounde/ ( !trin" )

      '/0

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    46/326

      SQL- sele!t E fo$ e$p whee sounde/(ena$e) H sounde/(=SMIT=).

      'MANO 'NM' >O M8R :IR'DT' SL D'ATNO

      """""""" """""""" """"" """"" """""""""""" """"""""" """"""""""

    V4 SMIT: CL'RF V31 2V"D'C"W3 33 13

    $) CONCT

      This will %e used to !o$%ine two stings onl75

      S7nta/0 !on!at ( !trin"1, !trin"2)

      '/0

      SQL- sele!t !on!at(=!o$pute=#= opeato=) fo$ dual.

    CONCT(=COMAUT'R=

    """""""""""""""""""""""""

    !o$pute opeato 

      If 7ou want to !o$%ine $oe than two stings 7ou have to use !on!atenation

    opeato(XX)5

      SQL- sele!t =how= XX = ae= XX = 7ou= fo$ dual.

    =:O6=XX=R'

    """""""""""""""

    how ae 7ou

    n) SCII

      This will etun the de!i$al epesentation in the data%ase !haa!te set of the fist

    !haa!te of the sting5

      S7nta/0 as!ii ( !trin" )

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    47/326

      '/0

      SQL- sele!t as!ii(=a=)# as!ii(=apple=) fo$ dual.

    SCII(==) SCII(=AAL'=)

    """""""""""" """"""""""""""""""

      V V

    o) C:R 

      This will etun the !haa!te having the %ina7 euivalent to the sting in eithe the

    data%ase !haa!te set o the national !haa!te set5

      S7nta/0 !h (number )

      '/0

      SQL- sele!t !h(V) fo$ dual.

    C:R 

    """""

      a

     p) SUSTR 

      This will %e used to e/ta!t su%stings5

    S7nta/0 su%st ( !trin", !tart_cr_count *, no_o'_car!+)

      '/0SQL- sele!t su%st(=!o$pute=#1)# su%st(=!o$pute=#1#)# su%st(=!o$pute=#4#V)

    fo$ dual.

    SUSTR( SUST SUSTR 

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    48/326

    """""""""" """"""" """"""""o$pute o$put $pute 

    1 If no_o'_car! paa$ete is negative then it will displa7 nothing5

    2 If %oth paa$etes e/!ept !trin"  ae null o eos then it will displa7 nothing5

    3 If no_o'_car! paa$ete is geate than the length of the sting then it ignoes and

    !al!ulates %ased on the oginal sting length5

    4 If !tart_cr_count  is negative then it will e/ta!t the su%sting fo$ ight end5

    2 1 4 @ V W

    C O M A U T ' R  

      "W "V " " "@ "4 "1 "2

    ) INSTR 

      This will allows 7ou fo sea!hing though a sting fo set of !haa!tes5

    S7nta/0 inst ( !trin", !earc_!tr *, !tart_cr_count *, occurrence+ +)

      '/0

      SQL- sele!t inst(=info$ation=#=o=#@#2)# inst(=info$ation=#=o=#@#1) fo$ dual.

    INSTR(=INBORMTION=#=O=#@#2) INSTR(=INBORMTION=#=O=#@#1)

    """""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""

      @ 23

    1 If 7ou ae not spe!if7ing !tart_cr_count  and occurrence then it will stat

    sea!h fo$ the %eginning and finds fist o!!uen!e onl75

    2 If %oth paa$etes !tart_cr_count  and occurrence ae null# it will displa7

    nothing5

    ) D'COD'

      De!ode will a!t as value %7 value su%stitution5

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    49/326

      Bo eve7 value of field# it will !he!&s fo a $at!h in a seies of if?then tests5

    S7nta/0 de!ode (value, i'1, ten1, i'2, ten2, ……. el!e).

      '/0

      SQL- sele!t sal# de!ode(sal#33#=Low=#333#=:igh=#=Mediu$=) fo$ e$p.

      SL D'COD'

      """"" """""""""

      33 Low

      133 Mediu$

      1333 Mediu$

      433 Mediu$

      4333 Mediu$

      333 :igh

      @333 Mediu$

      333 :igh

      2W33 Mediu$

      2133 Mediu$

      1333 Mediu$

      1V33 Mediu$

      1133 Mediu$

      4133 Mediu$

    SQL- sele!t de!ode(2#2#4)# de!ode(2#1#4#@#@#) fo$ dual.

    D'COD'(2#2#4) D'COD'(2#1#4#@#@#)""""""""""""""""" """"""""""""""""""""""""  4

    1 If the nu$%e of paa$etes ae odd and diffeent then de!ode will displa7

    nothing5

    2 If the nu$%e of paa$etes ae even and diffeent then de!ode will displa7 last

    value5

    3 If all the paa$etes ae null then de!ode will displa7 nothing5

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    50/326

    4 If all the paa$etes ae eos then de!ode will displa7 eo5

    s) 8R'T'ST

      This will give the geatest sting5

      S7nta/0 geatest ( !trn"1, !trin"2, !trin"3 … !trin"n)

      '/0

      SQL- sele!t geatest(=a=# =%=# =!=)# geatest(=satish=#=sinu=#=sa&eth=) fo$ dual.

    8R'T 8R'T""""""" """""""

      ! sinu

    7 If all the paa$etes ae nulls then it will displa7 nothing5

    8 If an7 of the paa$etes is null it will displa7 nothing5

    t) L'ST

      This will give the least sting5

      S7nta/0 geatest ( !trn"1, !trin"2, !trin"3 … !trin"n)

      '/0

      SQL- sele!t least(=a=# =%=# =!=)# least(=satish=#=sinu=#=sa&eth=) fo$ dual.

    L'ST L'ST

    """"""" """""""

      a sa&eth

    9 If all the paa$etes ae nulls then it will displa7 nothing5

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    51/326

    10 If an7 of the paa$etes is null it will displa7 nothing5

    u) COL'SC'

      This will gives the fist non"null sting5

      S7nta/0 !oales!e ( !trn"1, !trin"2, !trin"3 … !trin"n)

      '/0

      SQL- sele!t !oales!e(=a=#=%=#=!=)# !oales!e(null#=a=#null#=%=) fo$ dual.

    COL'SC' COL'SC'

    """"""""""" """""""""""

      a a

    DT' BUNCTIONS

    39 S7sdate

    40 Cuentdate

    41 Cuentti$esta$p

    42 S7sti$esta$p

    43 Lo!alti$esta$p

    44 D%ti$eone

    45 Sessionti$eone

    46 To!ha 

    47 Todate

    48 dd$onths

    49 Months%etween

    50  Ne/tda7

    51 Lastda7

    52 '/ta!t

    53 8eatest

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    52/326

    54 Least

    55 Round

    56 Tun!

    57  Newti$e

    58 Coales!e

    Oa!le default date fo$at is DD"MON"**5

    6e !an !hange the default fo$at to ou desied fo$at %7 using the following !o$$and5

    SQL- alte session set nlsdatefo$at H KDD"MONT:"****;.

      ut this will e/pie on!e the session was !losed5

    a) S*SDT'

      This will give the !uent date and ti$e5

      '/0

      SQL- sele!t s7sdate fo$ dual.

    S*SDT'

    """""""""""

    1@"D'C"3

     %) CURR'NTDT'

      This will etuns the !uent date in the session;s ti$eone5

      '/0

      SQL- sele!t !uentdate fo$ dual.

    CURR'NTDT'

    """"""""""""""""""

      1@"D'C"3

    !) CURR'NTTIM'STMA

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    53/326

      This will etuns the !uent ti$esta$p with the a!tive ti$e one info$ation5

      '/0

      SQL- sele!t !uentti$esta$p fo$ dual.

    CURR'NTTIM'STMA

    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

    1@"D'C"3 345@15@254W44 M G3043

    d) S*STIM'STMA

      This will etuns the s7ste$ date# in!luding fa!tional se!onds and ti$e one of the

    data%ase5

      '/0

      SQL- sele!t s7sti$esta$p fo$ dual.

    S*STIM'STMA

    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

    1@"D'C"3 345@5425W433 M G3043

    e) LOCLTIM'STMA

      This will etuns lo!al ti$esta$p in the a!tive ti$e one info$ation# with no ti$e

    one info$ation shown5

      '/0

      SQL- sele!t lo!alti$esta$p fo$ dual.

    LOCLTIM'STMA"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""1@"D'C"3 345@@52W531WV@ M

    f) DTIM'ZON'

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    54/326

      This will etuns the !uent data%ase ti$e one in UTC fo$at5 (Coodinated Univesal

    Ti$e)

      '/0

      SQL- sele!t d%ti$eone fo$ dual.

    DTIM'ZON'"""""""""""""""  "3V033

    g) S'SSIONTIM'ZON'

      This will etuns the value of the !uent session;s ti$e one5

      '/0

      SQL- sele!t sessionti$eone fo$ dual.

    S'SSIONTIM'ZON'

    """"""""""""""""""""""""""""""""""""

    G3043

     h) TOC:R 

      This will %e used to e/ta!t vaious date fo$ats5

      The availa%le date fo$ats as follows5

      S7nta/0 to!ha (date# 'ormat )

     

    DT' BORMTS

    D "" No of da7s in wee&  

    DD "" No of da7s in $onth

    DDD "" No of da7s in 7ea  

    MM "" No of $onth

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    55/326

    MON "" Thee lette a%%eviation of $onth

    MONT: "" Bull7 spelled out $onth

    RM "" Ro$an nu$eal $onth

    D* "" Thee lette a%%eviated da7

    D* "" Bull7 spelled out da7

    * "" Last one digit of the 7ea  

    ** "" Last two digits of the 7ea  

    *** "" Last thee digits of the 7ea  

    **** "" Bull fou digit 7ea  

    S**** "" Signed 7ea  

    I "" One digit 7ea fo$ ISO standad

    I* "" Two digit 7ea fo$ ISO standad

    I** "" Thee digit 7ea fo$ ISO standad

    I*** "" Bou digit 7ea fo$ ISO standad

    *# *** "" *ea with !o$$a

    *'R "" Bull7 spelled out 7ea  

    CC "" Centu7

    Q "" No of uates

    6 "" No of wee&s in $onth

    66 "" No of wee&s in 7ea  

    I6 "" No of wee&s in 7ea fo$ ISO standad

    :: "" :ous

    MI "" Minutes

    SS "" Se!onds

    BB "" Ba!tional se!onds

    M o AM "" Displa7s M o AM depending upon ti$e of da7

    5M o A5M "" Displa7s 5M o A5M depending upon ti$e of da7

    D o C "" Displa7s D o C depending upon the date

    5D o 5C "" Displa7s D o C depending upon the dateBM "" Aefi/ to $onth o da7# suppesses padding of $onth o da7

    T: "" Suffi/ to a nu$%e  

    SA "" suffi/ to a nu$%e to %e spelled out

    SAT: "" Suffi/ !o$%ination of T: and SA to %e %oth spelled out

    T:SA "" sa$e as SAT:

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    56/326

    '/0

      SQL- sele!t to!ha(s7sdate#=dd $onth 7777 hh0$i0ss a$ d7=) fo$ dual.

    TOC:R(S*SDT'#=DD MONT: ****::0MI

    """"""""""""""""""""""""""""""""""""""""""""""""""""

    1@ de!e$%e 133 31034014 p$ sun

      SQL- sele!t to!ha(s7sdate#=dd $onth 7ea=) fo$ dual.

    TOC:R(S*SDT'#=DDMONT:*'R=)

    """""""""""""""""""""""""""""""""""""""""""""""""""""""

    1@ de!e$%e two thousand si/

      SQL- sele!t to!ha(s7sdate#=dd f$$onth 7ea=) fo$ dual.

    TOC:R(S*SDT'#=DD BMMONT: *'R=)

    """""""""""""""""""""""""""""""""""""""""""""""""""""""

    1@ de!e$%e two thousand si/

      SQL- sele!t to!ha(s7sdate#=ddth DDT:=) fo$ dual.

    TOC:R(S

    """"""""""""

    1@th 1@T:

      SQL- sele!t to!ha(s7sdate#=ddspth DDSAT:=) fo$ dual.

    TOC:R(S*SDT'#=DDSAT:DDSAT:

    """"""""""""""""""""""""""""""""""""""""""

    twent7"fouth T6'NT*"BOURT:

      SQL- sele!t to!ha(s7sdate#=ddsp Ddsp DDSA =) fo$ dual.

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    57/326

    TOC:R(S*SDT'#=DDSADDSADDSA=)

    """"""""""""""""""""""""""""""""""""""""""""""""

    twent7"fou Twent7"Bou T6'NT*"BOUR 

    i) TODT'

      This will %e used to !onvet the sting into data fo$at5

      S7nta/0 todate (date)

      '/0

      SQL- sele!t to!ha(todate(=1@?de!?133=#=dd?$on?7777=)# =dd E $onth E da7=)

    fo$ dual.

    TOC:R(TODT'(=1@?D'C?13

    """"""""""""""""""""""""""

    1@ E de!e$%e E Sunda7

    "" If 7ou ae not using to!ha oa!le will displa7 output in default date fo$at5

     J) DDMONT:S

      This will add the spe!ified $onths to the given date5

      S7nta/0 add$onths (date, no_o'_mont!)

      '/0

      SQL- sele!t add$onths(todate(=22"Jan"23=#=dd"$on"7777=)# ) fo$ dual.

    DDMONT:S

    """"""""""""""""

    22">UN"3

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    58/326

    SQL- sele!t add$onths(todate(=22"Jan"23=#=dd"$on"7777=)# ") fo$ dual.

    DDMONT:

    """""""""""""""

    22"U8"W

    1 If no_o'_mont! is eo then it will displa7 the sa$e date5

    2 If no_o'_mont! is null then it will displa7 nothing5

    &) MONT:S'T6''N

      This will give diffeen!e of $onths %etween two dates5

      S7nta/0 $onths%etween (date1, date2)

      '/0

      SQL- sele!t $onths%etween(todate(=22"aug"23=#=dd"$on"7777=)# todate(=22"

      Jan"23=#=dd"$on"7777=)) fo$ dual.

     

    MONT:S'T6''N(TODT'(=22"U8"23=#=DD"MON"****=)#TODT'(=22">N"

    23=#=DD"MON"****=))

    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

      V

      SQL- sele!t $onths%etween(todate(=22"Jan"23=#=dd"$on"7777=)# todate(=22"

      aug"23=#=dd"$on"7777=)) fo$ dual.

     

    MONT:S'T6''N(TODT'(=22">N"23=#=DD"MON"****=)#TODT'(=22"U8"

    23=#=DD"MON"****=))

    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

      "V

    l) N'+TD*

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    59/326

      This will podu!e ne/t da7 of the given da7 fo$ the spe!ified date5

      S7nta/0 ne/tda7 (date, day)

      '/0

      SQL- sele!t ne/tda7(todate(=1@"de!"133=#=dd"$on"7777=)#=sun=) fo$ dual.

     N'+TD*(

    """""""""""""

    42"D'C"3

    "" If the da7 paa$ete is null then it will displa7 nothing5

    $) LSTD*

      This will podu!e last da7 of the given date5

      S7nta/0 lastda7 (date)

      '/0

      SQL- sele!t lastda7(todate(=1@"de!"133=#=dd"$on"7777=)#=sun=) fo$ dual.

    LSTD*(

    """""""""""""

    42"D'C"3

    n) '+TRCT

      This is used to e/ta!t a potion of the date value5

      S7nta/0 e/ta!t ((7ea X $onth X da7 X hou X $inute X se!ond)# date)

      '/0

      SQL- sele!t e/ta!t(7ea fo$ s7sdate) fo$ dual.

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    60/326

    '+TRCT(*'RBROMS*SDT')

    """"""""""""""""""""""""""""""""""""

      133

    "" *ou !an e/ta!t onl7 one value at a ti$e5

    o) 8R'T'ST

      This will give the geatest date5

      S7nta/0 geatest (date1, date2, date3 … daten)

      '/0

      SQL- sele!t geatest(todate(=22"Jan"3=#=dd"$on"77=)#todate(=22"$a"3=#=dd"

      $on"77=)#todate(=22"ap"3=#=dd"$on"77=)) fo$ dual.

     

    8R'T'ST(

      """""""""""""

      22"AR"3

     p) L'ST

      This will give the least date5

      S7nta/0 least (date1, date2, date3 … daten)

      '/0

      SQL- sele!t least(todate(=22"Jan"3=#=dd"$on"77=)#todate(=22"$a"3=#=dd"$on"

      77=)#todate(=22"ap"3=#=dd"$on"77=)) fo$ dual.

      L'ST(

      """""""""""""

      22">N"3

    ) ROUND

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    61/326

      Round will ounds the date to whi!h it was eual to o geate than the given date5

      S7nta/0 ound (date, ( da7 X $onth X 7ea  ))

      If the se!ond paa$ete was year  then ound will !he!&s the $onth of the given date in

    the following anges5

    >N "" >UN

    >UL "" D'C

      If the $onth falls %etween >N and >UN then it etuns the fist da7 of the !uent 7ea5

      If the $onth falls %etween >UL and D'C then it etuns the fist da7 of the ne/t 7ea5

      If the se!ond paa$ete was mont then ound will !he!&s the da7 of the given date in

    the following anges5

    2 "" 2

    2 "" 42

      If the da7 falls %etween 2 and 2 then it etuns the fist da7 of the !uent $onth5

      If the da7 falls %etween 2 and 42 then it etuns the fist da7 of the ne/t $onth5

      If the se!ond paa$ete was day then ound will !he!&s the wee& da7 of the given date

    in the following anges5

    SUN "" 6'D

    T:U "" SUN

      If the wee& da7 falls %etween SUN and 6'D then it etuns the pevious sunda75

      If the wee&da7 falls %etween T:U and SUN then it etuns the ne/t sunda75

    1 If the se!ond paa$ete was null then it etuns nothing5

    2 If the 7ou ae not spe!if7ing the se!ond paa$ete then ound will esets the ti$e to the %egining

    of the !uent da7 in !ase of use spe!ified date5

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    62/326

    3 If the 7ou ae not spe!if7ing the se!ond paa$ete then ound will esets the ti$e to the %egining

    of the ne/t da7 in !ase of s7sdate5

     

    '/0

      SQL- sele!t ound(todate(=1@"de!"3@=#=dd"$on"77=)#=7ea=)# ound(todate(=22"$a"

      3=#=dd"$on"77=)#=7ea=) fo$ dual.

    ROUND(TO ROUND(TO 

    """""""""""" """""""""""""""

    32">N"3 32">N"3

      SQL- sele!t ound(todate(=22"Jan"3@=#=dd"$on"77=)#=$onth=)# ound(todate(=2W"

      Jan"3@=#=dd"$on"77=)#=$onth=) fo$ dual.

    ROUND(TO ROUND(TO 

    """"""""""""" """""""""""""""

    32">N"3@ 32"B'"3@

      SQL- sele!t ound(todate(=1"de!"3=#=dd"$on"77=)#=da7=)# ound(todate(=1"de!"

      3=#=dd"$on"77=)#=da7=) fo$ dual.

     

    ROUND(TO ROUND(TO 

    """""""""""""" """"""""""""""

    1@"D'C"3 42"D'C"3

      SQL- sele!t to!ha(ound(todate(=1@"de!"3=#=dd"$on"77=))# =dd $on 7777

    hh0$i0ss a$=) fo$ dual.

    TOC:R(ROUND(TODT'(=

    """""""""""""""""""""""""""""""""

    1@ de! 133 21033033 a$

    ) TRUNC

      Tun! will !hops off the date to whi!h it was eual to o less than the given date5

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    63/326

      S7nta/0 tun! (date, ( da7 X $onth X 7ea  ))

    1 If the se!ond paa$ete was year  then it alwa7s etuns the fist da7 of the !uent 7ea5

    2 If the se!ond paa$ete was mont then it alwa7s etuns the fist da7 of the !uent $onth5

    3 If the se!ond paa$ete was day then it alwa7s etuns the pevious sunda75

    4 If the se!ond paa$ete was null then it etuns nothing5

    5 If the 7ou ae not spe!if7ing the se!ond paa$ete then tun& will esets the ti$e to the %egining

    of the !uent da75

      '/0

      SQL- sele!t tun!(todate(=1@"de!"3@=#=dd"$on"77=)#=7ea=)# tun!(todate(=22"$a"

      3=#=dd"$on"77=)#=7ea=) fo$ dual.

    TRUNC(TO TRUNC(TO 

    """"""""""""" """"""""""""""

    32">N"3@ 32">N"3

      SQL- sele!t tun!(todate(=22"Jan"3@=#=dd"$on"77=)#=$onth=)# tun!(todate(=2W"Jan"

      3@=#=dd"$on"77=)#=$onth=) fo$ dual.

    TRUNC(TO TRUNC(TO 

    """"""""""""" """""""""""""

    32">N"3@ 32">N"3@

     

    SQL- sele!t tun!(todate(=1"de!"3=#=dd"$on"77=)#=da7=)# tun!(todate(=1"de!"

      3=#=dd"$on"77=)#=da7=) fo$ dual.

      TRUNC(TO TRUNC(TO 

    """"""""""""" """"""""""""""

    1@"D'C"3 1@"D'C"3

     

    SQL- sele!t to!ha(tun!(todate(=1@"de!"3=#=dd"$on"77=))# =dd $on 7777 hh0$i0ss

    a$=) fo$ dual.

    TOC:R(TRUNC(TODT'(=

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    64/326

    """""""""""""""""""""""""""""""""

    1@ de! 133 21033033 a$

    s) N'6TIM'

      This will give the desied ti$eone;s date and ti$e5

      S7nta/0 newti$e (date, current_timeone, de!ired_timeone)

      vaila%le ti$eones ae as follows5

      TIM'ZON'S

    ST?DT "" tlanti! standad?da7 light ti$e

    ST?DT "" eing standad?da7 light ti$e

    CST?CDT "" Cental standad?da7 light ti$e

    'ST?'DT "" 'asten standad?da7 light ti$e

    8MT "" 8eenwi!h $ean ti$e

    :ST?:DT "" las&a":awaii standad?da7 light ti$e

    MST?MDT "" Mountain standad?da7 light ti$e

     NST "" Newfoundland standad ti$e

    AST?ADT "" Aa!ifi! standad?da7 light ti$e

    *ST?*DT "" *u&on standad?da7 light ti$e

      '/0

      SQL- sele!t to!ha(newti$e(s7sdate#=g$t=#=7st=)#=dd $on 7777 hh0$i0ss a$=) fo$

    dual.

    TOC:R(N'6TIM'(S*SDT

    """""""""""""""""""""""""""""""""""

    1@ de! 133 3102013 p$

      SQL- sele!t to!ha(newti$e(s7sdate#=g$t=#=est=)#=dd $on 7777 hh0$i0ss a$=) fo$

    dual.

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    65/326

    TOC:R(N'6TIM'(S*SDT

    """""""""""""""""""""""

    1@ de! 133 30201 p$

    t) COL'SC'

      This will give the fist non"null date5

      S7nta/0 !oales!e (date1, date2, date3 … daten)

      '/0

      SQL- sele!t !oales!e(=21"Jan"3=#=24"Jan"=)# !oales!e(null#=21"Jan"3=#=14"$a"

      W=#null) fo$ dual.

    COL'SC'( COL'SC'(

    """"""""""""" """"""""""""

    21"Jan"3 21"Jan"3

    MISC'LLN'OUS BUNCTIONS

    59 Uid

    60 Use 

    61 9sie

    62 Ran& 

    63 Densean& 

    a) UID

      This will etuns the intege value !oesponding to the use !uentl7 logged in5

      '/0

      SQL- sele!t uid fo$ dual.

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    66/326

      UID

    """"""""""

      42

     %) US'R 

      This will etuns the login;s use na$e5

      '/0

      SQL- sele!t use fo$ dual.

    US'R 

    """"""""""""""""

    SF'T:

    !) 9SIZ'

      This will etuns the nu$%e of %7tes in the e/pession5

      '/0

      SQL- sele!t vsie(214)# vsie(=!o$pute=)# vsie(=21"Jan"3=) fo$ dual.

    9SIZ'(214) 9SIZ'(=COMAUT'R=) 9SIZ'(=21">N"3=)

    """"""""""""" """"""""""""""""""""""" """"""""""""""""""""""

      4 W

    d) RNF 

      This will give the non"seuential an&ing5

      '/0

      SQL- sele!t ownu$#sal fo$ (sele!t sal fo$ e$p ode %7 sal des!).

      RO6NUM SL

      """""""""" """"""""""

      2 333

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    67/326

      1 4333

      4 4333

      @ 1V

      1W3

      1@3

      V 233

      W 233

      2433

      23 213

      22 213

      21 2233

      24 2333

      2@ 3

      2 W33

      SQL- sele!t an&(1V) within goup(ode %7 sal des!) fo$ e$p.

    RNF(1V)6IT:IN8ROUA(ORD'R*SLD'SC)

    """""""""""""""""""""""""""""""""""""""""""""""""""""""""

      @

    d) D'NS'RNF 

      This will give the seuential an&ing5

     

    '/0

      SQL- sele!t densean&(1V) within goup(ode %7 sal des!) fo$ e$p.

    D'NS'RNF(1V)6IT:IN8ROUA(ORD'R*SLD'SC)"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

      4

    CON9'RSION BUNCTIONS

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    68/326

    64 intonu$

    65 Chatoowid

    66 Rowidto!ha 

    67 Tonu$%e 

    68 To!ha 

    69 Todate

    a) INTONUM

      This will !onvet the %ina7 value to its nu$ei!al euivalent5

      S7nta/0 %intonu$( binary_bit!)

      '/0

      SQL- sele!t %intonu$(2#2#3) fo$ dual.

    INTONUM(2#2#3)

    """"""""""""""""""""""""

     

    1 If all the %its ae eo then it podu!es eo5

    2 If all the %its ae null then it podu!es an eo5

     %) C:RTORO6ID

      This will !onvet a !haa!te sting to a!t li&e an intenal oa!le ow identifie o owid5

    !) RO6IDTOC:R 

      This will !onvet an intenal oa!le ow identifie o owid to !haa!te sting5

    d) TONUM'R 

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    69/326

      This will !onvet a !ha o va!ha to nu$%e5

    e) TOC:R 

      This will !onvet a nu$%e o date to !haa!te sting5

    f) TODT'

      This will !onvet a nu$%e# !ha o va!ha to a date5

    8ROUA BUNCTIONS

    70 Su$

    71 vg

    72 Ma/

    73 Min

    74 Count

    8oup fun!tions will %e applied on all the ows %ut podu!es single output5

    a) SUM

      This will give the su$ of the values of the spe!ified !olu$n5

      S7nta/0 su$ (column)

      '/0

      SQL- sele!t su$(sal) fo$ e$p.

      SUM(SL)

      """"""""""

      4W33

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    70/326

     %) 98

      This will give the aveage of the values of the spe!ified !olu$n5

      S7nta/0 avg (column)

      '/0

      SQL- sele!t avg(sal) fo$ e$p.

      98(SL)

      """""""""""""""

      1VV52@1W

    !) M+

      This will give the $a/i$u$ of the values of the spe!ified !olu$n5

      S7nta/0 $a/ (column)

      '/0

      SQL- sele!t $a/(sal) fo$ e$p.

      M+(SL)

      """"""""""

      333

      d) MIN

      This will give the $ini$u$ of the values of the spe!ified !olu$n5

      S7nta/0 $in (column)

      '/0

      SQL- sele!t $in(sal) fo$ e$p.

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    71/326

      MIN(SL)

      """"""""""

      33

    e) COUNT

      This will give the !ount of the values of the spe!ified !olu$n5

      S7nta/0 !ount (column)

      '/0

      SQL- sele!t !ount(sal)#!ount(E) fo$ e$p.

    COUNT(SL) COUNT(E)

    """""""""""""" """"""""""""

      2@ 2@

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    72/326

    CONSTRINTS

    Constaints ae !ategoied as follows5

    Do$ain integit7 !onstaints

    1  Not null

    2 Che!& 

    'ntit7 integit7 !onstaints

    1 Uniue

    2 Ai$a7 &e7

    Refeential integit7 !onstaints

    1 Boeign &e7

    Constaints ae alwa7s atta!hed to a !olu$n not a ta%le5

    6e !an add !onstaints in thee wa7s5

    2 Colu$n level "" along with the !olu$n definition

    3 Ta%le level "" afte the ta%le definition

    4 lte level "" using alte !o$$and

    6hile adding !onstaints 7ou need not spe!if7 the na$e %ut the t7pe onl7# oa!le will intenall7 na$e the

    !onstaint5

    If 7ou want to give a na$e to the !onstaint# 7ou have to use the !onstaint !lause5

     NOT NULL

    This is used to avoid null values5

    6e !an add this !onstaint in !olu$n level onl75

    '/0

      SQL- !eate ta%le student(no nu$%e(1) not null# na$e va!ha(23)# $a&s

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    73/326

      nu$%e(4)).

      SQL- !eate ta%le student(no nu$%e(1) !onstaint nn not null# na$e va!ha(23)#

    $a&s nu$%e(4)).

    C:'CF 

    This is used to inset the values %ased on spe!ified !ondition5

    6e !an add this !onstaint in all thee levels5

    '/0

      COLUMN L'9'L

      SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4) !he!&

    ($a&s - 433)).

      SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)

    !onstaint !h !he!&($a&s - 433)).

      TL' L'9'L

      SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)# !he!&

    ($a&s - 433)).

      SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#

    !onstaint !h !he!&($a&s - 433)).

      LT'R L'9'L

      SQL- alte ta%le student add !he!&($a&s-433).

    SQL- alte ta%le student add !onstaint !h !he!&($a&s-433).

    UNIQU'

    This is used to avoid dupli!ates %ut it allow nulls5

    6e !an add this !onstaint in all thee levels5

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    74/326

    '/0

      COLUMN L'9'L

      SQL- !eate ta%le student(no nu$%e(1) uniue# na$e va!ha(23)# $a&s

      nu$%e(4)).

    SQL- !eate ta%le student(no nu$%e(1) !onstaint un uniue# na$e va!ha(23)#

    $a&s nu$%e(4)).

      TL' L'9'L

     

    SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#

    uniue(no)).

      SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#

    !onstaint un uniue(no)).

      LT'R L'9'L

      SQL- alte ta%le student add uniue(no).

    SQL- alte ta%le student add !onstaint un uniue(no).

    ARIMR* F'*

    1 This is used to avoid dupli!ates and nulls5 This will wo& as !o$%ination of uniue and not null5

    2 Ai$a7 &e7 alwa7s atta!hed to the paent ta%le5

    3 6e !an add this !onstaint in all thee levels5

    '/0

      COLUMN L'9'L

     

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    75/326

      SQL- !eate ta%le student(no nu$%e(1) pi$a7 &e7# na$e va!ha(23)# $a&s

      nu$%e(4)).

    SQL- !eate ta%le student(no nu$%e(1) !onstaint p& pi$a7 &e7# na$e va!ha(23)#

    $a&s nu$%e(4)).

     

    TL' L'9'L

      SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#

     pi$a7 &e7(no)).

      SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#

    !onstaint p& pi$a7 &e7(no)).

      LT'R L'9'L

      SQL- alte ta%le student add pi$a7 &e7(no).

    SQL- alte ta%le student add !onstaint p& pi$a7 &e7(no).

    BOR'I8N F'*

    1 This is used to efeen!e the paent ta%le pi$a7 &e7 !olu$n whi!h allows dupli!ates5

    2 Boeign &e7 alwa7s atta!hed to the !hild ta%le5

    3 6e !an add this !onstaint in ta%le and alte levels onl75

    '/0

      TL' L'9'L

      SQL- !eate ta%le e$p(e$pno nu$%e(1)# ena$e va!ha(23)# deptno nu$%e(1)#

     pi$a7 &e7(e$pno)# foeign &e7(deptno) efeen!es dept(deptno)).

      SQL- !eate ta%le e$p(e$pno nu$%e(1)# ena$e va!ha(23)# deptno nu$%e(1)#

    !onstaint p& pi$a7 &e7(e$pno)# !onstaint f& foeign &e7(deptno) efeen!es

    dept(deptno)).

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    76/326

     

    LT'R L'9'L

     

    SQL- alte ta%le e$p add foeign &e7(deptno) efeen!es dept(deptno).

    SQL- alte ta%le e$p add !onstaint f& foeign &e7(deptno) efeen!es dept(deptno).

    On!e the pi$a7 &e7 and foeign &e7 elationship has %een !eated then 7ou !an not e$ove an7 paent

    e!od if the dependent !hilds e/ists5

     

    USIN8 ON D'LT' CSCD'

    7 using this !lause 7ou !an e$ove the paent e!od even it !hilds e/ists5

    e!ause when eve 7ou e$ove paent e!od oa!le auto$ati!all7 e$oves all its dependent e!ods fo$

    !hild ta%le# if this !lause is pesent while !eating foeign &e7 !onstaint5

    '/0

      TL' L'9'L

      SQL- !eate ta%le e$p(e$pno nu$%e(1)# ena$e va!ha(23)# deptno nu$%e(1)#

     pi$a7 &e7(e$pno)# foeign &e7(deptno) efeen!es dept(deptno) on delete

      !as!ade).

      SQL- !eate ta%le e$p(e$pno nu$%e(1)# ena$e va!ha(23)# deptno nu$%e(1)#

    !onstaint p& pi$a7 &e7(e$pno)# !onstaint f& foeign &e7(deptno) efeen!es

    dept(deptno) on delete !as!ade).

     

    LT'R L'9'L

      SQL- alte ta%le e$p add foeign &e7(deptno) efeen!es dept(deptno) on delete

    !as!ade.

    SQL- alte ta%le e$p add !onstaint f& foeign &e7(deptno) efeen!es dept(deptno) on

    delete !as!ade.

    COMAOSIT' F'*S

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    77/326

    !o$posite &e7 !an %e defined on a !o$%ination of !olu$ns5

    6e !an define !o$posite &e7s on entit7 integit7 and efeential integit7 !onstaints5

    Co$posite &e7 !an %e defined in ta%le and alte levels onl75

    '/0

      UNIQU' (TL' L'9'L)

     

    SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#

    uniue(no#na$e)).

      SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#

    !onstaint un uniue(no#na$e)).

     

    UNIQU' (LT'R L'9'L)

      SQL- alte ta%le student add uniue(no#na$e).

    SQL- alte ta%le student add !onstaint un uniue(no#na$e).

      ARIMR* F'* (TL' L'9'L)

      SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#

     pi$a7 &e7(no#na$e)).

      SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#

    !onstaint p& pi$a7 &e7(no#na$e)).

      ARIMR* F'* (LT'R L'9'L)

      SQL- alte ta%le student add pi$a7 &e7(no#an$e).

    SQL- alte ta%le student add !onstaint p& pi$a7 &e7(no#na$e).

      BOR'I8N F'* (TL' L'9'L)

      SQL- !eate ta%le e$p(e$pno nu$%e(1)# ena$e va!ha(23)# deptno nu$%e(1)#

    dna$e va!ha(23)# pi$a7 &e7(e$pno)# foeign &e7(deptno#dna$e) efeen!es

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    78/326

      dept(deptno#dna$e)).

      SQL- !eate ta%le e$p(e$pno nu$%e(1)# ena$e va!ha(23)# deptno nu$%e(1)#

    dna$e va!ha(23)# !onstaint p& pi$a7 &e7(e$pno)# !onstaint f& foeign

    &e7(deptno#dna$e) efeen!es dept(deptno#dna$e)).

     

    BOR'I8N F'* (LT'R L'9'L)

     

    SQL- alte ta%le e$p add foeign &e7(deptno#dna$e) efeen!es dept(deptno#dna$e).

    SQL- alte ta%le e$p add !onstaint f& foeign &e7(deptno#dna$e) efeen!es

    dept(deptno#dna$e).

    D'B'RRL' CONSTRINTS

    'a!h !onstaint has two additional atti%utes to suppot defeed !he!&ing of !onstaints5

    1 Defeed initiall7 i$$ediate

    2 Defeed initiall7 defeed

    Defeed initiall7 i$$ediate !he!&s fo !onstaint violation at the ti$e of inset5

    Defeed initiall7 defeed !he!&s fo !onstaint violation at the ti$e of !o$$it5

    '/0

      SQL- !eate ta%le student(no nu$%e(1)# na$e va!ha(23)# $a&s nu$%e(4)#

    !onstaint un uniue(no) defeed initiall7 i$$ediate).

      SQL- !eate ta%le student(no nu$%e(1)# na$e va!ha(23)# $a&s nu$%e(4)#

    !onstaint un uniue(no) defeed initiall7 defeed).

      SQL- alte ta%le student add !onstaint un uniue(no) defea%le initiall7 defeed.

     

    SQL- set !onstaints all i$$ediate.

      This will ena%le all the !onstaints violations at the ti$e of inseting5

      SQL- set !onstaints all defeed.

      This will ena%le all the !onstaints violations at the ti$e of !o$$it5

    OA'RTIONS 6IT: CONSTRINTS

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    79/326

    Aossi%le opeations with !onstaints as follows5

    3 'na%le

    4 Disa%le

    5 'nfo!e

    6 Dop

    'NL'

    This will ena%le the !onstaint5 efoe ena%le# the !onstaint will !he!& the e/isting data5

    '/0

      SQL- alte ta%le student ena%le !onstaint un.

    DISL'

    This will disa%le the !onstaint5

    '/0

      SQL- alte ta%le student ena%le !onstaint un.

    'NBORC'

    This will enfo!e the !onstaint athe than ena%le fo futue insets o updates5

    This will not !he!& fo e/isting data while enfo!ing data5

    '/0

      SQL- alte ta%le student enfo!e !onstaint un.

    DROA

    This will e$ove the !onstaint5

    '/0

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    80/326

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    81/326

      33 low

      133 $ediu$

      1333 $ediu$

      433 $ediu$

      4333 $ediu$

      333 high

      @333 $ediu$

      333 high

      2W33 $ediu$

      2133 $ediu$

      1333 $ediu$

      1V33 $ediu$

      1133 $ediu$

      4133 $ediu$

    D'BULT

     -e'ault  !an %e !onsideed as a su%stitute %ehavio of not null  !onstaint when applied to new ows %eing

    enteed into the ta%le5

    6hen 7ou define a !olu$n with the de'ault  &e7wod followed %7 a value# 7ou ae a!tuall7 telling the

    data%ase that# on inset if a ow was not assigned a value fo this !olu$n# use the default value that 7ou

    have spe!ified5

    Default is applied onl7 duing insetion of new ows5

    '/0

      SQL- !eate ta%le student(no nu$%e(1) default 22#na$e va!ha(1)).

      SQL- inset into student values(2#=a=).  SQL- inset into student(na$e) values(=%=).

     

    SQL- sele!t E fo$ student.

      NO NM'

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    82/326

      """""" """""""""

      2 a

      22 %

      SQL- inset into student values(null# K!;).

      SQL- sele!t E fo$ student.

      NO NM'

      """""" """""""""

      2 a

      22 %

      C

    "" Default !an not oveide nulls5

    STRCT DT T*A'S

    So$e ti$es 7ou $a7 want t7pe whi!h holds all t7pes of data in!luding nu$%es# !has and spe!ial

    !haa!tes so$ething li&e this5 *ou !an not a!hieve this using pe"defined t7pes5

    *ou !an define !usto$ t7pes whi!h holds 7ou desied data5

    '/0

      Suppose in a ta%le we have addess !olu$n whi!h holds hno and !it7 info$ation5

      6e will define a !usto$ t7pe whi!h holds %oth nu$ei! as well as !ha data5

     

    CR'TIN8 DT

      SQL- !eate t7pe add as o%Je!t(hno nu$%e(4)#!it7 va!ha(23)). ?

     

    CR'TIN8 TL' S'D ON DT

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    83/326

      SQL- !eate ta%le student(no nu$%e(1)#na$e va!ha(1)#addess add).

     

    INS'RTIN8 DT INTO DT TL'S

      SQL- inset into student values(2#=a=#add(222#=h7d=)).

      SQL- inset into student values(1#=%=#add(111#=%ang=)).

      SQL- inset into student values(4#=!=#add(444#=delhi=)).

     

    S'L'CTIN8 DT BROM DT TL'S

      SQL- sele!t E fo$ student.

      NO NM' DDR'SS(:NO# CIT*)

      """ """"""" """""""""""""""""""""""""

      2 a DDR(222# =h7d=)

      1 % DDR(111# =%ang=)

      4 ! DDR(444# =delhi=)

      SQL- sele!t no#na$e#s5addess5hno#s5addess5!it7 fo$ student s.

      NO NM' DDR'SS5:NO DDR'SS5CIT*

      """" """"""" """"""""""""""""" """"""""""""""""

      2 a 222 h7d

      1 % 111 %ang

      4 ! 444 delhi

    UADT' 6IT: DT TL'S

    SQL- update student s set s5addess5!it7 H =%o$%a7= whee s5addess5hno H 444.

    SQL- sele!t no#na$e#s5addess5hno#s5addess5!it7 fo$ student s.

      NO NM' DDR'SS5:NO DDR'SS5CIT*

      """" """"""" """"""""""""""""" """"""""""""""""

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    84/326

      2 a 222 h7d

      1 % 111 %ang

      4 ! 444 %o$%a7

    D'L'T' 6IT: DT TL'S

    SQL- delete student s whee s5addess5hno H 222.

    SQL- sele!t no#na$e#s5addess5hno#s5addess5!it7 fo$ student s.

      NO NM' DDR'SS5:NO DDR'SS5CIT*

      """" """"""" """"""""""""""""" """"""""""""""""

      1 % 111 %ang

      4 ! 444 %o$%a7

    DROAAIN8 DT

    SQL- dop t7pe add.

    O>'CT 9I'6S ND M'T:ODS

    O>'CT 9I'6S

    If 7ou want to i$ple$ent o%Je!ts with the e/isting ta%le# o%Je!t views !o$e into pi!tue5

    *ou define the o%Je!t and !eate a view whi!h elates this o%Je!t to the e/isting ta%le nothing %ut ob#ect 

    view5

    O%Je!t views ae used to elate the use defined o%Je!ts to the e/isting ta%le5

    '/0

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    85/326

      2) ssu$e that the ta%le student has alead7 %een !eated with the following !olu$ns

      SQL?

      1) Ceate the following t7pes

    SQL- !eate t7pe add as o%Je!t(hno nu$%e(1)#!it7 va!ha(23)).?

      SQL- !eate t7pe stud as o%Je!t(na$e va!ha(23)#addess add).?

      4) Relate the o%Je!ts to the student ta%le %7 !eating the o%Je!t view

      SQL- !eate view studentov(no#studinfo) as sele!t no#stud(na$e#add(hno#!it7))

      fo$ student.

      @) Now 7ou !an inset data into student ta%le in two wa7s

      a) 7 egula inset

    SQL- Inset into student values(2#;sudha;#222#;h7d;).

      %) 7 using o%Je!t view

      SQL- Inset into studentov values(2#stud(Ksudha;#add(222#;h7d;))).

    M'T:ODS

    *ou !an define $ethods whi!h ae nothing %ut fun!tions in t7pes and appl7 in the ta%les whi!h holds the

    t7pes.

    '/0

      2) Defining $ethods in t7pes

      SQL- Ceate t7pe stud as o%Je!t(na$e va!ha(23)#$a&s nu$%e(4)#

      Me$%e fun!tion $a&sf($a&s in nu$%e) etun nu$%e#

      Aag$a esti!tefeen!es($a&sf#wnds#nds#wnps#fnps)).?

      1) Defining t7pe %od7

      SQL- Ceate t7pe %od7 stud as

      Me$%e fun!tion $a&sf($a&s in nu$%e) etun nu$%e is

      egin

      Retun ($a&sG233).

      'nd $a&sf.

      'nd.?

      4) Ceate a ta%le using stud t7pe

      SQL- Ceate ta%le student(no nu$%e(1)#info stud).

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    86/326

      @) Inset so$e data into student ta%le

      SQL- Inset into student values(2#stud(Ksudha;#233)).

      ) Using $ethod in sele!t

      SQL- Sele!t s5info5$a&sf(s5info5$a&s) fo$ student s.

      "" :ee we ae using the pag$a esti!tefeen!es to avoid the wites to the

    Data%ase5

    9RR*S ND N'ST'D TL'S

    9RR*S

    va7ing aa7 allows 7ou to stoe epeating atti%utes of a e!od in a single ow %ut with li$it5

    '/0

      2) 6e !an !eate vaa7s using oa!le t7pes as well as use defined t7pes5

      a) 9aa7 using pe"defined t7pes

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    87/326

      SQL- Ceate t7pe va as vaa7() of va!ha(23).?

      %) 9aa7s using use defined t7pes

      SQL- Ceate t7pe add as o%Je!t(hno nu$%e(4)#!it7 va!ha(23)).?

      SQL- Ceate t7pe va as vaa7() of add.?

      1) Using vaa7 in ta%le

      SQL- Ceate ta%le student(no nu$%e(1)#na$e va!ha(23)#addess va).

      4) Inseting values into vaa7 ta%le

      SQL- Inset into student values(2#;sudha;#va(add(222#;h7d;))).

      SQL- Inset into student values(1#;Jagan;#va(add(222#;h7d;)#add(111#;%ang;))).

      @) Sele!ting data fo$ vaa7 ta%le

      SQL- Sele!t E fo$ student.

      "" This will displa7 vaa7 !olu$n data along with vaa7 and adt.

      SQL- Sele!t no#na$e# s5E fo$ student s2# ta%le(s25addess) s.

      "" This will displa7 in geneal fo$at

      ) Instead of s5E 7ou !an spe!if7 the !olu$ns in vaa7

      SQL- Sele!t no#na$e# s5hno#s5!it7 fo$ student s2#ta%le(s25addess) s.

      "" Update and delete not possi%le in vaa7s5

      "" :ee we used ta%le fun!tion whi!h will ta&e the vaa7 !olu$n as input fo podu!ing

    output e/!luding vaa7 and t7pes5

     

     N'ST'D TL'S

    nested ta%le is# as its na$e i$plies# a ta%le within a ta%le5 In this !ase it is a ta%le that is epesented as a

    !olu$n within anothe ta%le5

     Nested ta%le has the sa$e effe!t of vaa7s %ut has no li$it5

    '/0

      2) 6e !an !eate nested ta%les using oa!le t7pes and use defined t7pes whi!h has no

    li$it5

      a) Nested ta%les using pe"defined t7pes

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    88/326

      SQL- Ceate t7pe nt as ta%le of va!ha(23).?

      %) Nested ta%les using use defined t7pes

      SQL- Ceate t7pe add as o%Je!t(hno nu$%e(4)#!it7 va!ha(23)).?

      SQL- Ceate t7pe nt as ta%le of add.?

      1) Using nested ta%le in ta%le

      SQL- Ceate ta%le student(no nu$%e(1)#na$e va!ha(23)#addess nt) nested ta%le

    addess stoe as studentte$p.

      4) Inseting values into ta%le whi!h has nested ta%le

      SQL- Inset into student values (2#;sudha;#nt(add(222#;h7d;))).

      SQL- Inset into student values (1#;Jagan;#nt(add(222#;h7d;)#add(111#;%ang;))).

      @) Sele!ting data fo$ ta%le whi!h has nested ta%le

      SQL- Sele!t E fo$ student.

      "" This will displa7 nested ta%le !olu$n data along with nested ta%le and adt.

      SQL- Sele!t no#na$e# s5E fo$ student s2# ta%le(s25addess) s.

      "" This will displa7 in geneal fo$at

      ) Instead of s5E 7ou !an spe!if7 the !olu$ns in nested ta%le

      SQL- Sele!t no#na$e# s5hno#s5!it7 fo$ student s2#ta%le(s25addess) s.

      ) Inseting nested ta%le data to the e/isting ow

      SQL- Inset into ta%le(sele!t addess fo$ student whee noH2)

    values(add(#;!hennai;)).

      V) Update in nested ta%les

      SQL- Update ta%le(sele!t addess fo$ student whee noH1) s set s5!it7H;%o$%a7;

    whee s5hno H 111.

      W) Delete in nested ta%le

      SQL- Delete ta%le(sele!t addess fo$ student whee noH4) s whee s5hnoH444.

    DT MOD'L

    1 LLCOLLT*A'S

    2 LLT*A'S

    3 DCOLLT*A'S

    4 DT*A'S

    5 US'RCOLLT*A'S

    6 US'RT*A'S

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    89/326

    BLS:CF QU'R*

    Used to etieve the data whi!h has %een alead7 !o$$itted with out going fo e!ove75

    Blash%a!&s ae of two t7pes

    1 Ti$e %ase flash%a!& 

    2 SCN %ased flash%a!& (SCN stands fo S7ste$ Change Nu$%e)

    '/0

    2) Using ti$e %ased flash%a!& 

      a) SQL- Sele!t Efo$ student.

      "" This will displa7 all the ows

      %) SQL- Delete student.

      !) SQL- Co$$it. "" this will !o$$it the wo&5

      d) SQL- Sele!t Efo$ student.

      "" :ee it will displa7 nothing

      e) Then e/e!ute the following po!edues

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    90/326

      SQL- '/e! d%$sflash%a!&5ena%leatti$e(s7sdate"1?2@@3)

      f) SQL- Sele!t Efo$ student.

      "" :ee it will displa7 the lost data

      "" The lost data will !o$e %ut the !uent s7ste$ ti$e was used

      g) SQL- '/e! d%$sflash%a!&5disa%le

      "" :ee we have to disa%le the flash%a!& to ena%le it again

    1) Using SCN %ased flash%a!& 

      a) De!lae a vaia%le to stoe SCN

      SQL- 9aia%le s nu$%e 

      %) 8et the SCN

      SQL- '/e! 0s 0H e/e! d%$sflash%a!&5gets7ste$!hangenu$%e 

      !) To see the SCN

      SQL- Aint s

      d) Then e/e!ute the following po!edues

      SQL- '/e! d%$sflash%a!&5ena%leats7ste$!hangenu$%e(0s)

      SQL- '/e! d%$sflash%a!&5disa%le

    '+T'RNL TL'S

    *ou !an use e/tenal ta%le featue to a!!ess e/tenal files as if the7 ae ta%les inside the data%ase5

    6hen 7ou !eate an e/tenal ta%le# 7ou define its stu!tue and lo!ation with in oa!le5

    6hen 7ou ue7 the ta%le# oa!le eads the e/tenal ta%le and etuns the esults Just as if the data had

     %een stoed with in the data%ase5

    CC'SSIN8 '+T'RNL TL' DT

    To a!!ess e/tenal files fo$ within oa!le# 7ou $ust fist use the !eate die!to7 !o$$and to define a

    die!to7 o%Je!t pointing to the e/tenal file lo!ation

    Uses who will a!!ess the e/tenal files $ust have the ead and wite pivilege on the die!to75

    '/0

    CR'TIN8 DIR'CTOR* ND OS L'9'L BIL'

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    91/326

      SQL- Slplus s7ste$?$anage 

      SQL- Ceate die!to7 sa&ethdi as K?9isd%?visd%?5153?e/tenal;.

      SQL- 8ant all on die!to7 sa&ethdi to sa&eth.

      SQL- Conn sa&eth?sa&eth

      SQL- Spool dept5lst

      SQL- Sele!t deptno XX K#; XX dna$e XX K#; XX lo! fo$ dept.

      SQL- Spool off 

    CR'TIN8 '+T'RNL TL'

     SQL- Ceate ta%le depte/t

      (deptno nu$%e(1)#

      Dna$e va!ha(2@)#

      Lo! va!ha(24))

      Oganiation e/tenal ( t7pe oa!leloade 

      Default die!to7 sa&ethdi 

      !!ess paa$etes

    ( e!ods deli$ited %7 newline

      Bields te$inated %7 P#

      ( deptno nu$%e(1)#

      Dna$e va!ha(2@)#

      Lo! va!ha(24)))

      Lo!ation (K?9isd%?visd%?5153?dept5lst;)).

    S'L'CTIN8 DT BROM '+T'RNL TL'

    SQL- sele!t E fo$ depte/t.

    This will ead fo$ dept5lst whi!h is a opeating s7ste$ level file5

    LIMITTIONS ON '+T'RNL TL'S

    a) *ou !an not pefo$ inset# update# and delete opeations

    b) Inde/ing not possi%le

    b) Constaints not possi%le

  • 8/20/2019 bestsqlplsqlmaterial-140617143256-phpapp02

    92/326

    'N'BITS OB '+T'RNL TL'S

    a) Queies of e/tenal ta%les !o$plete ve7 ui!&l7 even though a full ta%le s!an id euied with

    ea!h a!!ess

    b) *ou !an Join e/tenal ta%les to ea!h othe o to standad ta%les

    R'B D'R'B 9LU'

    R'B

    1 The ef fun!tion allows efeen!ing of e/isting ow o%Je!ts5

    2 'a!h of the ow o%Je!ts has an o%Je!t id value assigned to it5

    3 The o%Je!t id assigned !an %e seen %7 using ef fun!tion5

    D'R'B