7/25/2019 Oracle Interview Ques & Ans
1/44
SQL/PLSQL INTERVIEW QUESTION
AND ANSWER
1. SQL:- Structured query language is a specialized languagefor Updating, Deleting, and Requesting information from
Database. Developed by IBM in!"#$s.
2. PL/SQL:% &'(S)' is a procedural language t*at *as bot*interactive S)' and procedural programming language
constructs suc* as interaction, conditional branc*ing.
3. ORACLE:% +*e racle Database is an ob-ect relational Database management system produced and mared by racle
/orporation.
4. META-DATA:% Meta%data is data about data. Meta data isstructured data 0*ic* describes t*e c*aracteristics of a
resource.
5. Query:% +o retrieve data from t*e data base table is calledquery.
. A!!r"#u!e:% It is a particular property, 0*ic* describes t*e
entity.$. %"e&':% 1very table is broen up into smaller entities called
2eld. 34ield in t*e customers table consists of ID,
5ame, 6ddress, 6ge and Salary.
(. T)#&e:% +able is a container t*at *olds information aboutlie items.
4or%17am8% 6n 1mployee table 0ould contain t*e samebasic details on eac* employee 5ame, +itle, Department and
So n.
*. T)#&e-S+),e:% +.S is a logical Storage structure at t*e*ig*est level t*at stores all t*e data in data 2les.
7/25/2019 Oracle Interview Ques & Ans
2/44
1. D)!)-)e:% 6 D.B is a logical /ollection of relevantdata, re9ecting some in*erent meaning, representing some
aspect of real 0orld.
11.DMS:- It is a collection of programs t*at enables user tocreate and maintain a Database.
12.RDMS:- RDBMS stands for Relational DatabaseManagement System. It rganizes data into related ro0s and
columns.
13.Se0ue,e:- Sequence is a user created Database ob-ectt*at can be s*ared by multiple user to generate unique
integers.
14. E!"!y:- It is a t*ing in t*e real 0orld 0it* anindependent e7istence.
15. Re&)!""+:- It is an association among t0o or moreentities.
1. C&u:- 6 column is a vertical entity in a table t*at
contains all information associated 0it* a speci2c 2eld in a table.
1$. Nr)&")!":- 5ormalization is a process 0it* 0*ic*0e can reduce t*e redundancy . R
5ormalization means t*e process in 0*ic* ro0 data is converted
into 2ltered data.
:. 548%+able t*at contains one or more repeating groups
identi2es and remove repeating group.
:. ;548% Describe a table i.e. fully functionally dependent.
1(. W)! " V"e67 Ty+e 8 9"e6
7/25/2019 Oracle Interview Ques & Ans
3/44
: 1mp%Id> 1mp name> 1mp addr> Select emp ? id from emp>
Synta78%/reate
7/25/2019 Oracle Interview Ques & Ans
4/44
+ypes of Inde78%
@A. /lustered 3 Inde7 or 5ormal 3 Inde78%
% /lustered Inde7 is a special type of inde7 t*at records t*e 0ay
records in t*e table are p*ysically stored.
% +*e leaf nodes of a clustered inde7 contain t*e data page.
% /lustered Inde7 is p*ysically stored a table can *ave clustered
Inde7.
@;A. 5on 3 /lustered % Inde7 or Bitmap 3 Inde78%
% 5on%/lustered Inde7 is a special type of inde7 in 0*ic* t*e
logical order of t*e inde7 does not matc* t*e p*ysical storedorder of t*e ro0s on dis.
% +*e leaf nodes of a non%clustered inde7 do not consist of t*e
data page.
% 5on%/lustered Inde7 is logically stored a table can *ave ;!
5on%/lustered Inde7.
@EA. 4unctional based % Inde78%%+*ey are based on e7pressions.
%1nable query to evaluate value returned by an e7pression.
@A. Domain % Inde78%
%+*ey are Inde7 0*ic* are instances of an application speci2c
Inde7 of type Inde7.
2. D"
7/25/2019 Oracle Interview Ques & Ans
5/44
: = %r)>e!)!"
&aging occurs in memory 0*ereas.
4ragmentation occurs on dis.
22. D"
7/25/2019 Oracle Interview Ques & Ans
6/44
&rocedure can return one or more t*an one values t*roug*
parameter. &rocedure cannot.
&rocedure support DM', DD'.
&rocedures tae in, out, in out parameter. &rocedure does not return a value.
25. D"
7/25/2019 Oracle Interview Ques & Ans
7/44
/ommit, save point and rollbac are allo0ed.
Data dictionary contains source code in user source.
+/' commands are allo0ed.
2$. D"
7/25/2019 Oracle Interview Ques & Ans
8/44
2*. D"
7/25/2019 Oracle Interview Ques & Ans
9/44
Drop is t*e DD' Statement.
Drop commands remove t*e table from data dictionary.
Rollbac is not possible.
5o +riggers 0ill be 2red.
31. D"
7/25/2019 Oracle Interview Ques & Ans
10/44
It is used 0*en 0e 0ant t*e database to be s*ared 0it*
ot*er user. Hrant 0ill give permission to t*e user on database.
H./ is used to provide access or privileges on t*e database
ob-ects to t*e user. Synta78% S)'HrantJ&rivilege name,J&rivilege name;,
on Jb-ect name +o JUser name
178 % S)' Hrant select on 1%mp to 1nd users.
: Revoe /ommand8%
It is used 0*en 0e 0ant one database to stop s*aring t*e
information 0it* ot*er user.
Revoe 0e can remove t*e permission. R./ removes user access rig*ts or privileges to t*e database
ob-ects.
Synta78% S)'HrantJ&rivilege name,J&rivilege name;,
on Jb-ect name from JUser name 178 % S)' Revoe insert, delete on 1mp from operators.
:&rivilege8 % 6bility to compile t*e function( procedure.
6bility to e7ecute t*e function( procedure directly.
33. D"
7/25/2019 Oracle Interview Ques & Ans
11/44
/ase is a statement.
34. D"
7/25/2019 Oracle Interview Ques & Ans
12/44
3. D"
7/25/2019 Oracle Interview Ques & Ans
13/44
3(. W)! " Su# 0uery Ty+e 8 Su# 0uery
: Sub query8 %Sub query can be de2ned as a select query t*at
returns single or multiple values.
+ypes of Sub query8%
@A Single ro0 Sub query8 %+*ese query return only one
ro0 from t*e inner select statement is called Single ro0 sub
query.178 % N 8 J> J> > N> JN. : Select from emp 0*ere salary N @select salary from
emp 0*ere emp idN @#AA>@;A Multi ro0 Sub query8 %+*ese query return more t*an
one ro0 from inner select statement.178% I5> 65G> 6''. : Select. e name, sal, Dept no from emp 0*ere sal in
@select min @salA from emp group by dept noA>Synta78 %S)' Select Select 'ist from +able 5ame 0*ere
/olumn 5ame operator @select select 'ist from +able 5ameA>
3*. W)! " Curr Ty+e 8 Curr.
% /ursor is a mec*anism by 0*ic* you can assign a name to aOSelect StmtP and manipulate t*e information 0it*in t*e S)'
Statement.
% /ursor is a private S)' are used to e7ecute S)' Statement.
+0o +ypes of /ursor8%
@A. Implicit % /ursor8 %It is automatically declared by racle
server. It is private memory area allocated by .S.
@;A. 17plicit 3 /ursor8 %It is declared by programmer or user. It is
easy to trap error.
%ur S!e+ ! +er8r e;+&","!
,urr:-
7/25/2019 Oracle Interview Ques & Ans
14/44
@A/ursor Declaration8 % In t*e Declaration section.@;A/ursor pening8 % In t*e 17ecution section.@EA/ursor 4etc*ing8 % 4etc* t*e data from cursor into &'(S)'
variables or records in 17ecution Section.
@A/ursor /losing8 % /lose t*e cursor in t*e 17ecution sectionbefore you end t*e &'(S)' Bloc.
B Curr A!!r"#u!e 8ur Ty+e:-@A. S)' L Ro0 /ount8 % 5umber Return.@;A. S)' L Is pen8 %+(4 Return.@EA. S)' L 4ound8 %+(4 Return.@A. S)' L 5ot 4ound8 %+(4 Return.
BCurr A'9)!)>e:-
% Using /ursor to getting multiple values.% ne /ursor *as multiple Select Statement.
BCurr D")'9)!)>e:-% It is returned by only one ro0 at a time.% It gives less performance.% 1ac* time 0e fetc* a ro0 from t*e /ursor, 0*ere as a
normal cursor select statement query maes only
one trip. BCurr E;)+&e:-
(( Declaring a cursor ((
/ursor 1M& ?/ursor is
Select 1M& no, 1 name, Sal from 1M&>
Begin
(( pening a cursor ((
pen 1M& ? /ursor>
'oop
7/25/2019 Oracle Interview Ques & Ans
15/44
(( 4etc*ing records from a cursor ((
4etc* 1mp ? /ursor into
(( /losing t*e /ursor ((
/lose 1M& ? /ursor>
DBMS?utput. put?line @ODonePA>
1nd>
4. W)! " Tr">>er Le9e& 8 Tr">>er Ty+e 8
Tr">>er
: +rigger8 % 6 +rigger is a &l(S)' bloc structure 0*ic* is 2red
0*en a DM' statement lie, Insert, Delete, Update is e7ecuted on
a data base table. 6 trigger is triggered automatically 0*en an
associated DM' statement is e7ecuted.
OR
% +rigger is lie as procedure. +*is procedure 0ill call at some
events and occurring. 'ie Insert, Update, Delete.% 178% 6+M Mac*ine .
7/25/2019 Oracle Interview Ques & Ans
16/44
% 178% /reate table product@&roduct?id number @CA, &roduct?
name >er:-@A. Ro0 level of +rigger8 % 6n event is triggered for eac* ro0
updated, inserted or deleted.178 % /reate or Replace +rigger Deptupdate after update on
Dept 4or eac* ro0.
@;A.Statement level of +rigger8% % 6n event is triggered for
eac* S)' Statement e7ecuted.178 % /reate or Replace +rigger Dept Delete after Delete on
Dept.
B Tree Ty+e 8 Tr">>er:-@A. Before % +rigger8%+*ese trigger 2re before any
transaction are implemented lie Insert, Update and Delete.
@;A. 6fter % rigger8%+*ese trigger 2re after any transaction is
implemented lie Insert, Update and Delete,
@EA. Instead of +rigger8 %+*ese are special bind of trigger t*atis de2ned on data base vie0.
41. W)! " " Ty+e 8 "
oin8 %oin is a query t*at combines ro0s from t0o or more
tables, vie0s or materialized vie0s.
% 6 oin is performed 0*enever multiple tables appear in t*e
queries from clause.
178%oin queries are used to select data for multiple tables and
display t*at data in a single (&.
Synta78%=*ere +able . /olumn N +able ;. /olumn ;.
178%S)' Select 1mp no, 1 name, D name, 'oc from 1mp, Dept>
7/25/2019 Oracle Interview Ques & Ans
17/44
r8 %S)' Select 1mp no, 1 name, Sal, Hrade from 1mp, sal
Hrade>
B%ur Ty+e 8 ":-
1. E0u" r S"+&e r Ier ":- Returns t*e ro0s from t0o
or more tables -oined toget*er based upon a equality conditions
in t*e 0*ere clause.
E;:- Select from emp, dept 0*ere emp dep no N dept . dept no>
2. N - E0u" ":- Returns t*e ro0s from t0o or more tables
based upon a relations*ip ot*er t*an t*e equality conditions in
t*e 0*ere clause.
E;:- Select 1. 1 name, 1. Sal, S Hrade 4rom 1mp 1, Sal Hrade S
0*ere 1. Sal Bet0een S. 'osal 65D S.Tisal>
3. Se&8 - ":- Self 3 oin -oins a table to itself. Basically it is for
t*e Tierarc*ical relations*ip.
E;:- Select 1. 1 name, 1;. 1 name from 1mp 1, 1mp 1; 0*ere
1 . Mgr N 1;. 1M& no>
Sy!);:- S)' Select /olumns 4rom +able +, +able +; 0*ere+. /olumn N +;. /olumn ;.
4. Ou!er - ":- uter oin combines t0o or more tables
returning t*ose ro0s from one table t*at *ave no direct matc* in
t*e ot*er table.
E;:- Select 1. 1 name , D. Dept 5ame from 1mp 1, Dept D 0*ere
e. dept no N D. Dept no@A>
Sy!);:- Select +able. /olumn, +able;. /olumn from +able,
+able; 0*ere +able. /olumn N +able;. /olumn @A>
42. W)! " Pr,e'ure Ty+e 8 Pr,e'ure
7/25/2019 Oracle Interview Ques & Ans
18/44
&rocedure8% &rocedure is a type of sub program t*at performs an
actions.
% &rocedure may return one or more values t*roug* parameters or
may not return at all. BTree Ty+e 8 Pr,e'ure:-
@A. In 3 Mode8% It is read only value from calling environment.
@;A. ut 3 Mode8%It is 0rite only value from calling environment.
@A. In (ut3 Mode8% It is read and 0rite only value from calling
environment.
B S!re' F Pr,e'ure:- Stored 3 &rocedure is a sequence ofstatement t*at perform speci2c function.
43. W)! " %u,!" Ty+e 8 %u,!"
4unction8 % 4unction is al0ays returns a value using t*e return
statement.
B T6 Ty+e 8 %u,!":-
@ASingle Ro0 4unction8 %+*ese functions return a single result
for every ro0 of a queried table or vie0.% Single ro0 function are used to manipulate data Items.
@;AMulti Ro0 4unction8%+*ese functions manipulate group of
ro0s and return one result per group of ro0s.% Multi ro0s function or aggregate functions are SUM> M6>
MI5> 6 /U5+.
44. W)! " ASCII - %u,!"
It returns t*e 6S/II representation in t*e c*aracter Database
set of 4irst /*aracters of t*e /T6R.
Synta78 %S)' S1'R/+ 6S/II @6$A, 6S/II @6&&'1$A 4RM DU6'>
7/25/2019 Oracle Interview Ques & Ans
19/44
45. G6 M)y !y+e 8 SQL " Or),&e
+*ere are 2ve types of S)' in racle.
@A. Data Retrieval statement8%
% Select Statement.
@;A. Data Manipulation 'anguage @DM'A statement8%
% It is used to retrieve, store, modify, delete, insert and update
data in database.
% Insert> Update> Delete Statement.
@EA. Data De2nition language @DD'A statement8%
% It is used to create and modify t*e structure of database ob-ects
in database.
% /reate> 6lter> Drop> Rename> +runcate Statement.
@A. +ransaction /ontrol 'anguage @+/'A Statement8%
% It is used to manage diFerent transaction occurring 0it*in a
database.
% /ommit> Rollbac> Save point Statement.
@CA. Data /ontrol 'anguage @D/'A statement8%
% It is used to create roles, permissions and referential integrity as
0ell it is used to control access to database by searc*ing it.
% Hrant> Revoe Statements.
4. W)! " Se&e,!7 Ier!7 De&e!e = U+')!e
S!)!ee!
H Se&e,! S!)!ee!:- It is used to select data from a data base.
7/25/2019 Oracle Interview Ques & Ans
20/44
% +*e select statement is used to retrieve Data from ne or More,
+ables> b-ect tables> b-ect Materialized vie0s.
Sy!);8% select column ? name from table ? name
6nd8 % Select from table ? name
E;8% select 2rst ? name from student ? details>
r Select name, age, salary from employee 0*ere age C#>
H Ier! S!)!ee!:- It is used to add ne0 ro0s of data to a
table.
Sy!);8% Insert into table ? name @/olumn, /olumn;, /olumnEA
7/25/2019 Oracle Interview Ques & Ans
21/44
/olumn 6lias8 % /olumn 6lias renames a column *eading in a
query.
% 6lias *eading appears in upper casing by Default.
+able 6lias8 %+able 6lias Renames t*e riginal name of t*e tablein a S)' Statement.
% +able 6lias are very important 0*en 0oring 0it* self -oins.
% +*e +able 6lias is applied for t*e current S)' Statement only.
Sy!);8% Select /olumn ? 5ame @sA from table ? name as alias ?
name.
E;8% Select 2rst ? name 6s name from Student ? details>
(&8%Ra*ul S*arma, Ra-nis* r, &riya /*andra, 6s*utos* mis*ara.
4(. W)! )re @ru+ #y7 Or'er y7 = )9"> #y
@ru+ y8%
% +*e Hroup by clause is used along 0it* t*e group functions to
retrieve data grouped according to one or more columns.
4or 178 % If U 0ant to no0 t*e total amount of salary spent on
eac* department, t*e query 0ould be8%
Synta78 % Selectcolumn, sum @/olumn ;A from Olist of tableP
Hroup ByP /olumn 3 listP>
178%Select dept, sum @SalaryA from employee group by dept>
Or'er y8%+*e order by clause is used in a select statement tosort results eit*er in ascending or descending order. racle sorts
query results in ascending order by default.
4or 178%If U 0ant to sort t*e employee table by salary of t*e
1mployee, t*e S)' query 0ould be.
7/25/2019 Oracle Interview Ques & Ans
22/44
178 %Select name, salary from employee order by salary.
G)9"> y8 % Taving clause is used to 2lter data based on t*egroup functions. +*is is similar to 0*ere condition but is used 0it*
group functions. Hroup functions cannot be used in 0*ere clausebut can be used in *aving clause.
178 % Select dept, Sum @SalaryA from employee group by dept
Taving Sum @SalaryA ;C###.
4*. W)! " 6ere ,&)ue
% =*ere clause is used 0*en you 0ant to retrieve speci2c
information from a table e7cluding ot*er irrelevant data.
178%+*e 0*ere clause is used to e7tract only t*ose records t*at
ful2ll a speci2ed criterion.
Synta78% Select column ? name from table ? name 0*ere column
? name operator value.
178%Select from persons 0*ere city N &6+56$
5. W)! " O+er)!r Ty+e 8 O+er)!r
1. A' F O+er)!r: - 4or a ro0 to be selected all t*e speci2ed
condition must be true.
178 % Select 1name, Sal, dept no, ob from 1M& 0*ere dept noN ;#
6nd ob N M656H1R$>
2. Or F O+er)!r: -4or a ro0 to be selected at least one of t*e
conditions must be true.
178 % Select 1nema, Sal, dept no, ob from 1M& 0*ere dept noN ;#
r ob N M656H1R$>
3. N! F O+er)!r: -4or a ro0 to be selected t*e speci2ed
condition must be false.
7/25/2019 Oracle Interview Ques & Ans
23/44
178 % Select 1name, sal, ob from 1M& 0*ere 5ot ob N
M656H1R$>
51. 6)! " I O+er)!r7 e!6ee )' O+er)!r = I
Nu&& O+er)!r
H I O+er)!r: -+*is operator can be used upon any data type.
% +*is perator is used to test for values in a speci2ed list.
178%Select 1name, Sal, -ob from 1mp 0*ere 1name I5
@4RD$,$6''15$A>
H e!6ee A' O+er)!r: -+*is perator is used to display
ro0s based on a range of value.
% +*e 'o0er 'imit s*ould be declared 2rst.
178%Select 1name, Sal, ob from 1mp =*ere sal Bet0een ###
65D C##>
H I Nu&& O+er)!r:-+*is perator test for 5ull
7/25/2019 Oracle Interview Ques & Ans
24/44
178%Select 1name, ob, 4rom 1mp 0*ere 1name 'ie SL$ >
53. W)! " Sy')!e
% It is a date function t*at returns current date and time.
% Sysdate is generally selected upon a dummy table.
178% S)' Select Sysdate from Dual>
54. W)! " Se! O+er)!r
Set perators are used to combine information of similar data
type for one or more t*an one table.
DiFerence types of set operator.
. Union.;. Union all.E. Interacted.. Minus.
55. W)! " Peu' F C&u
% &seudo 3 /olumn is an act as a data base table column, but it$s
not a actual column in a table. =e can fetc* values from a pseudocolumn.
% &seudo 3 /olumn be*aves lie a table column, but is not actually
stored in a table.
E;8% User> User Id> Ro0 num> Ro0 Id> 'evel> 5e7t /urval>
Sysdate
5. W)! " E;,e+!" Ty+e 8 e;,e+!"% 17ception is an identi2er in &'(S)' raised during t*e e7ecution
of bloc.
% Run time error is called e7ception.
+*ree types of 17ception.
7/25/2019 Oracle Interview Ques & Ans
25/44
. &rede2ned8% It can be only *andle.
;. User 3 De2ned8% It can be declare, raise *andle.
E. 5on 3 &rede2ned8% De2ne and Tandle.
5$. W)! " P),?)>e Ty+e 8 P),?)>e
% &acage is a met*od to *andle all t*e required function and
procedure toget*er.
% &acage cannot be e7ecuted.
% &acage cannot be nested.
It consists of t0o parts8%
A. &acage 3 Speci2cation8 % &.S contains information about t*e
content of pacage and global K public variable.
;A. &acage 3 Body8 % &.B contains t*e actual e7ecutable code for
t*e ob-ect describe in t*e pacage speci2cation.
5(. W)! " L"!er)& Ty+e 8 L"!er)&
'iterals and /onstants value are synonyms to one anot*er andrefer to a 27ed data value.
+ypes of 'iterals recognized by racle are8%
A. +e7t 'iterals.
;A. Integer 'iterals.
EA. 5umber 'iterals.
A. Interval 'iterals.
178% 1mployee Information Manager$ s speci2cation 5$ 5c*ar
'iteral.
5*. W)! " Syy Ty+e 8 Syy
7/25/2019 Oracle Interview Ques & Ans
26/44
Synonyms is an alternative name for ob-ects suc* as +ables, 178 % S)' /reate Synonyms 1M& Info for Scott. 1M&>
+ypes of Synonyms8%
A. &rivate Synonym.
;A. &ublic Synonym.
. W)! " Mer>e S!)!ee!
+*e Mere Statement is used to select ro0s from one or more
sources for update or Insert into one or more table.
178% S)' /reate +able My Bonus @1mp no 5umber, Bonus
5umber Default ##A>
1. W)! " M)!er")&"e' V"e6
% 6 M.< is a data base ob-ect t*at contains t*e result of a query.
% M.< are used in data 0are *ouses and data Marts.
178 % S)' Hrant )uery Re0rite +o S/++>
S)' Hrant /reate Materialized vie0 +o S/++>
2. W)! " O#e,! T)#&e
% b-ect +ables are created by using t*e user de2ned data types.
% In b-ect table eac* ro0 or record is treated as an ob-ect.
Synta78 % /reate or replace +ype J +ype 5ame as ob-ect
@/olumn 5ame Data +ype @SizeA, /olumn 5ame ; Data +ype
@SizeA, /olumn 5ame 5 Data +ype @SizeAA,
7/25/2019 Oracle Interview Ques & Ans
27/44
3. W)! " O#e,! V"e6 = I&"e V"e6
b-ect
7/25/2019 Oracle Interview Ques & Ans
28/44
;A. Unique /onstraints.
EA. &rimary Yey /onstraints.
A. 4oreign Yey /onstraints.
CA. /*ec /onstraints.
VA. Default ( Ref /onstraints.
. W)! )re N! Nu&&7 U"0ue7 Pr")ry Jey7
%re"> Jey7 Ce,? C!r)"! )' De8)u&!
+!"
5ot 5ull8% 6 5ot 5ull /onstraints pro*ibits a column fromcontaining 5ull
7/25/2019 Oracle Interview Ques & Ans
29/44
4oreign Yey8% 6 4.Y is one or more column 0*ose value must e7it
in t*e primary ey of anot*er table
/*ec /onstraints8% It de2nes a condition t*at eac* ro0 Must
satisfy.% +o satisfy t*e constraint, eac* ro0 in t*e table must mae t*e
condition eit*er true or unno0n.
Default ption8%+*e Default option is given to maintain a
default value in a column.
% +*e Default value can be literal, an e7pression or a S)' function.
% +*e Default e7pression must matc* t*e data type of t*e column. /omposite ey8%+*e /ombination of t0o or more t*an t0o eys
0*ic* identi2es entities uniquely.
Super Yey8 % 6ll possible ey 0*ic* can identify entities in t*e
table uniquely.
6lternate Yey8% Rest of t*e condition ey 0*ic* is not t*e
primary ey.
$. W)! " @ru+ 8u,!"
Hroup function is built in S)' functions t*at operate on groups of
ro0s and return one value for t*e entire group.
+*ese functions are8 % /ount> Ma7> Min > 6vg > Sum> Distinct.
(. W)! " Cu! = D"!",!
/ount8%+*is function returns t*e number of ro0s in t*e tablet*at satis2es t*e condition speci2ed in t*e 0*ere condition.
178 % If U 0ant t*e 5o of employees in a particular department,
t*e query 0ould be8 %Select /ount @A from employee 0*ere dept
N 1lectronics$>
7/25/2019 Oracle Interview Ques & Ans
30/44
Distinct8%+*is function is used to select t*e distinct ro0s.
178% If U 0ant to select all distinct department names from
employee table, t*e query 0ould be8% Select Distinct dept 4rom
employee>
% +o get t*e count of employees 0it* unique name, t*e query
0ould be8%Select count @DIS+I5/+ 5ameA from employee>
*. W)! )re M"7 M);7 A9er)>e )' Su %u,!"
Minimum @MI5A 4unction8% +*is function is used to get t*e
minimum value from a column. 3 It ignores 5ull values.
178%+o get t*e minimum salary dra0n by an employee t*e query
0ould be8%
% Select MI5 @SalaryA from employee.
Ma7imum @M6A 4unction8% +*is function is used to get t*e
ma7imum value from a column. It ignores 5ull values.
178%+o get t*e ma7imum salary dra0n by an employee t*e query
0ould be8%
% Select M6 @SalaryA from employee.
6verage @6vgA 4unction8%+*is function is used to get t*e average
value of a numeric column. % It ignores 5ull values.
178%+o get t*e average salary t*e query 0ould be 8%
% Select 6vg @SalaryA from employee.
Sum 4unction8%+*is function is used to get t*e sum of a numeric
column.
% It ignores 5ull values.
7/25/2019 Oracle Interview Ques & Ans
31/44
178%+o get t*e total salary given out to t*e employee t*e query
0ould be 8%
% Select Sum @SalaryA from employee.
$. W)! " C9er" %u,!" Ty+e 8C9er" %u,!"
+*e /onversion function converts a value from one data type to
anot*er.
+0o types of /onversion function8%
A. Implicit Data +ype /onversion8% Implicit Data +ype /onversion
0or according to t*e conversion speci2ed by oracle.
% /T6R to D6+1 conversions succeed only if t*e c*aracter strings
represent t*e default format of date. DD 3 M5 % GG.
%
7/25/2019 Oracle Interview Ques & Ans
32/44
% It returns t*e standard deviation of t*e column.
% It ignores 5ull
/ount 4unction8%
% It returns t*e number of ro0s in t*e query.
% If $ is used returns all ro0s, Including duplicated and 5U''S.
178% Select /ount @A 4rom 1mp>
% Select /ount @SalA, /ount @/ommA from 1mp>$3. W)! " D)!e %u,!"
6dd Mont* 4unction8%% It returns t*e Date D$ plus or minus n$ Mont*s.% +*e argument n$ can be any positive or 5egative Integer.178%S)' Select sysdate , 6dd% Mont*s @Sysdate,;A from Dual>
Mont* bet0een 4unction8%% It returns number of mont*$s b(0 dates d$ and d;$
% If d$ is later t*an d;$, t*e result is
7/25/2019 Oracle Interview Ques & Ans
33/44
% Mostly used to determine *o0 many days are left in t*e
current Mont*.178 % S)l Select Sysdate, 'ast ? Day @SysdateA 'ast day from
dual>
$4. W)! " Su# S!r">K I S!r"> %u,!"
Sub String8% Returns speci2ed c*aracters from c*aracter value,
Starting from a speci2ed position m$ to n$ c*aracters long.
178% Select 6B/D14HT$ string , SUBS+R @6B/D14HT$,E,A sub
string from DU6'>
In Sting 4unction8% It returns t*e 5umeric position of a named
c*aracter.
178%Select S+RI5H$ String InS+R @S+RI5H$, R$A In string from
Dual>
$5. W)! " LPADK RPAD %u,!"
'&6D8% &ads t*e c*aracter value rig*t -usti2ed to a total 0idt*
of n$ c*aracter positions.
%+*e default padding c*aracter is space.
Synta78% '&6D @/*ar, n, c*ar;$A
178% Select $page$ string '&6D @&age$, C, $A ' &added from
Dual>
R&6D8% &ads t*e c*aracter value left -usti2ed to a total 0idt* of
n$ c*aracter positions.
%+*e default padding c*aracter is space.
Synta78% R&6D @/*ar, n, c*ar;$A
178% Select $page$ string R&6D @&age$, C, $A R &added from
Dual>
$. W)! " LTRIMK RTRIM %u,!"
7/25/2019 Oracle Interview Ques & Ans
34/44
' +RIMS 4unction8% It enables to +RIM Teading c*aracters from a
c*aracter string.
% 6ll t*e leftmost c*aracters t*at appear in t*e set are removed.
Synta78% ' +RIM @/*ar, S1+A
178% Select ob, ' +RIM @ob, M65$A ' +rimmed 4rom 1mp =*ere
ob 'ie M656H1R$
R +RIMS 4unction8% 8% It enables t*e trimming of trailing
c*aracters from a c*aracter string.
% 6ll t*e Rig*t most c*aracters t*at appear in t*e set are
removed.Synta78% R +RIM @/*ar, S1+A
178% Select R +RIM @ob, 1R$A, ob 4rom 1mp =*ere ' +RIM @B,
M65$A 'IY1 H1R$>
$$. W)! " TRIMK REPLACEK Tr)&)!e )' CGR
%u,!"
+RIM 4unction8% It enables to trim Teading or trailing c*aractersor bot* from a c*aracter string.
% If 'eading is speci2ed concentrates on leading c*aracters.
% If +railing is speci2ed concentrates on +railing c*aracters.
Synta78%+rim @'eading ( +railing( Bot*, +rim c*ar 4rom +rim
SourceA
178% Select MI+TSS$ String +RIM @S$ 4rom$ MI+TSS A +rimmed4rom Dual>
R1&'6/1 4unction8% It returns t*e every occurrence of searc*
string replaced by t*e replacement string.
7/25/2019 Oracle Interview Ques & Ans
35/44
% It substitutes one string for anot*er as 0ell as removes
c*aracter strings.
Synta78% Replace @/*ar, Searc* ? Str, Replace ? StrA
178% Select 1 name, Replace @B, M65$, D6M$A Replaced from1mp 0*ere ob N M656H1R$ >
+ranslate 4unction8 % Used to translate c*aracter by c*aracter in
a string.
Synta78 %+ranslate @/*ar, 4rom, +oA
178 % Select ob, +R65S'6+1 @ob, &$, A 4rom 1mp 0*ere ob N
&R1SID15+> /T6R 4unction8 % It returns a c*aracter *aving t*e 6S/II
1quivalent to n$.
% It returns t*e 1quivalent for n$ in data base c*aracter set or
5ational /*aracter set.
Synta78 % /TR @n USI5H 5/T6R ? /SA
178 % Select /TR @V"AQQ /TR @VCAQQ /TR @ZA Sample 4rom Dual>$(. W)! " OLAPK ROLLUP
'6&8% Some features for query processing in R6/'1 include
t*e use of 5'I51 656'G+I/6' &R/1SSI5H @'6&A Upon t*e
Data base.
% '6& features are useful for Data 0are*ousing and data mart
applications.
% '6& operations are performance en*ancements.
+& ? 5 )U1RI1S.
HRU& By.
/UB1.
7/25/2019 Oracle Interview Ques & Ans
36/44
R''U&8% It is a group by operation and is used to produce
subtotals at any level of t*e aggregation.
% +*e generated sub +otals ORolled UpP to produce Hrant total.
Synta78% Hroup by rollup @/olumn , /olumn ;A
178% Select Dept no, SUM @S6'A from 1mp group by Rollup @Dept
noA>
$*. W)! )re U"K U" A&&K I!ere,! )' Meu
Union8% Returns t*e combined ro0s from t0o queries, sorting
t*en and removing duplicates.
178% Select ob 4rom 1M& 0*ere Dept 5o N ;#> Union
% Select region ? name from regions Union select region ? name
from regions>
Union 6ll8% Returns t*e combined ro0s from t0o queries, 0it*out
sorting or removing duplicates.
178% Select ob 4rom 1M& 0*ere Dept 5o N E#> Union 6ll
% Select region ? name from regions Union all select region ?name from regions>
Intersect8% Returns only t*e ro0s t*at occur in bot* queries,
result sets, sorting t*en and removing duplicates.
178% Select ob 4rom 1M& 0*ere Dept 5o N E#> Intersect
% Select region ? name from regions Intersect select region ?
name from regions>
Menu8% Returns only t*e ro0s in t*e 2rst result set t*at do not
appear in t*e second result set , sorting t*en and removing
duplicates.
178% Select ob 4rom 1M& 0*ere Dept 5o N E#> Menu
7/25/2019 Oracle Interview Ques & Ans
37/44
% Select region ? name from regions Menu select region ? name
from regions>
(. W)! " D)!) Ty+e Ty+e 8 D)!) Ty+e
% +*e Data +ype associates a 27ed set of properties 0it* t*at
value stored.
% +*e Data type de2nes t*e domain of values t*at eac* column
can contain.
% +*e
7/25/2019 Oracle Interview Ques & Ans
38/44
@;A. 5 /T6R Data %+ype8% Ma7imum lengt* is determined by t*e
5ational c*aracter set de2nition.
% Minimum size is ;###Bytes and size *as to be speci2ed.
% 4irst time de2ned in R6/'1 !i and contains Unicode data only.
@EA.
7/25/2019 Oracle Interview Ques & Ans
39/44
% +*e lengt* of 'ong
7/25/2019 Oracle Interview Ques & Ans
40/44
/'B Data +ype8% It Stores single byte and multi byte
c*aracter data.
5/'B Data +ype8% It Stores Unicode data using t*e 5ational
c*aracter set.. R6 I' D)!) Ty+e:-1ac* ro0 in t*e data base *as an
address.
% +*e ro0s address can be queried using t*e pseudo column R=
ID.
% W6 value coded in base V t*at is t*e pointer to t*e location of a
ro0 in a table.X
(2. W)! " Crre&)!e' u#0uery
Ans:- A correlated subquery (also known as a synchronized subquery) is a
subquery (a query nested inside another query) that uses values from outer
query. The subquery is evaluated once for each row rocessed by the outerquery. !"
A query is called correlated subquery when both the inner
query and the outer query are interdependent. For every row
processed by the inner query, the outer query is processed as
well. The inner query depends on the outer query before it can
be processed.
S1'1/+ p.product?name 4RM product p
=T1R1 p.product?id N @S1'1/+ o.product?id 4RM
7/25/2019 Oracle Interview Ques & Ans
41/44
order?items o
=T1R1 o.product?id N p.product?idA>
(3. W)! " @u"'e&"e ! Ue @.%
7/25/2019 Oracle Interview Ques & Ans
42/44
7/25/2019 Oracle Interview Ques & Ans
43/44
7/25/2019 Oracle Interview Ques & Ans
44/44
Top Related