Вы находитесь на странице: 1из 8

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
SQL
13. Which s#stem table contains information on constraints on all the tables created?
USER!0,NSTRAINTS
1. )(;&</)' )/=L' '.>?
D'L')' @(O. '.>?
Will the outputs of the abo8e t$o commands differ?
-ot$ 1ill re"ult in &eleting all t$e ro1" in t$e ta%le E/.2
1". What is the difference bet$een )(;&</)' and D'L')' commands?
TRUN0ATE i" a DDL #omman& 1$erea" DELETE i" a D/L #omman&2 3en#e
DELETE operation #an %e rolle& %a#4) %ut TRUN0ATE operation #annot %e rolle& %a#42
53ERE #lau"e #an %e u"e& 1it$ DELETE an& not 1it$ TRUN0ATE2
1*. What command is used to create a table b# cop#ing the structure of another table?
Answer :
0REATE TA-LE 22 AS SELE0T #omman&
Explanation :
To #op6 onl6 t$e "tru#ture) t$e 53ERE #lau"e of t$e SELE0T #omman& "$oul&
#ontain a 7ALSE "tatement a" in t$e follo1ing2
0REATE TA-LE NE5TA-LE AS SELE0T 8 7R,/ E9ISTIN:TA-LE
53ERE ;<=>
If t$e 53ERE #on&ition i" true) t$en all t$e ro1" or ro1" "ati"f6ing t$e #on&ition
1ill %e #opie& to t$e ne1 ta%le2
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-LET3ETR,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 ?uer6 #$e#4" 1$et$er a gi@en "tring i" a numeri#al &igit2
11. What does the follo$ing Auer# do?
S'L'<) S/L G &HLB<O..,7E @(O. '.>?
T$i" &i"pla6" t$e total "alar6 of all emplo6ee"2 T$e null @alue" in t$e #ommi""ion
#olumn 1ill %e repla#e& %6 A an& a&&e& to "alar62
27. Which date function is used to find the difference bet$een t$o dates?
/,NT3S!-ET5EEN
21. Wh# does the follo$ing command gi8e a compilation error?
D(O> )/=L' I)/=L'J&/.'?
+aria%le name" "$oul& "tart 1it$ an alp$a%et2 3ere t$e ta%le name "tart" 1it$ an
BB "6m%ol2
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 o1ner to an6 ot$er u"er2
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%le2
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 < ;;AAA) #omm < ;AAA
2". What is the use of D'S< in SQL?
Answer :
DES0 $a" t1o purpo"e"2 It i" u"e& to &e"#ri%e a "#$ema a" 1ell a" to retrie@e
ro1" from ta%le in &e"#en&ing or&er2
Explanation :
T$e ?uer6 SELE0T 8 7R,/ E/. ,RDER -D ENA/E DES0 1ill &i"pla6 t$e
output "orte& on ENA/E in &e"#en&ing or&er2
2*. What is the use of </S</D' <O&S)(/%&)S?
5$en t$i" #lau"e i" u"e& 1it$ t$e DR,. #omman&) a parent ta%le #an %e &roppe&
e@en 1$en a #$il& ta%le e*i"t"2
2+. Which function is used to find the largest integer less than or eAual to a specific
8alue?
7L,,R
2,. What is the output of the follo$ing Auer#?
S'L'<) )(;&<B123."*+,,M2E @(O. D;/L?
;=AA
SQL QUERIES
I. SCHEMAS
)able 1 N STUDIES
.NA/E (+AR03AR)) S.LA0E (+AR03AR)) 0,URSE (+AR03AR)) 00,ST
(NU/-ER)
)able 2 N SOFTWARE
.NA/E (+AR03AR)) TITLE (+AR03AR)) DE+IN (+AR03AR)) S0,ST
(NU/-ER)) D0,ST (NU/-ER)) S,LD (NU/-ER)
)able 3 N PROGRAMMER
.NA/E (+AR03AR)) D,- (DATE)) D,E (DATE)) SE9 (03AR)) .R,7;
(+AR03AR)) .R,7= (+AR03AR)) SAL (NU/-ER)
LEGEND :
.NA/E F .rogrammer Name) S.LA0E F Stu&6 .la#e) 00,ST F 0our"e 0o"t) DE+IN
F De@elope& in) S0,ST F Soft1are 0o"t) D0,ST F De@elopment 0o"t) .R,7; F
.rofi#ien#6 ;
UERIES :
1. @ind out the selling cost a8erage for pac9ages de8eloped in Oracle.
2. Displa# the names, ages and e!perience of all programmers.
3. 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?
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:
;2 SELE0T A+:(S0,ST) 7R,/ S,7T5ARE 53ERE DE+IN < B,RA0LEB>
=2 SELE0T .NA/E)TRUN0(/,NT3S!-ET5EEN(SDSDATE)D,-)C;=)
GA:EG) TRUN0(/,NT3S!-ET5EEN(SDSDATE)D,E)C;=) GE9.ERIEN0EG
7R,/ .R,:RA//ER>
H2 SELE0T .NA/E 7R,/ STUDIES 53ERE 0,URSE < B.:D0AB>
I2 SELE0T /A9(S,LD) 7R,/ S,7T5ARE>
J2 SELE0T .NA/E) D,- 7R,/ .R,:RA//ER 53ERE D,- LIKE B'A.R
'B>
K2 SELE0T /IN(00,ST) 7R,/ STUDIES>
L2 SELE0T 0,UNT(8) 7R,/ STUDIES 53ERE 0,URSE < BD0AB>
M2 SELE0T SU/(S0,ST8S,LD(D0,ST) 7R,/ S,7T5ARE :R,U. -D
DE+IN 3A+IN: DE+IN < B0B>
N2 SELE0T 8 7R,/ S,7T5ARE 53ERE .NA/E < BRAKES3B>
;A2 SELE0T 8 7R,/ STUDIES 53ERE S.LA0E < B.ENTA7,URB>
;;2 SELE0T 8 7R,/ S,7T5ARE 53ERE S0,ST8S,LD(D0,ST > JAAA>
;=2 SELE0T 0EIL(D0,STCS0,ST) 7R,/ S,7T5ARE>
;H2 SELE0T 8 7R,/ S,7T5ARE 53ERE S0,ST8S,LD >< D0,ST>
;I2 SELE0T /A9(S0,ST) 7R,/ S,7T5ARE :R,U. -D DE+IN 3A+IN:
DE+IN < B+-B>
;J2 SELE0T 0,UNT(8) 7R,/ S,7T5ARE 53ERE DE+IN < B,RA0LEB>
;K2 SELE0T 0,UNT(8) 7R,/ STUDIES 53ERE S.LA0E < B.RA:AT3IB>
;L2 SELE0T 0,UNT(8) 7R,/ STUDIES 53ERE 00,ST -ET5EEN ;AAAA
AND ;JAAA>
;M2 SELE0T A+:(00,ST) 7R,/ STUDIES>
;N2 SELE0T 8 7R,/ .R,:RA//ER 53ERE .R,7; < B0B ,R .R,7= < B0B>
=A2 SELE0T 8 7R,/ .R,:RA//ER 53ERE .R,7; IN (B0B)B.AS0ALB) ,R
.R,7= IN (B0B)B.AS0ALB)>
=;2 SELE0T 8 7R,/ .R,:RA//ER 53ERE .R,7; N,T IN (B0B)B0OOB) AND
.R,7= N,T IN (B0B)B0OOB)>
==2 SELE0T TRUN0(/A9(/,NT3S!-ET5EEN(SDSDATE)D,-)C;=)) 7R,/
.R,:RA//ER 53ERE SE9 < B/B>
=H2 SELE0T TRUN0(A+:(/,NT3S!-ET5EEN(SDSDATE)D,-)C;=)) 7R,/
.R,:RA//ER 53ERE SE9 < B7B>
=I2 SELE0T .NA/E) TRUN0(/,NT3S!-ET5EEN(SDSDATE)D,E)C;=)
7R,/ .R,:RA//ER ,RDER -D .NA/E DES0>
=J2 SELE0T .NA/E 7R,/ .R,:RA//ER 53ERE T,!03AR(D,-)B/,NB)
< T,!03AR(SDSDATE)B/,NB)>
=K2 SELE0T 0,UNT(8) 7R,/ .R,:RA//ER 53ERE SE9 < B7B>
=L2 SELE0T DISTIN0T(.R,7;) 7R,/ .R,:RA//ER 53ERE SE9 < B/B>
=M2 SELE0T A+:(SAL) 7R,/ .R,:RA//ER>
=N2 SELE0T 0,UNT(8) 7R,/ .R,:RA//ER 53ERE SAL -ET5EEN JAAA
AND LJAA>
HA2 SELE0T 8 7R,/ .R,:RA//ER 53ERE .R,7; N,T IN (B0B)B0O
OB)B.AS0ALB) AND .R,7= N,T IN (B0B)B0OOB)B.AS0ALB)>
H;2 SELE0T .NA/E)TITLE)S0,ST 7R,/ S,7T5ARE 53ERE S0,ST IN
(SELE0T /A9(S0,ST) 7R,/ S,7T5ARE :R,U. -D .NA/E)>
H=2SELE0T B/r2B PP .NA/E PP B ( $a" B PP
TRUN0(/,NT3S!-ET5EEN(SDSDATE)D,E)C;=) PP B 6ear" of e*perien#eB
Q.rogrammerR 7R,/ .R,:RA//ER 53ERE SE9 < B/B UNI,N SELE0T
B/"2B PP .NA/E PP B ( $a" B PP TRUN0 (/,NT3S!-ET5EEN
(SDSDATE)D,E)C;=) PP B 6ear" of e*perien#eB Q.rogrammerR 7R,/
.R,:RA//ER 53ERE SE9 < B7B>
II . SCHEMA :
)able 1 N DEPT
DE.TN, (N,T NULL ) NU/-ER(=))) DNA/E (+AR03AR=(;I)))
L,0 (+AR03AR=(;H)
)able 2 N EMP
E/.N, (N,T NULL ) NU/-ER(I))) ENA/E (+AR03AR=(;A)))
E,- (+AR03AR=(N))) /:R (NU/-ER(I))) 3IREDATE (DATE))
SAL (NU/-ER(L)=))) 0,// (NU/-ER(L)=))) DE.TN, (NU/-ER(=))
/:R i" t$e empno of t$e emplo6ee 1$om t$e emplo6ee report" to2 DE.TN, i" a foreign
4e62
UERIES
1. List all the emplo#ees $ho ha8e at least one person reporting to them.
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:
;2 SELE0T DISTIN0T(A2ENA/E) 7R,/ E/. A) E/. - 53ERE A2E/.N, <
-2/:R> or SELE0T ENA/E 7R,/ E/. 53ERE E/.N, IN (SELE0T /:R
7R,/ E/.)>
=2 SELE0T 8 7R,/ E/. 53ERE DE.TN, IN (SELE0T DE.TN, 7R,/ E/.
:R,U. -D DE.TN, 3A+IN: 0,UNT(E/.N,)>;A AND DE.TN,<;A)>
H2 SELE0T A2ENA/E GE/.L,DEEG) -2ENA/E GRE.,RTS T,G 7R,/ E/. A)
E/. - 53ERE A2/:R<-2E/.N,>
I2 SELE0T 8 7R,/ E/. 53ERE E/.N, IN ( SELE0T E/.N, 7R,/ E/.
/INUS SELE0T /:R 7R,/ E/.)>
J2 SELE0T 8 7R,/ E/. 53ERE SAL > ( SELE0T /IN(SAL) 7R,/ E/.
:R,U. -D DE.TN, 3A+IN: DE.TN,<=A)>
K2 SELE0T 8 7R,/ E/. 53ERE SAL > ( SELE0T /A9(SAL) 7R,/ E/.
:R,U. -D E,- 3A+IN: E,- < B/ANA:ERB )>
L2 SELE0T E,-) /A9(SAL) 7R,/ E/. :R,U. -D E,->
M2 SELE0T 8 7R,/ E/. 53ERE (DE.TN,) 3IREDATE) IN (SELE0T DE.TN,)
/A9(3IREDATE) 7R,/ E/. :R,U. -D DE.TN,)>
N2 SELE0T T,!03AR(3IREDATE)BDDDDB) GDEARG) 0,UNT(E/.N,) GN,2 ,7
E/.L,DEESG 7R,/ E/. :R,U. -D T,!03AR(3IREDATE)BDDDDB) 3A+IN:
0,UNT(E/.N,) < (SELE0T /A9(0,UNT(E/.N,)) 7R,/ E/. :R,U. -D
T,!03AR(3IREDATE)BDDDDB))>
;A2 SELE0T DE.TN,) L.AD(SU/(;=8(SALON+L(0,//)A))));J)
G0,/.ENSATI,NG 7R,/ E/. :R,U. -D DE.TN, 3A+IN:
SU/( ;=8(SALON+L(0,//)A))) < (SELE0T
/A9(SU/(;=8(SALON+L(0,//)A)))) 7R,/ E/. :R,U. -D DE.TN,)>
;;2 SELE0T ENA/E) 3IREDATE) L.AD(B8B)M) GRE0ENTLD 3IREDG 7R,/ E/.
53ERE 3IREDATE < (SELE0T /A9(3IREDATE) 7R,/ E/.) UNI,N SELE0T
ENA/E NA/E) 3IREDATE) L.AD(B B);J) GRE0ENTLD 3IREDG 7R,/ E/.
53ERE 3IREDATE S< (SELE0T /A9(3IREDATE) 7R,/ E/.)>
;=2 SELE0T ENA/E)SAL 7R,/ E/. E 53ERE SAL > (SELE0T A+:(SAL)
7R,/ E/. 7 53ERE E2DE.TN, < 72DE.TN,)>
;H2 SELE0T ENA/E) SAL 7R,/ E/. A 53ERE N < (SELE0T 0,UNT
(DISTIN0T(SAL)) 7R,/ E/. - 53ERE A2SAL<<-2SAL)>
;I2 SELE0T 8 7R,/ E/. A 53ERE A2E/.N, IN (SELE0T E/.N, 7R,/ E/.
:R,U. -D E/.N, 3A+IN: 0,UNT(E/.N,)>;) AND A2R,5IDS</IN
(R,5ID))>
;J2 SELE0T ENA/E
GE/.L,DEEG)T,!03AR(TRUN0(/,NT3S!-ET5EEN(SDSDATE)3IREDATE)C;
=))PPB DEARS BPP T,!03AR(TRUN0(/,D(/,NT3S!-ET5EEN (SDSDATE)
3IREDATE));=)))PPB /,NT3S B GLEN:T3 ,7 SER+I0EG 7R,/ E/.>

Вам также может понравиться