Date post: | 08-Jul-2018 |
Category: |
Documents |
Upload: | tarikh-khan |
View: | 231 times |
Download: | 0 times |
of 12
8/19/2019 pl/sql interview q
1/28
I am Brahma Reddy i am postgraduate and having 4 years of experience in oracle
technology in the areas of Unix, Pl/sql and Sql !urrently I am associated "ith xxx as
soft"are developer ,previously i "or#ed in yyy as a soft"are developer $y expert li#e
as creating procedure, function, pac#age and handling the exception, during the years i"or#ed di%erent domains, currently I am associated "ith xxx
What is diference between TRUNCATE & DELETE?
& 'runcate is a (() command
* +e can remove ul# amount of records at a time
- +e can.t rollac# the records
4 Release the space in dataase
'runcate reset the high "ater mar#
0 'runcate explicitly commit
& (elete is a ($) command
* +e can delete record y record
- +e can rollac# the records
4 !an1t release the memory in dataase
(elete can1t reset the "ater mar#
0 (elete implicitly commit
23R
5ns6 (i%erences6
'RU7!5'8 commits after deleting entire tale ie, cannot e rolled ac#
(ataase triggers do not 9re on 'RU7!5'8 (8)8'8 allo"s the 9ltered deletion
(eleted records can e rolled ac# or committed(ataase triggers 9re on (8)8'8
3. Diference between view and materialied view
(i%erence
:ie" is a logical tale
:ie" can hold the query
+e can1t create indexes on vie"
8/19/2019 pl/sql interview q
2/28
8/19/2019 pl/sql interview q
3/28
/iews' 5 vie" is a virtual tale 8very vie" has a query attached to it 2'he query is a
S8)8!' statement that identi9es the columns and ro"s of the tale2s the vie" uses
0na"sh#t' 5 Snapshot is a recent copy of a tale from dataase or in some cases ,a
suset of ro"s/columns of a tale It is also #no"n as $ateriali>ed vie"D# a view c#ntain data?
5ns6 :ie"s do not contain or store data
+hat are the advantages of vie"s?
5ns6 Provide an additional level of tale security, y restricting access to a
predetermined set of ro"s and columns of a tale
@ Aide data complexity
@ Simplify commands for the user
@ Present the data in a di%erent perspective from that of the ase tale
@ Store complex queries
What is an 1racle se2$ence?
5ns6 5 Sequence generates a serial list of unique numers for numerical columns of a
dataase.s tales
What is a s,n#n,m?
5ns6 5 synonym is an alias for a tale, vie", sequence or program unit
What are the t,"es #% s,n#n,ms?
5ns6 'here are t"o types of synonyms private and pulic
What is a "rivate s,n#n,m?
5ns6 3nly its o"ner can access a private synonym
What is a "$blic s,n#n,m?
5ns6 5ny dataase user can access a pulic synonym
What is an 1racle inde+?
5ns6 5n index is an optional structure associated "ith a tale to have direct access to
ro"s, "hich can e created to increase the performance of data retrieval Index can e
created on one or more columns of a tale Index may also e considered as a ordered
list of content of a column
What is a schema?
5ns6 'he set of o=ects o"ned y user account is called the schema
8/19/2019 pl/sql interview q
4/28
8/19/2019 pl/sql interview q
5/28
8xplicit !ursor6 5 cursor "hich is opened for processing data through a P)/SG) loc# is
#no" as 8xplicit !ursor
Attrib$tes 1% a 4m"licit C$rs#r'
8/19/2019 pl/sql interview q
6/28
What is a tables"ace?
5ns6 5 dataase is divided into )ogical Storage Unit called talespaces 5 talespace is
used to grouped related logical structures together
4s se2$ence c,clic?5ns6 Kes
0elect nth hi9hest val$e %r#m a list #% val$es ?
5ns6 S8)8!' aempFname,asal ;R3$ emp a +A8R8 Ln @ &M 2S8)8!' !3U7'2(IS'I7!'
sal ;R3$ emp +A8R8 sal N asal
What are tri99ers and its t,"es?
5ns6 5 trigger is a piece of code attached to a tale that is executed after speci9ed ($)
statements executed on that tale 'here are &* types of triggers in P)/SG) that consist
of cominations of the B8;3R8, 5;'8R, R3+, S'5'8$87', '5B)8, I7S8R', UP(5'8,
(8)8'8 and 5)) #ey "ords6 ;or eg6 B8;3R8 5)) R3+ I7S8R' 5;'8R 5)) R3+ I7S8R'
B8;3R8 I7S8R' 5;'8R I7S8R'
What is the ma+im$m n$mber #% tri99ers can a""l, t# a sin9le table?
5ns6 &* triggers23racle
Diference between r#wid and r#wn$m?
5ns6 R3+I( is pseudo column in every tale 'he physical address of the ro"s is use to
for the R3+I(I7 A8D5(8!I$5) representation, R3+I( is sho"n as &O character string
of the follo"ing format BBBBBBBBBRRRR;;;; 2loc#, ro", 9le ;;;; is the 9leid of the
data9le that contains the ro" BBBBBBBBB is the address of the dataloc# "ithin the
data9le that contains the ro" RRRR is the R3+ 7U$B8R "ith the data loc# that
contains the ro" 'hey are unique identi9ers for the any ro" in a tale 'hey are
internally used in the construction of indexes
Ro"num is the sequential numer of ro"s in the result set o=ect
What is the %astest 2$er, meth#d %#r a table?
5ns6 By ro"id
What is the diference #% a LE(T :14N and an 4NNER :14N statement?
5ns6 5 )8;' 3I7 "ill ta#e 5)) values from the 9rst declared tale and matching values
from the second declared tale ased on the column the =oin has een declared on 5n
I778R 3I7 "ill ta#e only matching values from oth tales
8/19/2019 pl/sql interview q
7/28
5#w can 4 av#id a divide b, er# err#r?
5ns6 Use the (8!3(8 function 'his function is asolutely rilliant and functions li#e a
!5S8 statement, and can e used to return di%erent columns ased on the values of
others4s view $"datable?
5ns6 3nly if the vie" is a simple hori>ontal slice through a single tale
What is D$al ?
5ns6 'he (U5) tale is a tale "ith a single ro" and a single column used "here a tale
is syntactically required
What is the diference between C5AR and /ARC5AR ?
5ns6 !A5R is 9xed length character type at storage level, and that :5R!A5R "ill e
variale length
D# we $se c#mmit in tri99ers.
5ns6 7o
5#w will the %etch the last inserted rec#rd in an, table ?
5ns6 select column &, column * ;rom "here ro"id M 2select max2ro"id from tale
What are c#nstraints and its t,"es?
Integrity !onstraint 6 5n integrity constraint is a declarative "ay to de9ne a usiness
rule for a column of a tale 5n integrity constraint is a statement aout a tale.s data
that is al"ays true
'ypes of integrity constraints 6 'he follo"ing integrity constraints are supported y
3R5!)86
& 73' 7U)) 6 disallo"s nulls 2empty entries in a tale.s column
* U7IGU8 6 disallo"s duplicate values in a column or set of columns
- PRI$5RK Q8K 6 disallo"s duplicate values and nulls in a column or set of columns
4 ;3R8IE7 Q8K 6 requires each value in a column or set of columns match a value in a
related tale.s U7IGU8 or PRI$5RK Q8K
!A8!Q 6 disallo"s values that do not satisfy the logical expression of the constraint
What is Re%erential 4nte9rit, and Re%erential inte9rit, c#nstraint ?
5ns6 Referential Integrity 6 Referential integrity de9nes the relationships among di%erent
columns and tales in a relational dataase It1s called referential integrity ecause the
8/19/2019 pl/sql interview q
8/28
values in one column or set of columns refer to or must match the values in a related
column or set of columns
5 referential integrity constraint requires that for each ro" of a tale, the value in the
foreign #ey matches a value in a parent #eyWhat is 9r#$"s b, and havin9 cla$se? E+"lain with e+am"le
5ns6 Eroup y clause tells oracle to group ro"s ased on distinct values that exists for
speci9ed columns 'he group y clause creates a data set , containing several sets of
records grouped together ased on condition
Aaving !lause6 Aaving clause can e used "ith ER3UP BK clause Aaving imposes a
condition on the group y clause "hich further 9lters the group created y the ER3UP
BK clause Select ename,empno ;rom 8mpl Eroup y empno having empno N &C
What are L1C;0? What are t,"es #% diferent t,"es #% L#c
8/19/2019 pl/sql interview q
9/28
& 8xclusive (() )oc#s
* Share (() )oc#s
- Brea#ale Parse )oc#s Restrictiveness of )oc#s 6 In general, t"o levels of loc#ing can
e used in a multi@user dataase6 8xclusive )oc#s 6 5n exclusive loc# prohiits thesharing of the associated resource 'he 9rst transaction to exclusively loc# a resource is
the only transaction that can alter the resource until the exclusive loc# is released
Share )oc#s 6 5 share loc# allo"s the associated resource to e shared, depending on
the operations involved 2eg, several users can read the same data at the same time
Several transactions can acquire share loc#s on the same resource Share loc#s allo" a
higher degree of data concurrency than exclusive loc#s
Diference between $ni2$e
8/19/2019 pl/sql interview q
10/28
& !reate a cursor
* Parse the statement
- (escrie Results
4 (e9ning outputs Bind any variales
0 8xecute the statement
;etch ro"s of a query result
What d# ,#$ mean b, arsin9?
5ns6 Parsing 6 Parsing is the process of6 & 'ranslating a SG) statement, verifying it to e
a valid statement * Performing data dictionary loo#ups to chec# tale and column
de9nitions - 5cquiring parse loc#s on required o=ects so that their de9nitions do not
change during the statement.s parsing 4 !hec#ing privileges to access referenced
schema o=ects (etermining the execution plan to e used "hen executing the
statement 0 )oading it into a shared SG) area ;or distriuted statements, routing all
or part of the statement to remote nodes that contain referenced data
What is a 54NT and what are t,"es 54NT?
5ns6 Aints are suggestions that you give the optimi>er for optimi>ing a SG) statement
Aints allo" you to ma#e decisions usually made y the optimi>er
'KP8S 3; AI7'S 6
5))FR3+S 6 'he 5))FR3+S hint explicitly chooses the cost@ased approach to optimi>e
a statement loc# "ith a goal of est throughput
;IRS'FR3+S 6 'he ;IRS'FR3+S hint explicitly chooses the cost@ased approach to
optimi>e a statement loc# "ith a goal of est response time
;U)) 6 'he ;U)) hint explicitly chooses a full tale scan for the speci9ed tale
R3+I( 6 'he R3+I( hint explicitly chooses a tale scan y R3+I( for the speci9ed
tale
!)US'8R 6 'he !)US'8R hint explicitly chooses a cluster scan to access the speci9ed
tale
A5SA 6 'he A5SA hint explicitly chooses a hash scan to access the speci9ed tale
I7(8D 6 'he I7(8D hint explicitly chooses an index scan for the speci9ed tale
8/19/2019 pl/sql interview q
11/28
57(F8GU5)6 'he 57(F8GU5) hint explicitly chooses an execution plan that uses an
access path that merges the scans on several single@column indexes 2Kou can specify
multiple indexes through this hint I7(8DF5S!6 'he I7(8DF5S! hint explicitly chooses
an index scan for the speci9ed tale If the statement uses an index range scan,3R5!)8 scans the index entries in ascending order of their indexed values
I7(8DF(8S!6 'he I7(8DF(8S! hint explicitly chooses an index scan for the speci9ed
tale If the statement uses an index range scan, 3R5!)8 scans the index entries in
descending order of their indexed values
3R(8R8( 6 'he 3R(8R8( hint causes 3R5!)8 to =oin tales in the order in "hich they
appear in the ;R3$ clause
US8F7) 6 'he US8F7) hint causes 3R5!)8 to =oin each speci9ed tale to another ro"
source "ith a nested loops =oin using the speci9ed tale as the inner tale
US8F$8RE8 6 'he US8F$8RE8 hint causes 3R5!)8 to =oin each speci9ed tale "ith
another ro" source "ith a sort@merge =oin
What d# $ mean b, E>CET41N4N4T ra9ma ?
5ns6 8D!8P'I37FI7I' Pragma 6 'o handle unnamed internal exceptions, you must use
the 3'A8RS handler or the pragma 8D!8P'I37FI7I' 5 VpragmaV is a compiler directive,
"hich can e thought of as a parenthetical remar# to the compiler Pragmas 2also called
VpseudoinstructionsV are processed at compile time, not at run time 'hey do not a%ect
the meaning of a program they simply convey information to the compiler 'he
prede9ned pragma 8D!8P'I37FI7I' tells the P)/SG) compiler to associate an exception
name "ith an 3racle error numer 'hat allo"s you to refer to any internal exception y
name and to "rite a speci9c handler for it Kou code the pragma 8D!8P'I37FI7I' in the
declarative part of a P)/SG) loc#, suprogram, or pac#age
using the syntax PR5E$5 8D!8P'I37FI7I'2exceptionFname, 3racleFerrorFnumer
"here VexceptionFnameV is the name of a previously declared exception ;or internal
exceptions, SG)!3(8 returns the numer of the associated 3racle error 'he numer
that SG)!3(8 returns is negative unless the 3racle error is Vno data found,V in "hich
case SG)!3(8 returns W&CC SG)8RR$ returns the message associated "ith the 3racle
error that occurred 'he message egins "ith the 3racle error code ;or user@de9ned
exceptions, SG)!3(8 returns W& and SG)8RR$ returns the message XUser@(e9ned
8/19/2019 pl/sql interview q
12/28
8xceptionY unless you used the pragma 8D!8P'I37FI7I' to associate the exception
name "ith an 3racle error numer, in "hich case SG)!3(8 returns that error numer
and SG)8RR$ returns the corresponding error message 'he maximum length of an
3racle error message is &* characters including the error code, nested messages, andmessage inserts such as tale and column names
+hat do u mean y SP query?
5ns6 SP Guery 6 'he SP Guery is a standard query for numer to "ords conversion,
used especially for converting amount in numer into equivalent amount in "ords 'he
query is as follo"s 6 Select toFchar 2 toFdate 2 ZLno1, Z1 , ZSP1 "ords from dual ;or eg 6
Select toFchar 2 toFdate 2 .*-[4[.,.=. , .SP. V"ordsV from dual 'he value that can pass
to Lno cannot exceed digits
Describe 1racle database@s "h,sical and l#9ical str$ct$re ?
5ns6 Physical6 (ata 9les, Redo )og 9les, !ontrol 9le )ogical 6 'ales, :ie"s, 'alespaces,
etc
What is Chec< C#nstraintsB and with chec< #"ti#nsB and De%a$lt
0"ecicati#nB?
5ns6 !A8!Q Integrity !onstraints6 5 !A8!Q integrity constraint on a column or a set of
columns requires that a speci9ed condition e true or un#no"n 2ie 7ot false for every
ro" of the tale If a ($) statement is issued so that the condition of the !A8!Q
constraint evaluates to false, the statement is rolled ac# +ith chec# 3ption6 +ith
!hec# option restricts inserts and updates performed through the vie" to prevent them
from creating ro"s that the vie" cannot itself select ased on "here clause of the
create vie" statement ;or eg6 !reate or replace vie" +omen 5s select name from
8mployee +here SexM Z;emale1 +ith !hec# 3ption (efault Speci9cation It supplies a
default value if column value is not speci9ed on I7S8R' It can contain literals
2constants and SG) functions, US8R, SKS(5'8, sequence It cannot include references
to any columns
What is the ma+im$m n#. 1% c#l$mns a table can have ?
5ns6 *423racle
Can a tri99er written %#r a view ?
5ns6 7o
8/19/2019 pl/sql interview q
13/28
!onsider a sequence "hose currval is & and gets incremented y & y using the nextval
reference "e get the next numer * Suppose at this point "e issue an rollac# and
again issue a nextval +hat "ill the output e ?
5ns6 -Can ,#$ create inde+ #n view ?
5ns6 7o
What is the diference between alias and s,n#n,m ?
5ns6 5lias is temporary and used "ith one query Synonym is permanent and not used
as alias
+hat1s the length of SG) integer ?
5ns6 -* it length
What is t
8/19/2019 pl/sql interview q
14/28
tales are o"ned y SKS and their names all egin "ith :F\ :ie"s are created on these
tales, and then synonyms are created for the vie"s 'he synonym names egin "ith
:\
What is 0ave"#int ?5ns6 Savepoints are intermediate mar#ers that can e declared in long transactions that
contain many SG) statements By using savepoints, you can aritrarily mar# your "or#
at any point "ithin a long transaction 'his allo"s you the option of later rolling ac# all
"or# performed from the current point in the transaction to a declared savepoint "ithin
the transaction
+hat is (eadloc#s?
5ns6 5 deadloc# is a situation that can occur in multi@user systems that causes some
numer of transactions to e unale to continue "or# 5 deadloc# can occur "hen t"o
or more users are "aiting for data loc#ed y each other It typically happens "hen each
of t"o or more users are "aiting to access a resource that another user has already
loc#ed 'his creates a deadloc# situation ecause each user is "aiting for resources held
y the other user 8g 'ransaction & 'ime Point 'ransaction * UP(5'8 emp & UP(5'8
emp S8' sal M sal&& S8' sal M &-4* +A8R8 empno M &CCC +A8R8 empno M *CCC
UP(5'8 emp * UP(5'8 emp S8' sal M sal&& S8' sal M &-4* +A8R8 empno M *CCC
+A8R8 empno M &CCC 3R5@CCC0C - deadloc# detected "hile "aiting for resource
What is rivile9e ?
5ns6 5 privilege is a right to execute a particular type of SG) statement or to access
another user.s o=ect 'ypes of privileges 6 system privileges o=ect privileges
System Privileges 6 System privileges allo" users to perform a particular system"ide
action, or to perform a particular action on a particular type of o=ect 8g !reate
'alespace, (elete the ro" of any tale, etc 3=ect Privileges 6 3=ect privileges allo"
users to perform a particular action on a speci9c o=ect 8g (elete ro" of speci9c
tale, etc Roles 6 Roles are named groups of related privileges that are granted to users
or other roles 5dvantages of Roles 6 & Reduced granting of privileges * (ynamic
privilege management 2!hanging of privileges - Selective availaility of privileges
28nalling/(isaling roles 4 5pplication a"areness 28nalling/(isaling of roles y
application
8/19/2019 pl/sql interview q
15/28
What is Tw# hase C#mmit ?
5ns6 '"o Phase !ommit is a mechanism "herein 3R5!)8 automatically controls and
monitors the commit or rollac# of a distriuted transaction and maintains the integrity
of the gloal dataase 'he Phases of the '"o@Phase !ommit $echanism 6 Prepare phase 6 'he gloal co@ordinator 2initiating node as#s participants to prepare
2to promise to commit or rollac# the transaction, even if there is a failure
!ommit phase 6 If all participants respond to the co@ordinator that they are prepared,
the co@ordinator as#s all nodes to commit the transaction if all participants cannot
prepare, the co@ordinator as#s all nodes to roll ac# the transaction
E+"lain ab#$t sna"sh#ts in detail?
5ns6 Snapshots are read@only copies of a master tale 2or multiple tales located on a
remote node 5 snapshot can e queried, ut not updated only the master tale can e
updated 5 snapshot is periodically refreshed to reect changes made to the master
tale 5 snapshot is a full copy of a tale or a suset of a tale that reects a recent
state of the master tale 5 snapshot is de9ned y a distriuted query that references
one or more master tales, vie", or other snapshots Simple vs !omplex Snapshots 6
8ach ro" in a simple snapshot is ased on a single ro" in a single remote tale
'herefore, a simple snapshot.s de9ning query has no ER3UP BK or !3778!' BK
clauses, or suqueries, =oins, or set operations If a snapshot.s de9ning query contains
any of these clauses or operations, it is referred to as a complex snapshot Internals of
Snapshot !reation6 +hen a snapshot is created, several operations are performed
internally y 3R5!)86 3R5!)8 2at the snapshot node creates a tale to store the ro"s
retrieved y the snapshot.s de9ning query this is the snapshot.s ase tale 3R5!)8
creates a read@only vie" on the S75P\ tale 2ase tale for queries issued against the
snapshot 3R5!)8 creates a second local vie" on the remote master tale It uses this
vie" "hen it refreshes the snapshot 5dditionally, if the snapshot is a simple snapshot,
3R5!)8 creates an index on the S75P\ tale 5ll of these internal o=ects are created in
the schema of the snapshot (o not alter, change data in, or delete these o=ects
manually
What is Re% C$rs#r?
8/19/2019 pl/sql interview q
16/28
5ns6 5 R8; !URS3R is asically a data type 5 variale created ased on such a data
type is generally called a cursor variale 5 cursor variale can e associated "ith
di%erent queries at run@time 'he primary advantage of using cursor variales is their
capaility to pass result sets et"een su programs 2li#e stored procedures, functions,pac#ages etc
What is r#w chainin9 h#w d#es it ha""en?
5ns6 Ro" chaining occurs "hen a :5R!A5R* value is updated and the length of the ne"
value is longer than the old value and "on1t 9t in the remaining loc# space 'his results
in the ro" chaining to another loc# It can e reduced y setting the storage
parameters on the tale to appropriate values It can e corrected y export and import
of the e%ected tale
Describe hit rati# as it "ertains t# the database b$fers. What is the diference
between instantane#$s and c$m$lative hit rati# and which sh#$ld be $sed %#r
t$nin9?
5ns6 'he hit ratio is a measure of ho" many times the dataase "as ale to read a
value from the u%ers verses ho" many times it had to re@read a data value from the
dis#s 5 value greater than OC@[C< is good, less could indicate prolems If you simply
ta#e the ratio of existing parameters this "ill e a cumulative value since the dataase
started If you do a comparison et"een pairs of readings ased on some aritrary time
span, this is the instantaneous ratio for that time span 5n instantaneous reading gives
more valuale data since it "ill tell you "hat your instance is doing for the time it "as
generated over
What is a Cartesian "r#d$ct?
5ns6 5 !artesian product is the result of an unrestricted =oin of t"o or more tales 'he
result set of a three tale !artesian product "ill have x y > numer of ro"s "here x,
y, > correspond to the numer of ro"s in each tale involved in the =oin
What is a m$tatin9 table err#r and h#w can ,#$ 9et ar#$nd it?
5ns6 'his happens "ith triggers It occurs ecause the trigger is trying to update a ro" it
is currently using 'he usual 9x involves either use of vie"s or temporary tales so the
dataase is selecting from one "hile updating the other
8/19/2019 pl/sql interview q
17/28
What are 08LC1DE and 08LERR and wh, are the, im"#rtant %#r L=08L
devel#"ers?
5ns6 SG)!3(8 returns the value of the error numer for the last error encountered 'he
SG)8RR$ returns the actual error message for the last error encountered 'hey can eused in exception handling to report, or, store in an error log tale, the error that
occurred in the code 'hese are especially useful for the +A87 3'A8RS exception
What are Transacti#nal Tri99ers ? ive the $ses #% Transati#nal Tri99er ?
5ns6 'ransactional 'riggers 9re in response to transaction processing events 'hese
events represent points during application processing at "hich 3racle ;orms needs to
interact "ith the data source 8xamples of such events include updating records, rolling
ac# to savepoints, and committing transactions By default, 3racle ;orms assumes that
the data source is an 3R5!)8 dataase, and issues the appropriate SG) statements to
optimi>e transaction processing accordingly Ao"ever, y de9ning
transactional triggers and user exits, you can uild a form to interact "ith virtually any
data source, including even non@relational dataases and at 9les !alling User 8xits
+hen you de9ne transactional triggers to interact "ith a non@3R5!)8 data source, you
"ill usually include a call to a user exit in the appropriate triggers 'he code in your user
exit interacts "ith the non@3R5!)8 data source 3nce the user exit has performed the
appropriate function 2as indicated y the trigger from "hich it "as called, it returns
control to 3racle ;orms for susequent processing ;or example, a user exit called from
an 3n@;etch trigger might e responsile for retrieving the appropriate numer of
records from the non@3R5!)8 data source 3nce the records are retrieved, 3racle ;orms
ta#es over the display and management of those records in the form interface, =ust as it
"ould if the records had een fetched from an 3R5!)8 dataase Uses for 'ransactional
'riggers 'ransactional triggers, except for the commit triggers, are primarily intended
to access certain data sources other than 3racle 'he logon and logo% transactional
triggers can also e used "ith 3racle dataases to change connections at run time
What is A$t#n#m#$s transacti#n ? Where d# we $se it?
5ns6 In 3racle.s dataase products, an autonomous transaction is an independent
transaction that is initiated y another transaction It must contain at least one
Structured Guery )anguage 2SG) statement 5utonomous transactions allo" a single
8/19/2019 pl/sql interview q
18/28
transaction to e sudivided into multiple commit/rollac# transactions, each of "hich
"ill e trac#ed for auditing purposes +hen an autonomous transaction is called, the
original transaction 2calling transaction is temporarily suspended 'he autonomous
transaction must commit or roll ac# efore it returns control to the calling transaction3nce changes have een made y an autonomous transaction, those changes are
visile to other transactions in the dataase 5utonomous transactions can e nested
'hat is, an autonomous transaction can operate as a calling transaction, initiali>ing
other autonomous transactions "ithin itself
What is a "ac
8/19/2019 pl/sql interview q
19/28
5ns6 'he L operator means that the P) SG) loc# requires user input for a variale 'he
LL operator means that the value of this variale should e the same as inputted y
the user previously for this same variale
If all the values from a cursor have een fetched and another fetch is issued, the output"ill e?
5ns6 )ast Record
+hat is a for"ard declaration ? +hat is its use ?
5ns6 P)/SG) requires that you declare an identi9er efore using it 'herefore, you must
declare a suprogram efore calling it 'his declaration at the start of a suprogram is
called for"ard declaration 5 for"ard declaration consists of a suprogram speci9cation
terminated y a semicolon
5ny three P)/SG) 8xceptions?
5ns6 'ooFmanyFro"s, 7oF(ataF;ound, :alueF8rror, ]eroF8rror, 3thers
Describe the $se #% FR1WTGE and FTGE in L=08L
5ns6
8/19/2019 pl/sql interview q
20/28
process using the error@reporting functions SG)!3(8 and SG)8RR$ in an 3'A8RS
handler 'he statement RaiseF5pplicationF8rror can e called either from a procedure
ody or from an exception handler Irrespective of "hether an error occurred or not, a
raiseFapplicationFerror command al"ays raises an exception in the calling program 2ega forms trigger If an exception handler is not "ritten in that forms trigger, then a forms
error occurs
Q:To find the uniquness of the given record.
A1:select * from dual where 1=
(select max(count(empno)) from emp group by empno)
A2: select 1 yes_unique from emp
having count(distinct sal)=count(sal)
--> Q:To delete the even number of recordsA:delete from emp where rowid in(select rowid from
emp group by rownum,rowid having mod(rownum,2)0)
--> Q:To find the nth max sal
A1: select distinct sal from emp e where &n=
(select count(distinct sal) from emp d where e.sal Q:To find the nth min salA: select distinct sal from emp e where &n=
(select count(distinct sal) from emp d where e.sal>=d.sal)
--> Q:To select nth max sal from each department.
A1: select * from(select rownum r,e.* from
(select distinct sal from emp order by sal)e) where r=&n
8/19/2019 pl/sql interview q
21/28
A2:select distinct sal from emp e where &n=
(select count(distinct sal) from emp d where e.sal Q:To select nth min sal from each department.
A: select distinct sal from emp e where &n=
(select count(distinct sal) from emp d where
e.sal>=d.sal and e.deptno=d.deptno)
--> Q:TO select top n salarys from each department.
A: select * from(select empno,ename,sal,deptno,rank() over
(partition by deptno order by sal desc) top_sal from emp)
where top_sal Q:To select bottom n salarys from each department
A:select * from(select empno,ename,sal,deptno,rank() over
(partition by deptno order by sal ) bottom_sal from emp)
where bottom_sal Q:To create the duplicate table without data
A: create table emp_dup as select * from emp where 1=2
--> Q:what will be the output
select * from emp where null is null
select * from emp where null=null
--> Q:To delete nth record
A:Delete from emp where rowid=(select rowid from emp group by
rowid,rownum having rownum=&n)
A2:delete from emp where rowid=(select max(r) from
(select rowid r from emp where rownum Q:To delete a record where there are no employes working
A:delete from(select * from dept e where not exists
(select 'x' from emp d where d.deptno=e.deptno))
--> Q:To display the duplicate records
A:select col1,col2,col# ,count(*) from table group by col1,col2,col# h
aving
count(*)>1
--> Q:To delete duplicate recoreds
A:delete from tabel a where rowid in
(select rowid from table b minus select max(rowid)
from table c group by c.col1,c.col2,c.col#)
8/19/2019 pl/sql interview q
22/28
--> Q:To count the number of nulls and notnulls in Comm. column of emp
table
A:select count(decode(nvl2(comm,1,2),1,1)) nulls,
count(decode(nvl2(comm,1,2),2,1)) not_nulls from emp
--> Q:To select 1st and last record of the employee table
A: select * from(select rownum r,e.* from emp e)
where r=(select count(*) from emp) or r=1
--> Q:To count the number of sundays,mondays...saturdays..tot_days in
the current month
A:create table temp
(
num number(2)
)
insert into temp values(&num)
insert the values into temp from 1 to 31. and execute the below query
. select
count(decode(to_char(last_day(add_months(sysdate,-1))+num,'d'),1,1)) s
un,
count(decode(to_char(last_day(add_months(sysdate,-1))+num,'d'),2,1)) m
on,
count(decode(to_char(last_day(add_months(sysdate,-1))+num,'d'),3,1)
)tue,
count(decode(to_char(last_day(add_months(sysdate,-1))+num,'d'),4,1)
)wed,
count(decode(to_char(last_day(add_months(sysdate,-1))+num,'d'),5,1)) t
hu,
count(decode(to_char(last_day(add_months(sysdate,-1))+num,'d'),6,1)) fri,
count(decode(to_char(last_day(add_months(sysdate,-1))+num,'d'),7,1)) s
at,
to_char(last_day(sysdate),’dd’) tot_days
from temp where num Q:To select first and last record of employee table
A2: select * from emp where rowid in
(select rowid from emp group by rowid,rownum having rownum
8/19/2019 pl/sql interview q
23/28
in(1,(select count(*) from emp)))
A3:select * from emp where rowid in
(select min(rowid) from emp union select max(rowid) from emp)
--> Q:To display the second max sal
A:select max(sal) from emp where sal Q:To display top n salarys
A:select * from(select rownum r,e.* from(select distinct sal from emp
order
by sal desc) e) where r Q:To select bottom n salarys
A:select * from(select rownum r,e.* from
(select distinct sal from emp order by sal ) e) where r Q:To select first and last salary of the table
A:select * from(select rownum r,e.* from
(select distinct sal from emp order by sal desc ) e)
where r in(1,(select count(*) from emp))
--> Q:To select n to nth record
A:select * from(select rownum r,e.* from emp e)
where r between 4 and 7
--> Q:Display empno,ename,sal,max(sal) of their own dept ,max(SAL)
of the emp table of all the employes using with clause.
A:with maxsal as (select max(sal) max_sal from emp),dept_max as
(select deptno,max(sal) dept_maxsal from emp group by deptno)
select empno,ename,sal,(select max_sal from maxsal) maxsal,(select dep
t_maxsal from dept_max where
dept_maxsal.deptno=e.deptno) dept_max from emp e
--> Q:To find the empno,ename,deptno,maximum sal of the whole table,
maximum salary of the whole dept and minimum salary of the whole
department and dept name of the employee
A:select empno,ename,sal,deptno,(select max(sal) from emp) max_sal_ta
ble,
(select max(sal) from emp where deptno=e.deptno) dept_max,
(select min(sal) from emp where deptno=e.deptno) min_sal,
(select dname from dept
d where d.deptno=e.deptno) dname from emp e
--> Q:Display the employes whose salary is greater than his own
manager
A:select*from emp e where sal>(select sal from emp where empno=e.mgr)
8/19/2019 pl/sql interview q
24/28
--> Q:Disply the employes whose sal is greater than the other managers
A: select * from emp e where sal> any(select sal from emp
where empno in(select distinct mgr from emp where mgre.mgr))
--> Q:To find the employes who are seniour to the employes who are
joined in the year 1981.
A:SELECT HIREDATE FROM EMP WHERE HIREDATE Q:To fined the employes who have joined on the same hiredate
A: SELECT * FROM EMP WHERE HIREDATE IN
(SELECT HIREDATE FROM EMP GROUP BY HIREDATE HAVING COUNT(HIREDAT
E)>1)
--> Q:To find the uniquness of the given column for the given table.
A: SELECT 1 YES_UNIQUE FROM DUAL
WHERE 1=(SELECT MAX(COUNT(EMPNO)) FROM EMP GROUP BY EMPNO)
--> Q:To delete the managers who are working under king with salary
ranging from 2000 to 3000 and joined in first half of 1981
A:DELETE FROM EMP_D WHERE EMPNO IN
(SELECT EMPNO FROM EMP_D WHERE EMPNO IN
(SELECT DISTINCT MGR FROM EMP_D WHERE MGR
(SELECT EMPNO FROM EMP_D WHERE
ENAME='KING')) AND MGR=(SELECT EMPNO FROM EMP_D WHERE EN
AME='KING'))
AND (SAL BETWEEN 2000 AND 3000) AND (HIREDATE BETWEEN '1-JAN-81' AND '31-MAY-81')
--> Q:To delete all the employes who have joined most recently under
king.
A: DELETE FROM EMP44 E WHERE MGR=(SELECT EMPNO FROM EMP44
D WHERE ENAME='KING' AND HIREDATE>E.HIREDATE)
--> Q:To delete all the grade 1 and grade 2 employes and woring in
chicago and joined in the first half of 81.
A: SELECT E.EMPNO,E.ENAME,S.GRADE,D.LOC,E.HIREDATE FROM SALGRADE
S, DEPT
D, EMP E WHERE E.DEPTNO=D.DEPTNO AND E.SALBETWEEN S.LOSAL AND S.HISAL
AND S.GRADE IN(1,2) AND D.LOC='CHICAGO'
AND E.HIREDATE BETWEEN '01-JAN-81' AND '30-JUN-81'
--> Q:To delete all the employes with experience 4
8/19/2019 pl/sql interview q
25/28
AND JOB LIKE '%MAN')
--> Q:Delete all the employes of sales department whose salary ranging
from 1500 to 3000
A: DELETE FROM EMP44 WHERE EMPNO IN(select e.empno from emp44 e,dept
d where e.deptno=d.deptno
AND d.dname='SALES' AND E.SAL BETWEEN 1500 AND 3000)
--> Q:To delete all the grade 2 and 3 employes of sales dept and
working at chicago and joined after the all the employes whose
hiredate is in the year1980.
A:DELETE FROM EMP44 WHERE EMPNO IN(SELECT E.EMPNO FROM EMP44 E,DEPT
D,SALGRADE S
WHERE E.DEPTNO=D.DEPTNO
AND E.SAL BETWEEN S.LOSAL AND S.HISAL
AND S.GRADE IN(2,3)
AND D.DNAME ='SALES'
AND D.LOC='CHICAGO'AND
HIREDATE>ALL(SELECT HIREDATE FROM EMP44 WHERE HIREDATE LIKE'%80'))
--> Q: Delete the emps whose salary is lowest salary of their own
deptartment
A: DELETE FROM EMP44 WHERE EMPNO IN
(SELECT EMPNO FROM EMP44 WHERE SAL IN
(SELECT MIN(SAL)
FROM EMP44 GROUP BY DEPTNO))
A2.delete from emp e where sal =(select min(sal) from emp
d where d.deptno=e.deptno)
--> Q: To find the employes who are seniour to their own managers.
A: SELECT * FROM EMP E WHERE HIREDATE<
(SELECT HIREDATE FROM EMP WHERE EMPNO=E.MGR)
--> Q:To find the employes who are seniour to their own managers using
corelated sub query.
A: DELETE FROM EMP44 WHERE EMPNO IN
(SELECT E.EMPNO FROM EMP44 E WHERE
HIREDATE Q:To find the employes who are seniour to their own manager using
self join.
A: SELECT E.* FROM EMP E,EMP
D WHERE E.MGR=D.EMPNO AND E.HIREDATE Q: Delete the employes whose experience greater than four.
A: delete from emp where hiredate in(select hiredate from emp where (m
onths_between(sysdate,hiredate)/12)>4)
8/19/2019 pl/sql interview q
26/28
--> Q: To list the employes whose salary is less than his own manages
and greater than any of the other managers.
A: select * from emp e where sal any(select sal from emp
where empno in(select distinct mgr from emp where mgre.mgr))
--> Q:To display the employee name and this manager name for each
record selected.
A: SELECT E.EMPNO,E.ENAME,D.ENAME MGR_NAME FROM EMP E,EMP
D WHERE D.EMPNO=E.MGR
--> Q:To display all the employes who are working under blake and
display the manager name along with the select list.
A: SELECT * FROM(SELECT E.*,D.ENAME MGR_NAME FROM EMP E,EMP
D WHERE E.MGR=D.EMPNO ) WHERE MGR_NAME='BLAKE'
--> Q:To find the employes who are seniour to all the other managers.
A:SELECT * FROM EMP E WHERE HIREDATE Q:To count the m's and f's from the column and display in the same
row like
A:SELECT COUNT(DECODE(GENDER1,'M',1)) M, COUNT(DECODE(GENDER1,'F',1))
F FROM GENDER
--> Q:To find the emps who are senior to his own manager and junior toany one of the other managers
A: select * from emp e where hiredate any(SELECTHIREDate from emp where empno
IN(SELECT DISTINCT MGR FROM EMP
WHERE MGR (SELECT EMPNO FROM EMP WHERE EMPNO=E.MGR)))
--> Q:To convert the given number into string format.
A:SELECT TO_CHAR(TO_DATE(SAL,'J'),'JSP') SAL_STRING,SAL FROM EMP
Q:To find the employes who have joined on the same hiredate.
A: select*from emp where hiredate in(select hiredate from(select hired
ate, count(hiredate) from emp group by hiredate
having count(*)>1))
--> Q:To delete nth record.
A: delete from emp44 where rowid=(select rowid from emp44 group by row
id,rownum having rownum=&n)
--> Q:To find the uniqueness of any given cloumn in a given table.
A: SELECT CASE
8/19/2019 pl/sql interview q
27/28
WHEN COUNT( DISTINCT &COLUMN)=COUNT(*)
THEN
'YES_UNIQUE'
ELSE
'NOT_UNIQUE'
END CASE
FROM &TABLE
--> Q:To find nth minimum salary.
A:select * from(select rownum r,e.* from
(select distinct(sal) from emp order by sal)e)where r=&n
--> Q:To find nth minimum salary.
A: select * from(select rownum r,e.* from
(select distinct(sal) from emp order by sal)e)where r=&n
--> Q:To delete the duplicate records existing.
A: delete from emp_dups e where rowid Q:To count the number of nulls and notnulls.
A:SELECT COUNT(*)-COUNT(DECODE(NVL(COMM,1),1,1)) NOT_NULLS,
COUNT(DECODE(NVL(COMM,1),1,1)) NULLS FROM EMP
--> Q:To select the duplicate records.
A: select e.* from emp_dups e where rowid Q:To find the hirearchey of the employee table
A; select level, e.* from emp e connect by prior empno=mgr start
with mgr is null
--> Q: To incrimentally update the employee table from nth row
A: update emp set empno=rownum+999 where rowid >
(select max(rowid) from emp where
rownum Q: To incrementally update the table where mgr is null
A: update emp set empno=rownum where rowid in
(select rowid from emp where comm is null)
--> Q:To select from nth record to nth record.
A: select * from(select rownum r,e.* from emp e)
8/19/2019 pl/sql interview q
28/28
where r between &n and &m
--> Q:To select the given records
A:select * from(select rownum r,e.* from emp e)
where r in(3,5,6)
--> Q:TO delete the nth record
A:delete from emp where rowid=
(select rowid from emp group by rownum,rowid
having rownum=&n )
--> Q:TO delete the given set of records
A:delete from emp where rowid in
(select rowid from emp group by rownum,rowid
having rownum in (4,5,6) )