You are on page 1of 9

First Job. Dream Job. Freshersworld.

com

SQL
1. Which is the subset of SQL commands used to manipulate Oracle Database structures, including tables? Data Definition Language (DDL) 2. What operator performs pattern matching? LIKE operator 3. What operator tests column for the absence of data? IS NULL operator . Which command e!ecutes the contents of a specified file? START <filename> or @<filename> ". What is the parameter substitution s#mbol used $ith %&S'() %&)O command? *. Which command displa#s the SQL command in the SQL buffer, and then e!ecutes it? RUN +. What are the $ildcards used for pattern matching? ! for "ingle #$ara#ter "u%"titution an& ' for multi(#$ara#ter "u%"titution ,. State true or false. '-%S)S, SO.', /&0 are operators in SQL. True 1. State true or false. 23, 45, 63 all denote the same operation. True 17. What are the pri8ileges that can be granted on a table b# a user to others? In"ert) up&ate) &elete) "ele#t) referen#e") in&e*) e*e#ute) alter) all 11. What command is used to get bac9 the pri8ileges offered b# the :(/&) command? RE+,KE 12. Which s#stem tables contain information on pri8ileges granted and pri8ileges obtained? USER!TA-!.RI+S!/ADE) USER!TA-!.RI+S!RE0D 13. Which s#stem table contains information on constraints on all the tables created? USER!0,NSTRAINTS

Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com 1 . )(;&</)' )/=L' '.>? D'L')' @(O. '.>? Will the outputs of the abo8e t$o commands differ? -ot$ 2ill re"ult in &eleting all t$e ro2" in t$e ta%le E/.3 1". What is the difference bet$een )(;&</)' and D'L')' commands? TRUN0ATE i" a DDL #omman& 2$erea" DELETE i" a D/L #omman&3 4en#e DELETE operation #an %e rolle& %a#5) %ut TRUN0ATE operation #annot %e rolle& %a#53 64ERE #lau"e #an %e u"e& 2it$ DELETE an& not 2it$ TRUN0ATE3 1*. What command is used to create a table b# cop#ing the structure of another table? Answer : 0REATE TA-LE 33 AS SELE0T #omman& Explanation : To #op7 onl7 t$e "tru#ture) t$e 64ERE #lau"e of t$e SELE0T #omman& "$oul& #ontain a 8ALSE "tatement a" in t$e follo2ing3 0REATE TA-LE NE6TA-LE AS SELE0T 9 8R,/ E:ISTIN;TA-LE 64ERE 1<=> If t$e 64ERE #on&ition i" true) t$en all t$e ro2" or ro2" "ati"f7ing t$e #on&ition 2ill %e #opie& to t$e ne2 ta%le3 1+. What $ill be the output of the follo$ing Auer#?

S'L'<) ('>L/<'B)(/&SL/)'BL)(%.B()(%.BC22 /)D'& 22C,C2CE, C2CE, C/&C, CFFCE,CFC,C)(O;=L'CE @(O. D;/L?


TR,U-LET4ETR,U-LE 1,. What $ill be the output of the follo$ing Auer#? S'L'<) D'<OD'B)(/&SL/)'BC/C,C123 "*+,17C,C1111111111CE, C1C,C0'SC, C&OC E? Answer : N, Explanation : T$e ?uer7 #$e#5" 2$et$er a gi@en "tring i" a numeri#al &igit3 11. What does the follo$ing Auer# do? S'L'<) S/L G &HLB<O..,7E @(O. '.>? T$i" &i"pla7" t$e total "alar7 of all emplo7ee"3 T$e null @alue" in t$e #ommi""ion #olumn 2ill %e repla#e& %7 A an& a&&e& to "alar73 27. Which date function is used to find the difference bet$een t$o dates? /,NT4S!-ET6EEN 21. Wh# does the follo$ing command gi8e a compilation error? D(O> )/=L' I)/=L'J&/.'?

Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com +aria%le name" "$oul& "tart 2it$ an alp$a%et3 4ere t$e ta%le name "tart" 2it$ an B B "7m%ol3 22. What is the ad8antage of specif#ing W%)D :(/&) O>)%O& in the :(/&) command? T$e pri@ilege re#ei@er #an furt$er grant t$e pri@ilege" $eC"$e $a" o%taine& from t$e o2ner to an7 ot$er u"er3 23. What is the use of the D(O> option in the /L)'( )/=L' command? It i" u"e& to &rop #on"traint" "pe#ifie& on t$e ta%le3 2 . What is the 8alue of KcommL and KsalL after e!ecuting the follo$ing Auer# if the initial 8alue of KsalL is 17777? ;>D/)' '.> S') S/L 3 S/L G 1777, <O.. 3 S/LF7.1? "al < 11AAA) #omm < 1AAA 2". What is the use of D'S< in SQL? Answer : DES0 $a" t2o purpo"e"3 It i" u"e& to &e"#ri%e a "#$ema a" 2ell a" to retrie@e ro2" from ta%le in &e"#en&ing or&er3 Explanation : T$e ?uer7 SELE0T 9 8R,/ E/. ,RDER -D ENA/E DES0 2ill &i"pla7 t$e output "orte& on ENA/E in &e"#en&ing or&er3 2*. What is the use of </S</D' <O&S)(/%&)S? 6$en t$i" #lau"e i" u"e& 2it$ t$e DR,. #omman&) a parent ta%le #an %e &roppe& e@en 2$en a #$il& ta%le e*i"t"3 2+. Which function is used to find the largest integer less than or eAual to a specific 8alue? 8L,,R 2,. What is the output of the follo$ing Auer#? S'L'<) )(;&<B123 ."*+,,M2E @(O. D;/L? 1=AA

SQL QUERIES I. SCHEMAS )able 1 N STUDIES


Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com

.NA/E (+AR04AR)) S.LA0E (+AR04AR)) 0,URSE (+AR04AR)) 00,ST (NU/-ER) )able 2 N SOFTWARE .NA/E (+AR04AR)) TITLE (+AR04AR)) DE+IN (+AR04AR)) S0,ST (NU/-ER)) D0,ST (NU/-ER)) S,LD (NU/-ER) )able 3 N PROGRAMMER .NA/E (+AR04AR)) D,- (DATE)) D,F (DATE)) SE: (04AR)) .R,81 (+AR04AR)) .R,8= (+AR04AR)) SAL (NU/-ER) LEGEND : .NA/E G .rogrammer Name) S.LA0E G Stu&7 .la#e) 00,ST G 0our"e 0o"t) DE+IN G De@elope& in) S0,ST G Soft2are 0o"t) D0,ST G De@elopment 0o"t) .R,81 G .rofi#ien#7 1 UERIES : 1. 2. 3. . ". *. +. ,. @ind out the selling cost a8erage for pac9ages de8eloped in Oracle. Displa# the names, ages and e!perience of all programmers. Displa# the names of those $ho ha8e done the >:D</ course. What is the highest number of copies sold b# a pac9age? Displa# the names and date of birth of all programmers born in /pril. Displa# the lo$est course fee. Do$ man# programmers ha8e done the D</ course. Do$ much re8enue has been earned through the sale of pac9ages de8eloped in <. 1. Displa# the details of soft$are de8eloped b# (a9esh. 17. Do$ man# programmers studied at >entafour. 11. Displa# the details of pac9ages $hose sales crossed the "777 mar9. 12. @ind out the number of copies $hich should be sold in order to reco8er the de8elopment cost of each pac9age. 13. Displa# the details of pac9ages for $hich the de8elopment cost has been reco8ered. 1 . What is the price of costliest soft$are de8eloped in H=? 1". Do$ man# pac9ages $ere de8eloped in Oracle ? 1*. Do$ man# programmers studied at >(/:/)D%? 1+. Do$ man# programmers paid 17777 to 1"777 for the course? 1,. What is the a8erage course fee? 11. Displa# the details of programmers 9no$ing <. 27. Do$ man# programmers 9no$ either < or >ascal? 21. Do$ man# programmers donLt 9no$ < and <GG?
Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com 22. Do$ old is the oldest male programmer? 23. What is the a8erage age of female programmers? 2 . <alculate the e!perience in #ears for each programmer and displa# along $ith their names in descending order. 2". Who are the programmers $ho celebrate their birthda#s during the current month? 2*. Do$ man# female programmers are there? 2+. What are the languages 9no$n b# the male programmers? 2,. What is the a8erage salar#? 21. Do$ man# people dra$ "777 to +"77? 37. Displa# the details of those $ho donLt 9no$ <, <GG or >ascal. 31. Displa# the costliest pac9age de8eloped b# each programmer. 32. >roduce the follo$ing output for all the male programmers >rogrammer .r. /r8ind O has 1" #ears of e!perience KEYS: 13 SELE0T A+;(S0,ST) 8R,/ S,8T6ARE 64ERE DE+IN < B,RA0LEB> =3 SELE0T .NA/E)TRUN0(/,NT4S!-ET6EEN(SDSDATE)D,-)C1=) IA;EI) TRUN0(/,NT4S!-ET6EEN(SDSDATE)D,F)C1=) IE:.ERIEN0EI 8R,/ .R,;RA//ER> E3 SELE0T .NA/E 8R,/ STUDIES 64ERE 0,URSE < B.;D0AB> H3 SELE0T /A:(S,LD) 8R,/ S,8T6ARE> J3 SELE0T .NA/E) D,- 8R,/ .R,;RA//ER 64ERE D,- LIKE B'A.R'B> K3 SELE0T /IN(00,ST) 8R,/ STUDIES> L3 SELE0T 0,UNT(9) 8R,/ STUDIES 64ERE 0,URSE < BD0AB> M3 SELE0T SU/(S0,ST9S,LD(D0,ST) 8R,/ S,8T6ARE ;R,U. -D DE+IN 4A+IN; DE+IN < B0B> N3 SELE0T 9 8R,/ S,8T6ARE 64ERE .NA/E < BRAKES4B> 1A3 SELE0T 9 8R,/ STUDIES 64ERE S.LA0E < B.ENTA8,URB> 113 SELE0T 9 8R,/ S,8T6ARE 64ERE S0,ST9S,LD(D0,ST > JAAA> 1=3 SELE0T 0EIL(D0,STCS0,ST) 8R,/ S,8T6ARE> 1E3 SELE0T 9 8R,/ S,8T6ARE 64ERE S0,ST9S,LD >< D0,ST> 1H3 SELE0T /A:(S0,ST) 8R,/ S,8T6ARE ;R,U. -D DE+IN 4A+IN; DE+IN < B+-B> 1J3 SELE0T 0,UNT(9) 8R,/ S,8T6ARE 64ERE DE+IN < B,RA0LEB> 1K3 SELE0T 0,UNT(9) 8R,/ STUDIES 64ERE S.LA0E < B.RA;AT4IB> 1L3 SELE0T 0,UNT(9) 8R,/ STUDIES 64ERE 00,ST -ET6EEN 1AAAA AND 1JAAA> 1M3 SELE0T A+;(00,ST) 8R,/ STUDIES> 1N3 SELE0T 9 8R,/ .R,;RA//ER 64ERE .R,81 < B0B ,R .R,8= < B0B> =A3 SELE0T 9 8R,/ .R,;RA//ER 64ERE .R,81 IN (B0B)B.AS0ALB) ,R .R,8= IN (B0B)B.AS0ALB)>
Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com =13 SELE0T 9 8R,/ .R,;RA//ER 64ERE .R,81 N,T IN (B0B)B0OOB) AND .R,8= N,T IN (B0B)B0OOB)> ==3 SELE0T TRUN0(/A:(/,NT4S!-ET6EEN(SDSDATE)D,-)C1=)) 8R,/ .R,;RA//ER 64ERE SE: < B/B> =E3 SELE0T TRUN0(A+;(/,NT4S!-ET6EEN(SDSDATE)D,-)C1=)) 8R,/ .R,;RA//ER 64ERE SE: < B8B> =H3 SELE0T .NA/E) TRUN0(/,NT4S!-ET6EEN(SDSDATE)D,F)C1=) 8R,/ .R,;RA//ER ,RDER -D .NA/E DES0> =J3 SELE0T .NA/E 8R,/ .R,;RA//ER 64ERE T,!04AR(D,-)B/,NB) < T,!04AR(SDSDATE)B/,NB)> =K3 SELE0T 0,UNT(9) 8R,/ .R,;RA//ER 64ERE SE: < B8B> =L3 SELE0T DISTIN0T(.R,81) 8R,/ .R,;RA//ER 64ERE SE: < B/B> =M3 SELE0T A+;(SAL) 8R,/ .R,;RA//ER> =N3 SELE0T 0,UNT(9) 8R,/ .R,;RA//ER 64ERE SAL -ET6EEN JAAA AND LJAA> EA3 SELE0T 9 8R,/ .R,;RA//ER 64ERE .R,81 N,T IN (B0B)B0O OB)B.AS0ALB) AND .R,8= N,T IN (B0B)B0OOB)B.AS0ALB)> E13 SELE0T .NA/E)TITLE)S0,ST 8R,/ S,8T6ARE 64ERE S0,ST IN (SELE0T /A:(S0,ST) 8R,/ S,8T6ARE ;R,U. -D .NA/E)> E=3SELE0T B/r3B PP .NA/E PP B ( $a" B PP TRUN0(/,NT4S!-ET6EEN(SDSDATE)D,F)C1=) PP B 7ear" of e*perien#eB Q.rogrammerR 8R,/ .R,;RA//ER 64ERE SE: < B/B UNI,N SELE0T B/"3B PP .NA/E PP B ( $a" B PP TRUN0 (/,NT4S!-ET6EEN (SDSDATE)D,F)C1=) PP B 7ear" of e*perien#eB Q.rogrammerR 8R,/ .R,;RA//ER 64ERE SE: < B8B>

II . SCHEMA :
)able 1 N DEPT DE.TN, (N,T NULL ) NU/-ER(=))) DNA/E (+AR04AR=(1H))) L,0 (+AR04AR=(1E) )able 2 N EMP E/.N, (N,T NULL ) NU/-ER(H))) ENA/E (+AR04AR=(1A))) F,- (+AR04AR=(N))) /;R (NU/-ER(H))) 4IREDATE (DATE)) SAL (NU/-ER(L)=))) 0,// (NU/-ER(L)=))) DE.TN, (NU/-ER(=)) /;R i" t$e empno of t$e emplo7ee 2$om t$e emplo7ee report" to3 DE.TN, i" a foreign 5e73 UERIES 1. List all the emplo#ees $ho ha8e at least one person reporting to them.
Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com 2. List the emplo#ee details if and onl# if more than 17 emplo#ees are present in department no 17. 3. List the name of the emplo#ees $ith their immediate higher authorit#. . List all the emplo#ees $ho do not manage an# one. ". List the emplo#ee details $hose salar# is greater than the lo$est salar# of an emplo#ee belonging to deptno 27. *. List the details of the emplo#ee earning more than the highest paid manager. +. List the highest salar# paid for each Pob. ,. @ind the most recentl# hired emplo#ee in each department. 1. %n $hich #ear did most people Poin the compan#? Displa# the #ear and the number of emplo#ees. 17. Which department has the highest annual remuneration bill? 11. Write a Auer# to displa# a KFL against the ro$ of the most recentl# hired emplo#ee. 12. Write a correlated subMAuer# to list out the emplo#ees $ho earn more than the a8erage salar# of their department. 13. @ind the nth ma!imum salar#. 1 . Select the duplicate records B(ecords, $hich are inserted, that alread# e!istE in the '.> table. 1". Write a Auer# to list the length of ser8ice of the emplo#ees Bof the form n #ears and m monthsE. KEYS: 13 SELE0T DISTIN0T(A3ENA/E) 8R,/ E/. A) E/. - 64ERE A3E/.N, < -3/;R> or SELE0T ENA/E 8R,/ E/. 64ERE E/.N, IN (SELE0T /;R 8R,/ E/.)> =3 SELE0T 9 8R,/ E/. 64ERE DE.TN, IN (SELE0T DE.TN, 8R,/ E/. ;R,U. -D DE.TN, 4A+IN; 0,UNT(E/.N,)>1A AND DE.TN,<1A)> E3 SELE0T A3ENA/E IE/.L,DEEI) -3ENA/E IRE.,RTS T,I 8R,/ E/. A) E/. - 64ERE A3/;R<-3E/.N,> H3 SELE0T 9 8R,/ E/. 64ERE E/.N, IN ( SELE0T E/.N, 8R,/ E/. /INUS SELE0T /;R 8R,/ E/.)> J3 SELE0T 9 8R,/ E/. 64ERE SAL > ( SELE0T /IN(SAL) 8R,/ E/. ;R,U. -D DE.TN, 4A+IN; DE.TN,<=A)> K3 SELE0T 9 8R,/ E/. 64ERE SAL > ( SELE0T /A:(SAL) 8R,/ E/. ;R,U. -D F,- 4A+IN; F,- < B/ANA;ERB )> L3 SELE0T F,-) /A:(SAL) 8R,/ E/. ;R,U. -D F,-> M3 SELE0T 9 8R,/ E/. 64ERE (DE.TN,) 4IREDATE) IN (SELE0T DE.TN,) /A:(4IREDATE) 8R,/ E/. ;R,U. -D DE.TN,)> N3 SELE0T T,!04AR(4IREDATE)BDDDDB) IDEARI) 0,UNT(E/.N,) IN,3 ,8 E/.L,DEESI 8R,/ E/. ;R,U. -D T,!04AR(4IREDATE)BDDDDB) 4A+IN; 0,UNT(E/.N,) < (SELE0T /A:(0,UNT(E/.N,)) 8R,/ E/. ;R,U. -D T,!04AR(4IREDATE)BDDDDB))> 1A3 SELE0T DE.TN,) L.AD(SU/(1=9(SALON+L(0,//)A))))1J) I0,/.ENSATI,NI 8R,/ E/. ;R,U. -D DE.TN, 4A+IN;
Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com SU/( 1=9(SALON+L(0,//)A))) < (SELE0T /A:(SU/(1=9(SALON+L(0,//)A)))) 8R,/ E/. ;R,U. -D DE.TN,)> 113 SELE0T ENA/E) 4IREDATE) L.AD(B9B)M) IRE0ENTLD 4IREDI 8R,/ E/. 64ERE 4IREDATE < (SELE0T /A:(4IREDATE) 8R,/ E/.) UNI,N SELE0T ENA/E NA/E) 4IREDATE) L.AD(B B)1J) IRE0ENTLD 4IREDI 8R,/ E/. 64ERE 4IREDATE S< (SELE0T /A:(4IREDATE) 8R,/ E/.)> 1=3 SELE0T ENA/E)SAL 8R,/ E/. E 64ERE SAL > (SELE0T A+;(SAL) 8R,/ E/. 8 64ERE E3DE.TN, < 83DE.TN,)> 1E3 SELE0T ENA/E) SAL 8R,/ E/. A 64ERE N < (SELE0T 0,UNT (DISTIN0T(SAL)) 8R,/ E/. - 64ERE A3SAL<<-3SAL)> 1H3 SELE0T 9 8R,/ E/. A 64ERE A3E/.N, IN (SELE0T E/.N, 8R,/ E/. ;R,U. -D E/.N, 4A+IN; 0,UNT(E/.N,)>1) AND A3R,6IDS</IN (R,6ID))> 1J3 SELE0T ENA/E IE/.L,DEEI)T,!04AR(TRUN0(/,NT4S!-ET6EEN(SDSDATE)4IREDAT E)C1=))PPB DEARS BPP T,!04AR(TRUN0(/,D(/,NT4S!-ET6EEN (SDSDATE) 4IREDATE))1=)))PPB /,NT4S B ILEN;T4 ,8 SER+I0EI 8R,/ E/.>

Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com

Freshersworld.com Resource Center

You might also like