You are on page 1of 16

Practice Q & A

(Chapter 1 - 7)

Chapter 1
1.
A RDBMS groups data in a logical manner into tables and manages the access to the tables. Yes No A table always has columns and rows. No Yes A schema diagram is used to understand a database!s design. No Yes A column in a table de#ined as N$% N&'' is a primary or #oreign (ey. No Yes Re#erential integrity is en#orced by the relationship between the primary (ey and #oreign (ey. Yes No

2.

.

".

).

Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 1 o# 16 7ersion8 )9292334

hapters 1-. No A column in a table de!ined as N"# N$%% is a primary or !oreign &ey. Any column in a table is a candidate #or the S:':. %he (eywords D. . 5. 2. . Yes Re!erential integrity is en!orced by the relationship between primary &ey and !oreign &ey. 4. Note: A table can exist without rows but must have at least one column. Additional *+A #or . ". 3.s>l e?tension can be e?ecuted with the @ command. Yes A schema diagram is used to understand a database s design.B: command is a S*' command. 1.*&: cannot be used interchangeably in a S:':. No Yes <iles sa=ed with a .% list.% and &N./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 2 o# 16 7ersion8 )9292334 .hapter 2 1.Answers for "Chapter 1" Yes A RDBMS groups data in a logical manner into tables and manages the access to the tables. No Yes %he D:S.N.R.S%.% list. No A table always has columns and rows. Yes No 2.

Yes No You can store at most "C333 characters in a 7AR. 3.s.hapters 1-.l extension can be executed with the command. Yes +iles saved with a .. No #hese &eywords D)S#)N(# and $N)*$' cannot be be used interchangeably. 4. Yes No %he S*'A0lus bu##er shows the last S*' command you typed. B. Additional *+A #or . Yes Any column in a table is a candidate !or the S'%'(# list. . No Yes An $racle database re>uires that a user ha=e a user id and password to communicate with it. 5. Yes No You must always type column and table names in lowercase letters #or the S*' statement to e?ecute correctly. No #he push pin icon in S*% Developer allows you to toggle between the wor&sheets. 2. No #he D'S(R)B' command is a S*% command./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age o# 16 7ersion8 )9292334 .1AR2 column. 4.Yes No ). Yes No 6. %he push pin icon in S*' De=eloper allows you to toggle between the wor(sheets. Answers for "Chapter 2" 1.

Note. No Yes %he optional (eyword AS can precede the alias name. Yes No %he AND and $R logical operators can only be combined with the use o# parentheses. No Yes You can test #or null =alues by using an empty string such as the #ollowing8 SELECT * FROM course WHERE prerequisite = ''. ".t is not possible to limit the number o# rows returned #rom a S:':.hapter 1. Yes No 2. Additional *+A #or .9 . %he B:%D::N operator tests #or a range o# =alues. )./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age " o# 16 7ersion8 )9292334 .uires that a user have a user id and password to communicate with it. . Note: #he S*% language s &eywords are not case8sensitive. 7. Yes #he S*%. Yes 0ou can store at most 12333 characters in a 4AR(5AR6 column./lus bu!!er shows the last S*% command you typed. #his answer is ("RR'(#2 unless you use an "racle version 7 or below where the limit was 62333 characters. No 0ou must always type column and table names in lowercase letters !or the S*% statement to execute correctly.6.hapters 1-. . Yes An "racle database re. 9. #he convention used in this boo& is listed in Appendix B2 9S*% +ormatting :uidelines.% statement. +or clarity and readability you !ollow a naming convention. 8.

uery. No 0ou can test !or null values by using an empty such as the !ollowing: SELECT * FROM course WHERE prerequisite = '' 4. Additional *+A #or . Answers for "Chapter 3" 1. Yes No %he underscore wildcard character can match multiple characters. 2. Note: #he .5'R' clause allows you to restrict the number o! rows returned by the . Yes No . %he $RD:R BY clause must #ollow the D1:R: clause. 4. 3. Yes #he "RD'R B0 clause must !ollow the . 6. Yes #he optional &eyword AS can precede the alias name.''N "/'RA#"R tests !or a range o! values. 5. No )t is not possible to limit the number o! rows returned !rom a S'%'(# statement.Yes No 6.hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age ) o# 16 7ersion8 )9292334 . Yes #he B'#. No #he AND and "R logical operators can only be combined with the use o! parentheses.. No Yes %he #ollowing notation starts a multi-line comment. B. 9A Yes No A pseudocolumn such as R$DN&M is not actually stored in the database.5'R' clause.

8.hapter " 1. . No Yes %he D&A' table contains data trans#ormed by character #unctions. ). Additional *+A #or . .NS%R #unction return a N&MB:R. ./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 6 o# 16 7ersion8 )9292334 2. Yes No &nli(e many other character #unctionsC the ':NE%1 and .haracter #unctions trans#orm data in tables in order to retrie=e it more easily. 9.N$M is not actually stored in the database. Yes No Arithmetic operators and number #unctions can be combined. No #he = underscore wildcard character can match multiple characters. Yes A pseudocolumn such as R". Yes #he !ollowing notation starts a multi8line comment. No Yes 'i(e character #unctionsC number #unctions operate on single =alues. Yes No %he '0AD #unction le#t trims a string. <. . Yes No You can retrie=e speci#ic character data in a database regardless o# what case it was entered in..7. ". 6.hapters 1-. .

: #unction. Yes No 4. 5.hapters 1-. Yes 0ou can retrieve speci!ic character data in a database regardless o! what case it was entered in. #he !ollowing S*% . Arithmetic operators and number !unctions can be combined. No Yes %he simple .EN2-")5 <R$M dual Yes No You can substitute the N7' #unction with the .$A':S.No Yes B. No #he %/AD !unction le!t trims a string. 13 . No (haracter !unctions trans!orm data in tables in order to retrieve it more easily. 8./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age . Yes %i&e character !unctions2 number !unctions operate on single values. Yes $nli&e many other character !unctions2 the %'N:#5 and )NS#R !unction return a N$MB'R. 7. 0ou learn about modi!ying the data in tables in (hapter >>2 9)nsert2 $pdate2 and Delete.% S. %he #ollowing S*' >uery returns -18 S:':. o# 16 7ersion8 )9292334 . Answers for "Chapter 4" 1.uery returns 8>: S'%'(# S):N?81@A +R"M dual Yes Additional *+A #or . Yes No #he D$A% table contains data trans!ormed by character !unctions. 3. Note: All !unctions2 including character !unctions2 trans!orm the output o! data2 not actual data in tables.9 2.AS: e?pression tests #or e>uality only. 4. 6.

Dhich #ormat mas( is re>uired to display this outputF !Sunday 291B92313!F Additional *+A #or . Dhich o# the #ollowing S*' statements results in this error8 $RA-31. Yes 0ou can substitute the N4% !unction with the ("A%'S(' !unction. %he #ollowing S*' >uery implicitly per#orms a data type con=ersion. SELECT student_id. Yes #he simple (AS' expression tests !or e.hapters 1-. 10./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age B o# 16 7ersion8 )9292334 .uality only.9.+++')) dual TO_$%M&ER'TO_CH(R'+++.+++')) dual ". Dhat is the result o# the #ollowing S*' >ueryF SELECT TO_$%M&ER''(&C') FROM dual $racle :rror message AB.C 2313! Mon-dd yyyy Mon ddC yyyy dd-mon-yyyy M$N ddC YY ).228 in=alid number F SELECT FROM SELECT FROM SELECT FROM SELECT FROM TO_CH(R'TO_$%M&ER'*+++.+++)) dual TO_CH(R'TO_$%M&ER''*+++. Dhich #ormat mas( is re>uired to display this outputF !Mar 1. last_na e FROM student WHERE student_id = '!"#' No Yes 2.+++)) dual TO_CH(R'TO_$%M&ER''-*+++. . 12 .hapter ) 1.

M: G$N: data type..<mDay mm9dd9yyyy DAY MM9DD9YYYY Day mm9dd9yyyy Day#m MM9DD9YYYY 6.<< AM %G18%GM!. %he #ollowing shows one o# the de#ault #ormats #or the %.(TE''/!1/!1!+//'. TO_. !DD-M$N-RR 11.'MM1.uery implicitly per!orms a data type conversion.N%:R7A' #unction con=erts a te?t literal to an . No Yes 13.'..SS.%1 %. Dould you change the #ollowing S*' statement in any wayF SELECT start_date_ti e FROM section WHERE TO_CH(R'start_date_ti e.(TE''#!*. '...$ND data type. Does the #ollowing S*' statement return any rowsF SELECT * FROM section WHERE start_date_ti e &ETWEE$ TO_.N%:R7A' DAY %$ S:. odi4ied_date FROM section WHERE odi4ied_date = '""*M(R*++' No Yes 4. Dill the #ollowing S*' statement return an errorF SELECT course_no. Yes No .*MO$*0000') 2 '/!*3($*"/!/' No Yes B.M:S%AM0 D.n=alid >uery.EC*""//'.*MO$ 0000') ($.. Yes #he !ollowing S*% .M. Yes No %he %$HDS. last_na e Additional *+A #or ./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 4 o# 16 7ersion8 )9292334 . Answers for "Chapter 5" 1.10000') . SELECT student_id.hapters 1-.

'MM1. Yes ..hapters 1-.(TE''/!1/!1!+//'.*MO$*0000') 2 '/!* 3($*"/!/' Do not use the #"B(5AR !unction on the S#AR#BDA#'B#)M' column2 because the . 3.EC*""//'. m!ay mm"dd"yyyy 6..FROM student WHERE student_id = '!"#' #he S#$D'N#B)D column is o! the N$MB'R data type.+++')) FROM dual A text literal such as E8FFF.hich o! the !ollowing S*% statements results in this error: "RA8 3>766: invalid number SELECT TO_CH(R'TO_$%M&ER''-*+++.'.uery returns the incorrect result.ill the !ollowing S*% statement return an errorD Additional *+A #or . No Does the !ollowing S*% statement return any rowsD SELECT * FROM section WHERE start_date_ti e &ETWEE$ TO_... Oracle error message .uires the lowest end o! the range !irst2 then the highest../ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 13 o# 16 7ersion8 )9292334 .*MO$*0000') 7.10000') #he B'#. TO_.*MO$ 0000') ($.''N operator re. .(TE''/!1/!1!+//'.hat is the result o! the !ollowing S*% . Mon dd.hich !ormat mas& is re.uired be!ore the Day !ormat mas&.EC*""//'.(TE''#!*. 8. Note the case o! the !m speci!ier is irrelevant. #he .ould you change the !ollowing S*% statement in any wayD SELECT start_date_ti e FROM section WHERE TO_CH(R'start_date_ti e.hich !ollowing !ormat mas& is re.10000') ($. yyyy .'MM1. No . TO_. 4. 5. '. )t is always pre!erable to explicitly per!orm the conversion. #he two data types do not agree2 there!ore2 "racle per!orms an implicit conversion. $se the S$BS#R !unction to remove the E symbol2 and then convert to a number. )nstead2 write it as !ollows: SELECT * FROM section WHERE start_date_ti e &ETWEE$ TO_. 2.'.uired to display this outputD Mar >72 63>3 .5'R' clause speci!ies the text literal >6C which is a string2 also called a text constant or text literal.ueryD SELECT TO_$%M&ER''(&C') FROM dual A text literal such as AB( cannot be converted into a number.uired to display this outputD Sunday 6<>G<63>3 #he !illmode ?!mA speci!ier is re.(TE''#!*.FF cannot be converted into a number.

No Yes %he #ollowing >uery is in=alid. No Yes Aggregate #unctions usually ignore N&'' =alues. odi4ied_date FROM section WHERE odi4ied_date = '""*M(R*++' #his .uery does not result in an error. But there are two ways to improve the . . ). odi4ied_date 2 TO_. odi4ied_date FROM section WHERE odi4ied_date 5=TO_. '. Yes No %he M./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 11 o# 16 7ersion8 )9292334 ". Secondly2 it does not speci!y the century in the text literal. Aggregate #unctions always return a single result #or a group o# =alues. DD8M"N8RR 55. An aggregate #unction can be used in a 1A7.uery could be improved as !ollows: SELECT course_no. Yes . %astly2 always consider the time component.NE clause. '.NE clause can be used instead o# the D1:R: clause. /)) Additional *+A #or .* MO$*0000') ($. )! this statement is executed on a system with a di!!erent de!ault !ormat mas&2 it results in an error.)#5 #)M' H"N' data type.++ AM #H5:#HM .SELECT course_no.N and MAI #unctions wor( only on the N&MB:R data type.* MO$*0000') 9.. 6.hapter 6 1.SS. 10.M). #he #"BDS)N#'R4A% !unction converts a text literal to an )N#'R4A% DA0 #" S'("ND data type.uery. SELECT (67'CO(LESCE'cost. Yes No %he 1A7.(TE''""*M(R*!+++'. No Yes 2.hapters 1-. . +irstly2 the text literal 668MAR8FF relies on implicit conversion to the DA#' data type and does not speci!y the !ormat mas&. Yes #he !ollowing shows one o! the de!ault !ormats !or the #)M'S#AM/ . #he ..(TE''"#*M(R*!+++'.

CO%$T'*) FROM enroll ent 7RO%8 &0 student_id Yes No Additional *+A #or . student_id.FROM course Yes No .. SELECT S0S. %he #ollowing >uery is in=alid. 'HELLO'.(TE./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 12 o# 16 7ersion8 )9292334 .hapters 1-.

A2 which does ta&e N$%% values into account. No #he !ollowing . student_id. 'HELLO'. 4. SELECT (67'CO(LESCE'cost. 7. SELECT S0S. No #he M)N and MAI !unctions wor& only on the N$MB'R data type. 5.Answers for "Chapter #" 1. 3. Yes Aggregate !unctions always return a single result !or a group o! values. 2. #he exception is ("$N#?. /)) FROM course No #he !ollowing . Yes #he 5A4)N: clause can be used instead o! the .uery is invalid./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 1 o# 16 7ersion8 )9292334 .uery is invalid. 6. Yes An aggregate !unction can be used in a 5A4)N: clause. Yes Aggregate !unctions usually ignore N$%% values.5'R' clause.(TE. CO%$T'*) FROM enroll ent 7RO%8 &0 student_id Additional *+A #or .hapters 1-.

. section s. ($. Determine the >uestion #or the #ollowing S:':. Additional *+A #or . SELECT FROM WHERE ($. section_id. section_no. e.section_id.section_id = e.section_id :.pe_code. course c c. description. ($.description. Display a list o# course descriptionsC their section numbersC and #or each section the last name o# the assigned instructor.last_na e student s.student_id. $nly show sections that start on %uesdays Display the course descriptionC section numberC and last names o# instructors teaching classes on Dednesdays.% statement.instructor_id = i.hapters 1-.student_id = e.course_no s. SELECT FROM WHERE ($. %he #ollowing two S*' statements are e>ui=alent. instructor i c.student_id) last_na e = 'Torres' 2. ./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 1" o# 16 7ersion8 )9292334 .student_id = ""! s. 1. '. c.section_id :. Yes No .instructor_id TO_CH(R'start_date_ti e.student_id last_na e = 'Torres' s. %he S:':.n=alid >uery. section s. :rade_t. last_na e course c.% statement causes a .course_no = s.student_id = e. enroll ent e s.student_id = e. Show also the grade type. Display the course descriptionC section numberC and the last name o# the instructor that teaches the section.artesian product. last_na e student s 3O9$ enroll ent e 's.student_id Show the course description o# the course 3 in which the student with the id 221 is enrolled. Show the descriptionC grade typeC and grade #or course number 3 and the student with the id o# 221. Dhich >uestion is answered by the #ollowing S*' statementF SELECT FROM WHERE ($. ($.course_no = c.course_no = ##/ :.course_no s. enroll ent e. Show only those courses with enrollments starting on %uesdays. ($.0') = 'T%E' Show a list o# the coursesC sectionsC and instructors. ($.hapter .student_id. SELECT FROM O$ WHERE s.section_id = e. nu eric_:rade :rade :. s.

section_id = e.section_id = e. enroll ent e s.*.student_id = e.student_id Additional *+A #or .instructor_id TO_CH(R'start_date_ti e.section_id :.course_no = ##/ :. SELECT FROM O$ WHERE <.uestion is answered by the !ollowing S*% statementD SELECT FROM WHERE ($. description. Determine the .<ip = <.last_na e student s.course_no = s. last_na e student s 3O9$ enroll ent e 's.". ($. Show the #irst and last name o# students with the last name o# %orres. . e.uestion !or the !ollowing S'%'(# statement. ($. section s. course c c.uivalent. ($. Determine the >uestion #or the #ollowing S*' statement.<ip) last_na e = 'Torres' Show students with the #irst and last name o# %orres and their corresponding Jip code. '. ($. Yes #he !ollowing two S*% statements are e.hich . SELECT FROM WHERE ($.course_no s. section s.nclude all the columns o# the G.n=alid >uery. SELECT FROM O$ WHERE s. ($. . . c. last_na e.section_id.0') = 'T%E' Display a list o! course descriptions2 their section numbers2 and !or each section the last name o! the assigned instructor.hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 1) o# 16 7ersion8 )9292334 . :rade_t. enroll ent e. last_na e course c. )t also avoids any errors in S*% statements i! a column with the same name is added to the other table in the !uture. nu eric_:rade :rade :. 3.student_id.student_id = ""! s. 4irst_na e student s 3O9$ <ipcode < 's.student_id) last_na e = 'Torres' #he statements are e.instructor_id = i.pe_code. instructor i c. SELECT FROM WHERE ($.student_id = e. Answers for "Chapter $" 1.course_no = c. section_no.course_no s. section_id. )t is pre!erable to speci!y aliases in the column2 because it is easier to identi!y which tables the columns belong to. "nly show sections that start on #uesdays 2.0.student_id = e.description.$D: table in the result.student_id.section_id :. s.uivalent.student_id last_na e = 'Torres' s.

*. Determine the .hapters 1-. SELECT FROM O$ WHERE Show the !irst and last name o! students with the last name o! #orres and their corresponding Jip code. )nclude all the columns o! the H)/("D' table in the result. <.<ip = <. last_na e./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 16 o# 16 7ersion8 )9292334 .Show the description2 grade type2 and grade !or course number CC3 and the student with the id o! 66>.<ip) last_na e = 'Torres' Additional *+A #or .uestion !or the !ollowing S*% statement. 4. 4irst_na e student s 3O9$ <ipcode < 's.