0% found this document useful (0 votes)
216 views17 pages

Practice Q's 1-7

The document contains practice questions and answers for chapters 1-7 from the book "Oracle SQL by Example" by Alice Rischert. It includes 10 multiple choice questions for each chapter, covering topics such as relational database concepts, SQL commands, joins, functions and data types. The questions test understanding of key SQL concepts and how to properly write SQL statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
216 views17 pages

Practice Q's 1-7

The document contains practice questions and answers for chapters 1-7 from the book "Oracle SQL by Example" by Alice Rischert. It includes 10 multiple choice questions for each chapter, covering topics such as relational database concepts, SQL commands, joins, functions and data types. The questions test understanding of key SQL concepts and how to properly write SQL statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 17

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

2.

A table always has columns and rows.


No
Yes

3.

A schema diagram is used to understand a database's


design.
No
Yes

4.

A column in a table defined as NOT NULL is a primary or


foreign key.
No
Yes

5.

Referential integrity is enforced by the relationship between


the primary key and foreign key.
Yes
No

Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 1 of 17
Version: 5/2/2009

Answers for "Chapter 1"

1.

Yes

A RDBMS groups data in a logical manner into tables and manages


the access to the tables.

2.

No

A table always has columns and rows.


Note: A table can exist without rows but must have at least one
column.

3.

Yes

A schema diagram is used to understand a database's design.

4.

No

A column in a table defined as NOT NULL is a primary or foreign key.

5.

Yes

Referential integrity is enforced by the relationship between primary


key and foreign key.

Chapter 2
1.

Any column in a table is a candidate for the SELECT list.


Yes
No

2.

The keywords DISTINCT and UNIQUE cannot be used interchangeably in


a SELECT list.
No
Yes

3.

The DESCRIBE command is a SQL command.


Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 2 of 17
Version: 5/2/2009

No
Yes

4.

Files saved with a .sql extension can be executed with the @ command.
Yes
No

5.

The push pin icon in SQL Developer allows you to toggle between the
worksheets.
Yes
No

6.

The SQL*Plus buffer shows the last SQL command you typed.
No
Yes

7.

An Oracle database requires that a user have a user id and password to


communicate with it.
Yes
No

8.

You can store at most 4,000 characters in a VARCHAR2 column.


Yes
No

9.

You must always type column and table names in lowercase letters for the
SQL statement to execute correctly.
Yes
No

Answers for "Chapter 2"

1.

Yes

Any column in a table is a candidate for the SELECT list.

2.

No

These keywords DISTINCT and UNIQUE cannot be be used


interchangeably.

Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 3 of 17
Version: 5/2/2009

3.

No

The DESCRIBE command is a SQL command.

4.

Yes

Files saved with a .sql extension can be executed with the @


command.

5.

No

The push pin icon in SQL Developer allows you to toggle between the
worksheets.

6.

Yes

The SQL*Plus buffer shows the last SQL command you typed.

7.

Yes

An Oracle database requires that a user have a user id and password


to communicate with it.

8.

Yes

You can store at most 4,000 characters in a VARCHAR2 column.


Note. This answer is CORRECT, unless you use an Oracle version 7 or below
where the limit was 2,000 characters.

9.

No

You must always type column and table names in lowercase letters
for the SQL statement to execute correctly.
Note: The SQL language's keywords are not case-sensitive. For clarity and
readability you follow a naming convention. The convention used in this book
is listed in Appendix B, "SQL Formatting Guidelines."

Chapter 3
1.

The BETWEEN operator tests for a range of values.


Yes
No

Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 4 of 17
Version: 5/2/2009

2.

It is not possible to limit the number of rows returned from a SELECT


statement.
No
Yes

3.

You can test for null values by using an empty string such as the following:
SELECT * FROM course WHERE prerequisite = ''.
No
Yes

4.

The optional keyword AS can precede the alias name.


Yes
No

5.

The AND and OR logical operators can only be combined with the use of
parentheses.
Yes
No

6.

The ORDER BY clause must follow the WHERE clause.


No
Yes

7.

The following notation starts a multi-line comment.


/*
Yes
No

8.

A pseudocolumn such as ROWNUM is not actually stored in the database.


Yes
No

9.

The underscore wildcard character can match multiple characters.


Yes
No

Answers for "Chapter 3"


Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 5 of 17
Version: 5/2/2009

1.

Yes

The BETWEEN OPERATOR tests for a range of values.

2.

No

It is not possible to limit the number of rows returned from a SELECT


statement.
Note: The WHERE clause allows you to restrict the number of rows
returned by the query.

3.

No

You can test for null values by using an empty such as the following:

4.

Yes

The optional keyword AS can precede the alias name.

5.

No

The AND and OR logical operators can only be combined with the use
of parentheses.

6.

Yes

The ORDER BY clause must follow the WHERE clause.

7.

Yes

The following notation starts a multi-line comment.


/*

8.

Yes

A pseudocolumn such as ROWNUM is not actually stored in the


database.

9.

No

The % underscore wildcard character can match multiple characters.

SELECT * FROM course WHERE prerequisite = ''

Chapter 4
1.

Character functions transform data in tables in order to retrieve it more


Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 6 of 17
Version: 5/2/2009

easily.
Yes
No

2.

You can retrieve specific character data in a database regardless of what


case it was entered in.
Yes
No

3.

Arithmetic operators and number functions can be combined.


No
Yes

4.

The DUAL table contains data transformed by character functions.


No
Yes

5.

Like character functions, number functions operate on single values.


Yes
No

6.

The LPAD function left trims a string.


Yes
No

7.

Unlike many other character functions, the LENGTH and INSTR function
return a NUMBER.
No
Yes

8.

The following SQL query returns -1: SELECT SIGN(-45) FROM dual
Yes
No

9.

You can substitute the NVL function with the COALESCE function.
No
Yes
Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 7 of 17
Version: 5/2/2009

10 .

The simple CASE expression tests for equality only.


Yes
No

Answers for "Chapter 4"

1.

No

Character functions transform data in tables in order to retrieve it


more easily.
Note: All functions, including character functions, transform the output of
data, not actual data in tables. You learn about modifying the data in tables in
Chapter 11, "Insert, Update, and Delete."

2.

Yes

You can retrieve specific character data in a database regardless of


what case it was entered in.

3.

Yes

Arithmetic operators and number functions can be combined.

4.

No

The DUAL table contains data transformed by character functions.

5.

Yes

Like character functions, number functions operate on single values.

6.

No

The LPAD function left trims a string.

7.

Yes

Unlike many other character functions, the LENGTH and INSTR


function return a NUMBER.

8.

Yes

The following SQL query returns -1: SELECT SIGN(-45) FROM dual

Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 8 of 17
Version: 5/2/2009

9.

Yes

You can substitute the NVL function with the COALESCE function.

10.

Yes

The simple CASE expression tests for equality only.

Chapter 5
1.

The following SQL query implicitly performs a data type conversion.


SELECT student_id, last_name
FROM student
WHERE student_id = '123'

No
Yes

2.

What is the result of the following SQL query?


SELECT TO_NUMBER('ABC')
FROM dual

Oracle Error message


ABC
123

3.

Which of the following SQL statements results in this error: ORA-01722:


invalid number ?
SELECT
FROM
SELECT
FROM
SELECT
FROM
SELECT
FROM

4.

TO_CHAR(TO_NUMBER(-999.999))
dual
TO_CHAR(TO_NUMBER('$-999.999'))
dual
TO_NUMBER(TO_CHAR(999.999))
dual
TO_CHAR(TO_NUMBER('-999.999'))
dual

Which format mask is required to display this output?


'Mar 17, 2010'
Mon-dd yyyy
Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 9 of 17
Version: 5/2/2009

Mon dd, yyyy


dd-mon-yyyy
MON dd, YY

5.

Which format mask is required to display this output?


'Sunday 2/18/2010'?
FmDay mm/dd/yyyy
DAY MM/DD/YYYY
Day mm/dd/yyyy
Dayfm MM/DD/YYYY

6.

Does the following SQL statement return any rows?


SELECT *
FROM section
WHERE start_date_time BETWEEN
TO_DATE('31-DEC-2200','DD-MON YYYY')
AND TO_DATE('01/01/1900','MM/DD/YYYY')

Invalid query.
Yes
No

7.

Would you change the following SQL statement in any way?


SELECT start_date_time
FROM section
WHERE TO_CHAR(start_date_time, 'DD-MON-YYYY') < '01-JAN-2010'

No
Yes

8.

Will the following SQL statement return an error?


SELECT course_no, modified_date
FROM section
WHERE modified_date = '22-MAR-99'

No
Yes

9.

The following shows one of the default formats for the TIMESTAMP WITH
TIME ZONE data type. 'DD-MON-RR HH.MI.SS.FF AM TZH:TZM'.
Yes
No
Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 10 of 17
Version: 5/2/2009

10.

The TO_DSINTERVAL function converts a text literal to an INTERVAL


DAY TO SECOND data type.
No
Yes

Answers for "Chapter 5"

1.

Yes

The following SQL query implicitly performs a data type conversion.

SELECT student_id, last_name


FROM student
WHERE student_id = '123'
The STUDENT_ID column is of the NUMBER data type. The WHERE clause
specifies the text literal '123' which is a string, also called a text constant or
text literal. The two data types do not agree, therefore, Oracle performs an
implicit conversion. It is always preferable to explicitly perform the conversion.

2.

Oracle error
message

What is the result of the following SQL query?

SELECT TO_NUMBER('ABC')
FROM dual
A text literal such as 'ABC' cannot be converted into a number.

Which of the following SQL statements results in this error: ORA01722: invalid number

3.

SELECT TO_CHAR(TO_NUMBER('$-999.999'))
FROM dual
A text literal such as '$-999.99' cannot be converted into a number. Use the
SUBSTR function to remove the $ symbol, and then convert to a number.

4.

Mon dd, yyyy

Which following format mask is required to display this output?


'Mar 17, 2010'

5.

FmDay
mm/dd/yyyy

Which format mask is required to display this output?


'Sunday 2/18/2010'
The fillmode (fm) specifier is required before the Day format mask. Note the
case of the fm specifier is irrelevant.

6.

No

Does the following SQL statement return any rows?

SELECT *
Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 11 of 17
Version: 5/2/2009

FROM section
WHERE start_date_time BETWEEN
TO_DATE('31-DEC-2200','DD-MON YYYY')
AND TO_DATE('01/01/1900','MM/DD/YYYY')
The BETWEEN operator requires the lowest end of the range first, then the
highest. Instead, write it as follows:

SELECT *
FROM section
WHERE start_date_time BETWEEN
TO_DATE('01/01/1900','MM/DD/YYYY')
AND TO_DATE('31-DEC-2200','DD-MON-YYYY')

7.

Yes

Would you change the following SQL statement in any way?

SELECT start_date_time
FROM section
WHERE TO_CHAR(start_date_time, 'DD-MON-YYYY') < '01JAN-2010'
Do not use the TO_CHAR function on the START_DATE_TIME column, because
the query returns the incorrect result.

8.

No

Will the following SQL statement return an error?

SELECT course_no, modified_date


FROM section
WHERE modified_date = '22-MAR-99'

This query does not result in an error. But there are two ways to improve the
query. Firstly, the text literal '22-MAR-99' relies on implicit conversion to the
DATE data type and does not specify the format mask. If this statement is
executed on a system with a different default format mask, it results in an
error. Secondly, it does not specify the century in the text literal. Lastly, always
consider the time component. The query could be improved as follows:

SELECT course_no, modified_date


FROM section
WHERE modified_date >=TO_DATE('22-MAR-1999', 'DDMON-YYYY')
AND modified_date < TO_DATE('23-MAR-1999', 'DDMON-YYYY')

9.

Yes

The following shows one of the default formats for the TIMESTAMP
WITH TIME ZONE data type. 'DD-MON-RR HH.MI.SS.FF AM TZH:TZM'.

10.

Yes

The TO_DSINTERVAL function converts a text literal to an INTERVAL


DAY TO SECOND data type.

Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 12 of 17
Version: 5/2/2009

Chapter 6
1.

Aggregate functions always return a single result for a group of values.


No
Yes

2.

Aggregate functions usually ignore NULL values.


No
Yes

3.

An aggregate function can be used in a HAVING clause.


Yes
No

4.

The HAVING clause can be used instead of the WHERE clause.


Yes
No

5.

The MIN and MAX functions work only on the NUMBER data type.
No
Yes

6.

The following query is invalid.


SELECT AVG(COALESCE(cost, 0))
FROM course

Yes
No

7.

The following query is invalid.


SELECT SYSDATE, 'HELLO', student_id, COUNT(*)
FROM enrollment
GROUP BY student_id

Yes
No

Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 13 of 17
Version: 5/2/2009

Answers for "Chapter 6"

1.

Yes

Aggregate functions always return a single result for a group of


values.

2.

Yes

Aggregate functions usually ignore NULL values.


The exception is COUNT(*), which does take NULL values into account.

3.

Yes

An aggregate function can be used in a HAVING clause.

4.

Yes

The HAVING clause can be used instead of the WHERE clause.

5.

No

The MIN and MAX functions work only on the NUMBER data type.

6.

No

The following query is invalid.

7.

No

The following query is invalid.

SELECT AVG(COALESCE(cost, 0))


FROM course

SELECT SYSDATE, 'HELLO', student_id, COUNT(*)


FROM enrollment
GROUP BY student_id

Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 14 of 17
Version: 5/2/2009

Chapter 7
1.

Which question is answered by the following SQL statement?


SELECT
FROM
WHERE
AND
AND

description, section_no, last_name


course c, section s, instructor i
c.course_no = s.course_no
s.instructor_id = i.instructor_id
TO_CHAR(start_date_time, 'DY') = 'TUE'

Show a list of the courses, sections, and instructors.


Display the course description, section number, and the last name of
the instructor that teaches the section. Show only those courses with
enrollments starting on Tuesdays.
Display a list of course descriptions, their section numbers, and for
each section the last name of the assigned instructor. Only show
sections that start on Tuesdays
Display the course description, section number, and last names of
instructors teaching classes on Wednesdays.

2.

The following two SQL statements are equivalent.


SELECT
FROM
WHERE
AND

s.student_id, e.section_id, s.last_name


student s, enrollment e
s.student_id = e.student_id
last_name = 'Torres'

SELECT
FROM
ON
WHERE

s.student_id, section_id, last_name


student s JOIN enrollment e
(s.student_id = e.student_id)
last_name = 'Torres'

Yes
No

3.

Determine the question for the following SELECT statement.


SELECT
FROM
WHERE
AND
AND
AND
AND
AND

c.description, grade_type_code, numeric_grade


grade g, enrollment e, section s, course c
c.course_no = 330
g.student_id = 221
s.course_no = c.course_no
s.section_id = e.section_id
g.section_id = e.section_id
g.student_id = e.student_id

Show the course description of the course 330 in which the student
with the id 221 is enrolled. Show also the grade type.
Show the description, grade type, and grade for course number 330
and the student with the id of 221.
Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 15 of 17
Version: 5/2/2009

Invalid query.
The SELECT statement causes a Cartesian product.

4.

Determine the question for the following SQL statement.


SELECT
FROM
ON
WHERE

z.*, last_name, first_name


student s JOIN zipcode z
(s.zip = z.zip)
last_name = 'Torres'

Show students with the first and last name of Torres and their
corresponding zip code. Include all the columns of the ZIPCODE
table in the result.
Invalid query.
Show the first and last name of students with the last name of Torres.

Answers for "Chapter 7"

Which question is answered by the following SQL statement?

1.

SELECT
FROM
WHERE
AND
AND

description, section_no, last_name


course c, section s, instructor i
c.course_no = s.course_no
s.instructor_id = i.instructor_id
TO_CHAR(start_date_time, 'DY') = 'TUE'

Display a list of course descriptions, their section numbers, and for


each section the last name of the assigned instructor. Only show
sections that start on Tuesdays

2.

Yes

The following two SQL statements are equivalent.

SELECT
FROM
WHERE
AND

s.student_id, e.section_id, s.last_name


student s, enrollment e
s.student_id = e.student_id
last_name = 'Torres'

SELECT
FROM
ON
WHERE

s.student_id, section_id, last_name


student s JOIN enrollment e
(s.student_id = e.student_id)
last_name = 'Torres'

The statements are equivalent. It is preferable to specify aliases in the column,


because it is easier to identify which tables the columns belong to. It also
avoids any errors in SQL statements if a column with the same name is added
to the other table in the future.

Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 16 of 17
Version: 5/2/2009

3.

Determine the question for the following SELECT statement.

SELECT
FROM
WHERE
AND
AND
AND
AND
AND

c.description, grade_type_code, numeric_grade


grade g, enrollment e, section s, course c
c.course_no = 330
g.student_id = 221
s.course_no = c.course_no
s.section_id = e.section_id
g.section_id = e.section_id
g.student_id = e.student_id

Show the description, grade type, and grade for course number 330
and the student with the id of 221.

4.

Determine the question for the following SQL statement.

SELECT
FROM
ON
WHERE

z.*, last_name, first_name


student s JOIN zipcode z
(s.zip = z.zip)
last_name = 'Torres'

Show the first and last name of students with the last name of Torres
and their corresponding zip code. Include all the columns of the
ZIPCODE table in the result.

Additional Q&A for Chapters 1-7; Oracle SQL by Example by Alice Rischert; Prentice Hall (2009)
Page 17 of 17
Version: 5/2/2009

You might also like