Download Review Question Solutions

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Concurrency control wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Database wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Functional Database Model wikipedia , lookup

Oracle Database wikipedia , lookup

Clusterpoint wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Open Database Connectivity wikipedia , lookup

SQL wikipedia , lookup

Database model wikipedia , lookup

Relational model wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
Solutions to Review Questions
Chapter 1
Review Questions
1. C
2. B
3. A
4. C
5. D
6. C
7. A
8. A
9. C
10. B
11. Procedure - PL/SQL block that can receive and return multiple values
Function - PL/SQL block that typically returns one value and can be used in SQL and
PL/SQL statements
Package - Groups procedures and functions together
Database Trigger - PL/SQL block that Fires automatically based on a DML action on
a specified table
12. a. Can use SQL within PL/SQL
b. Greater efficiency in processing as the code can be stored in the database and
reduces transmissions over the network
c. Tighter security as users will not need rights to directly access database objects
13. Yes, regardless of the development tool it is still advantageous to use stored program
units especially when performing SQL tasks as this will reduce overall efficiency by
reducing network transmissions.
14. A middle-tier exists in the three-tier model which serves as the application server.
The application code is stored on the application server rather than the client machine.
15. A user interface is the screens that a user will see to interact with the application. If a
developer uses Oracle tools such as Oracle Forms, PL/SQL code will provide all the
program code that will process based on any user events that occur such as clicking a
button.
Chapter 2
Review Questions
1. B
2. A, B, D
3. B
4. A
5. C
6. C
7. D
8. A
9. C
10. C
11. Variables are named memory areas that hold values to allow retrieval and
manipulation of values within our programs
12. A SELECT statement within a PL/SQL block must include an INTO clause to
indicate the variable/s that will hold the data being retrieved. In addition, a SELECT
statement that returns no rows will raise an Oracle error.
13. An implicit cursor is automatically created by the Oracle system when an SQL
statement is executed. An explicit cursor is declared in the DECLARE section as a
SELECT statement. Everything must be handled manually in the code with the OPEN,
FETCH and CLOSE steps.
14. The CURSOR FOR loop automatically declares a record variable to hold values
returned with a FETCH. It also automatically handles the OPEN, FETCH and CLOSE
actions.
15. Composite data types allow the creation of a variable that can hold multiple values
with various data types as a single unit. Examples include a record and a table of records.
Advanced Review Questions
1. A
2. C
3. C
4. A
5. B
Chapter 3
Review Questions
1. C
2. B
3. A
4. A
5. B
6. D
7. A
8. B
9. A
10. A
11. Provide program instructions as to what to do if errors occur. The goal is to avoid the
user receiving confusing error messages and/or interruption of application processing.
12.
1) Declare an exception variable to identify an exception name
2) Use the RAISE statement in the executable section to appropriately raise the
exception during block processing
3) Create an exception handler in the EXCEPTION section using the exception name
created in the DECLARE section
13.
1) Predefined - Common Oracle error that already have an exception name associated
such as NO_DATA_FOUND
2) Non-Predefined - All other Oracle errors that must have an exception name
associated by using
PRAGMA EXCEPTION_INIT
14.
1) Basic - Uses an EXIT WHEN statement within the loop to check a condition and, if
TRUE, stop the looping activity.
2) While - Includes a condition check in the opening loop statement and if FALSE will
stop the looping activity. This type of loop may never execute any of the statements
within the loop.
3) For - Indicates an iteration range in the opening loop statement. A counter variable is
created and starts at the lower bound value of the range. The counter is increased by 1
for each iteration of the loop. The loop activity stops when the counter reaches the upper
bound number.
15. Many believe it is easier to read Case statements in that they list the condition being
checked at the beginning only once followed by each of the values being checked. This
can lead to more efficient processing versus an IF statement. If many ELSIF clauses are
used, the action of checking the variable value is accomplished repeatedly. With a Case
statement, the value of the variable is evaluated only once at the beginning.
Advanced Review Questions
1. A
2. D
3. B
4. C
5. B
Chapter 4
Review Questions
1. d
2. a,b,c
3. c
4. c
5. a,c
6. c
7. c
8. c
9. b
10. c
11. Named program units are PL/SQL blocks that have been assigned a name so they can
be saved and reused. Header information including a name and parameters is followed
by a PL/SQL block to construct a named program unit. Types of named program units
include procedures, functions, packages and triggers.
12. The DBMS_OUTPUT statement can be used to display variable values throughout
the procedure, as well as, display messages to confirm which statements are executing
within the procedure.
13. Parameters make a procedure flexible or reusable in that they allow values to be sent
into and out of a procedure. Three parameter modes are available which determine how
values can flow through the parameters: IN, OUT and IN OUT.
14. One continuous transaction is created across multiple program units. If procedure A
calls procedure B, one transaction is created for thee DML actions in both procedures. If
a transaction control statement such as a commit is issued in procedure B, the DML
activity from both procedures will be committed. Separate transactions can be created by
using the PRAGMA AUTONOMOUS_TRANSACTION directive.
15. If we would like to share the program unit across a number of applications, saving to
the database makes it available to anyone who has access to the database (and proper
privileges of course!). Also, if it is SQL intensive it is more efficient to have it compiled
and stored on the database as it will require interaction with database objects.
Advanced Review Questions
1. c
2. c
3. d
4. c
5. c
Chapter 5
Review Questions
1. a
2. c
3. c
4. a
5. b
6. c
7. c
8. b
9. b
10. d
11. Functions are typically used to return one value via a RETURN statement. Functions
that follow certain restrictions can be used in both PL/SQL and SQL statements.
12. In a function, the RETURN statement returns a value to the calling environment. In a
procedure, a RETURN statement changes the flow of processing by exiting the procedure
at that point.
13. Formal parameters are the parameter names provided in the header of a procedure or
function and are used to receive values when the program unit is invoked. Actual
parameters are the arguments used in the statement that calls or invokes a program unit.
14. Passing values by reference means the value in the actual parameter is not copied to
the formal parameter. A single copy of the value exists in the actual parameter and a
pointer to it is held in the formal parameter. Passing values by value indicates a copy of
the value held in the actual parameter is made and held in the formal parameter.
15. -Must be a stored database object (or in a stored package)
-Can use only IN parameters
-Formal parameter data types must use database data types (no PL/SQL data types such
as BOOLEAN are permitted)
-Return data types must be a database data type
-Must not issue transaction control statements to end the current transaction prior to
execution
-Cannot issue alter session or alter system commands
Advanced Review Questions
1. d
2. a
3. c
4. c
5. b
Chapter 6
Review Questions
1. B
2. D
3. A,D
4. C,D
5. B,D
6. A
7. C
8. D
9. A
10. D
11. The user objects view can be used to determine all the packages that exist in the
database. In the query, use a WHERE clause to select the rows that contain the term
'PACKAGE' in the object type column. Selecting the text column of the user source view
will list all the source code line of the package. Use a WHERE clause on the name
column to select a single package.
12. If there are values referenced continually in the application, storing them in packaged
variables will allow the values to only be retrieved once thus saving data retrieval
processing. The values in global constructs are persistent for the entire user session.
13. Overloading allows two or more program units in a package to have the same name
yet accept a different set of arguments. At times you may have certain functionality that
you need to occur but you must handle a variety of different types of data to be supplied
to the program unit. In this case, you can write several program units to contain the same
code yet accept different arguments. The Oracle server will automatically identify the
appropriate copy of the program unit to use based on the arguments provided in the
invocation.
14. If you need to share some values or objects across all sessions, a package
specification allows this by housing global variables, cursors and types. If the package
only consists of global constructs to share and no program units then a package body is
not needed.
15. A program unit that exists in a package body but is not declared in the package
specification is referred to as a private construct. It is private in that only program units
that are included in the same package can call or invoke this program unit.
Advanced Review Questions
1. C
2. D
3. B
4. C
5. B, C
Chapter 7
Review Questions
1. b
2. c
3. a,c
4. b
5. a,b
6. d
7. b
8. b
9. a
10. c
11. b
12. b
13. b
14. d
15. a,c
16. Dependencies on packaged program units as driven by the package specification.
Any changes to the header of the packaged program units being referenced will change
the status of the dependent object to INVALID. Changes to the body only will not alter
the status of dependent objects.
17. BASK_CALC_SP
ORDER_TOTAL_SP
18. To be aware of the recompilation needs. A developer should recompile objects made
INVALID manually to test the reference and avoid this processing at runtime. In
addition, remote dependencies will cause a runtime error if objects not recompiled.
19. If a local dependent object is INVALID when executed, the system will automatically
recompile the object and continue processing if successful. A remote dependent object
will not be flagged as INVALID when remote referenced objects are modified.
Therefore, when executed for the first time after the remote object has been modified, the
system will flag the dependent object as INVALID and raise an error. The INVALID
status will cause the object to be recompiled upon the second execution.
20. Using the dependency tree utility provided by Oracle.
-Create needed objects with the utldtree.sql script
-Execute the deptree_fill procedure for the object of
interest
-Query the deptree or ideptree view
Advanced Review Questions
1. b
2. d
3. b
4. a
5. b
Chapter 8
Review Questions
1. a,c,d
2. d
3. a
4. b
5. c
6. b
7. a,b,c
8. c
9. a
10. b
11. b
12. a,b
13. a
14. a
15. b
16. A mutating table error is raised when a row level trigger attempts to use the table that
the trigger is based on.
17. Reference Table 8-3 for possible responses.
18. First, a database trigger is more closely tied to a specific table versus a program unit.
If a table is dropped, the associated triggers will be dropped while the program units will
only change to an INVALID status. Second, program units must be explicitly called by
application code while triggers fire automatically based on events.
19. With a DELETE event, the only values involved are those in the existing row that are
being deleted.
20. If a table is dropped, the associated triggers will be dropped while the program units
will only change to an INVALID status.
Advanced Review Questions
1. b
2. b
3. c
4. c
5. c
Chapter 9
Review Questions
1. b
2. d
3. c
4. a,c
5. a
6. c
7. d
8. b
9. b
10. a
11. The DBMS_JOB package allows the scheduling of jobs that will automatically
invoke program execution at specified intervals. The ability to schedule jobs to execute
during low usage hours is important in balancing system performance. Also, A broken
parameter allows the job to be flagged that it is not executing properly and should be
reviewed.
12. An Oracle built-in package is the same packages we can create ourselves. The
packages group together related procedures and functions. The built-ins are supplied by
Oracle to provide functionality that is commonly needed. The script that builds each of
the Oracle supplied packages are available in the rdbms\admin of the Oracle database
directory.
13. Oracle built-in packages are not different than the ones we can construct ourselves.
14. The UTL_FILE package enables a text (non-Oracle file) to be read or written. This
can be important in exchanging data since data can be stored in so many different
formats.
15. The UTL_SMTP package has been increasingly important as the automatic
generation of email can be used to improve so many facets of business. Email is used
externally to communicate with customers and internally to improve the flow of
information.
Advanced Review Questions
1. a
2. a
3. a
4. b
5. a
Chapter 10
Review Questions
1. a
2. d
3. a,c
4. b
5. a
6. b
7. b,c
8. c,d
9. b
10. a
11. Dynamic SQL will enable the creation of a much more flexible query system in that it
will allow users to select the columns to be queried and the columns on which criteria
will be set. The user could also be allowed to select functions (round, AVG, etc.) to be
used.
12. -The number and types of columns to be used is known
-The number and type of bind variables is known
-To perform DDL
-Executing the statement only once or twice
-User-defined types such as object and collections are used (not supported by
DBMS_SQL)
-Fetching rows of data into PL/SQL records (not supported by DBMS_SQL)
-SQL statement is less than 32KB in size
13. The main difference of the object-oriented approach versus traditional database
design is that program units are tied to the object in an object-oriented database. In other
words, an object not only consists of data elements such as a table but it also contains the
procedures and functions associated with that data.
14. In an object relational database REF variables are used to create relationships while
foreign keys are used in the traditional relational database. REF variables serve as
pointers to the row of another table which is related.
15. An object view is used to allow a traditional relational database to take advantage of
object-oriented features. The object view is a view that associates table data to object
types creating an object layer on top of the traditional database.
Advanced Review Questions
1. b,d
2. a
3. b
4. b
5. c
Chapter 11
Review Questions
1. c
2. a,c
3. a
4. b
5. d
6. b
7. a
8. c
9. a,c
10. b
11. c
12. b
13. b
14. a
15. b
16. The optimizer determines the most efficient way to process the statement creating an
execution plan that will be followed.
17. Yes, the order of conditions in an IF or CASE statement can have an impact on
performance. If certain values have the most matches in the condition being checked,
these values should be checked at the top of the condition statements.
18. The driving table in a join is considered the one that the execution uses first to
perform the join operation. The goal is to have the smallest table involved in the join
operation to be the driving table to ascertain the best performance. The rule-based
optimizer will use the last table listed in the FROM clause as the driving table. Whereas,
the cost-based optimizer will use the first table listed in the FROM clause as the driving
table. Therefore, be careful in ordering the tables in your FROM clauses. The order of
tables in the FROM clause in all queries involving joins should be reviewed with this
consideration. Large differences in table sizes can have a significant impact on
performance if not listed in the most advantageous order.
19. If the tables used in the SQL statement have been analyzed.
20. The optimizer will use these indexes only when the leading column indexed is
included in the criteria of the SQL statement.