1.
CREATE OR REPLACE PACKAGE theater_pck
IS
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER);
END theater_pck;
CREATE OR REPLACE PACKAGE BODY theater_pck
IS
current_avg_cost_per_ticket NUMBER;
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER)
IS
v_seats_sold gross_receipt.seats_sold%TYPE;
v_budget studio.yearly_budget%TYPE;
BEGIN
SELECT seats_sold
INTO v_seats_sold
FROM gross_receipt
WHERE movie_id = v_movie_id
AND theater_id = v_theater_id;
END find_seats_sold;
FUNCTION get_budget
(v_studio_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
END get_budget;
END theater_pck;
Which statement about the CURRENT_AVG_COST_PER_TICKET variable is true?
Correct Answer
C. It can be referenced by all constructs within the package.
Explanation
The CURRENT_AVG_COST_PER_TICKET variable can be referenced by all constructs within the package. This means that it can be accessed and used by any procedure or function within the package, including the find_seats_sold procedure and the get_budget function. It does not need to be moved to the package specification in order to compile successfully.
2.
While creating a package, you placed the function name in the specification and the body. Which type of construct have you created?
Correct Answer
A. PUBLIC
Explanation
By placing the function name in both the specification and the body, you have created a PUBLIC construct. This means that the function can be accessed and used by other parts of the code or other packages.
3.
Examine this package specification and body:
CREATE OR REPLACE PACKAGE theater_pck
IS
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER);
END theater_pck;
CREATE OR REPLACE PACKAGE BODY theater_pck
IS
current_avg_cost_per_ticket NUMBER;
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER)
IS
v_seats_sold gross_receipt.seats_sold%TYPE;
v_budget studio.yearly_budget%TYPE;
BEGIN
SELECT seats_sold
INTO v_seats_sold
FROM gross_receipt
WHERE movie_id = v_movie_id
AND theater_id = v_theater_id;
END find_seats_sold;
FUNCTION get_budget
(v_studio_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
END get_budget;
END theater_pck;Which statement about the FIND_SEATS_SOLD procedure is true?
Correct Answer
C. It can be referenced from within and outside of the package.
Explanation
The FIND_SEATS_SOLD procedure can be referenced from both within and outside of the package. This means that the procedure can be called and used in SQL statements as well as in other parts of the code outside of the package.
4.
Examine this package specification:
CREATE OR REPLACE PACKAGE theater_package
IS
PROCEDURE find_cpt
(v_movie_id IN NUMBER, v_cost_per_ticket IN OUT NUMBER);
PROCEDURE update_theater (v_name IN VARCHAR2);
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER);
PROCEDURE add_theater;
END theater_package;
Which statement about the procedures in this specification is true?
Correct Answer
A. They are public procedures
Explanation
The procedures in this package specification are considered public procedures because they are declared without any access modifiers. Public procedures can be accessed and called by other programs or packages.
5.
CREATE OR REPLACE PACKAGE theater_pck
IS
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER);
END theater_pck;
CREATE OR REPLACE PACKAGE BODY theater_pck
IS
current_avg_cost_per_ticket NUMBER;
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER)
IS
v_seats_sold gross_receipt.seats_sold%TYPE;
v_budget studio.yearly_budget%TYPE;
BEGIN
SELECT seats_sold
INTO v_seats_sold
FROM gross_receipt
WHERE movie_id = v_movie_id
AND theater_id = v_theater_id;
END find_seats_sold;
FUNCTION get_budget
(v_studio_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
END get_budget;
END theater_pck;
Which will successfully invoke the FIND_SEATS_SOLD procedure within SQL*Plus?
Correct Answer
C. EXECUTE theater_pck.find_seats_sold (500,11);
Explanation
The correct answer is "EXECUTE theater_pck.find_seats_sold (500,11);" because it uses the correct syntax to invoke a procedure within SQL*Plus. The EXECUTE keyword is used to execute a stored procedure, followed by the fully qualified name of the procedure, which includes the package name "theater_pck" and the procedure name "find_seats_sold". The procedure is then passed the arguments 500 and 11.
6.
CREATE OR REPLACE PACKAGE theater_pck
IS
v_total_budget NUMBER;
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER);
END theater_pck;
CREATE OR REPLACE PACKAGE BODY theater_pck
IS
current_avg_cost_per_ticket NUMBER;
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER)
IS
v_seats_sold gross_receipt.seats_sold%TYPE;
v_budget studio.yearly_budget%TYPE;
BEGIN
SELECT seats_sold
INTO v_seats_sold
FROM gross_receipt
WHERE movie_id = v_movie_id
AND theater_id = v_theater_id;
END find_seats_sold;
FUNCTION get_budget
(v_studio_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
END get_budget;
END theater_pck;
Which statement about the V_TOTAL_BUDGET variable is true?
Correct Answer
D. It can be referenced from inside and outside the package.
Explanation
The V_TOTAL_BUDGET variable can be referenced from both inside and outside the package. This is because it is declared in the package specification, which allows it to be accessed by any program that uses the package. It does not need to be declared again in the package body.
7.
CREATE OR REPLACE PACKAGE BODY theater_pck
IS
current_avg_cost_per_ticket NUMBER;
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER)
IS
v_seats_sold gross_receipt.seats_sold%TYPE;
v_budget studio.yearly_budget%TYPE;
BEGIN
SELECT seats_sold
INTO v_seats_sold
FROM gross_receipt
WHERE movie_id = v_movie_id
AND theater_id = v_theater_id;
END find_seats_sold;
FUNCTION get_budget
(v_studio_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
END get_budget;
BEGIN
current_avg_cost_per_ticket := 8.50;
END theater_pck;
Which statement about the value of CURRENT_AVG_COST_PER_TICKET is true?
Correct Answer
D. It is assigned 8.50 when the package is first invoked within a session.
Explanation
The value of CURRENT_AVG_COST_PER_TICKET is assigned 8.50 when the package is first invoked within a session.
8.
Examine this function:
CREATE OR REPLACE FUNCTION get_budget
(v_studio_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
END;
This function is owned by the account, PROD. The user, JSMITH, must execute this function. Which GRANT
command(s) should be issued?
Correct Answer
A. GRANT EXECUTE ON get_budget TO jsmith;
Explanation
The function "get_budget" is owned by the account PROD and the user JSMITH needs to execute this function. To grant JSMITH the permission to execute the function, the GRANT command "GRANT EXECUTE ON get_budget TO jsmith;" should be issued. This command specifically grants the EXECUTE privilege on the "get_budget" function to the user JSMITH.
9.
Evaluate this statement:
DROP PACKAGE dept_pack;
Which statement is true?
Correct Answer
C. The statement removes the package specification and the package body.
Explanation
The given statement "DROP PACKAGE dept_pack;" is used to remove a package in a database. In this case, it removes both the package specification and the package body for the package named "dept_pack". Therefore, the correct answer is "The statement removes the package specification and the package body."
10.
Examine this package specification and body:
CREATE OR REPLACE PACKAGE theater_pck
IS
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER);
END theater_pck;
CREATE OR REPLACE PACKAGE BODY theater_pck
IS
current_avg_cost_per_ticket NUMBER;
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER)
IS
v_seats_sold gross_receipt.seats_sold%TYPE;
v_budget studio.yearly_budget%TYPE;
BEGIN
SELECT seats_sold
INTO v_seats_sold
FROM gross_receipt
WHERE movie_id = v_movie_id
AND theater_id = v_theater_id;
END find_seats_sold;
FUNCTION get_budget
(v_studio_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
END get_budget;
END theater_pck;
Which statement about the GET_BUDGET function is true?
Correct Answer
C. It can only be referenced from within the package.
Explanation
The GET_BUDGET function can only be referenced from within the package. This means that it cannot be called or used outside of the package. It is only accessible within the package's body, and cannot be accessed or called from any other part of the code or program.
11.
Examine this function:
CREATE OR REPLACE FUNCTION set_budget
(v_studio_id IN NUMBER, v_new_budget IN NUMBER)
RETURN number
IS
BEGIN
UPDATE studio
SET yearly_budget = v_new_budget
WHERE id = v_studio_id;
COMMIT;
RETURN SQL%ROWCOUNT;
END;
While executing this in SQL*Plus, you want to see the value of SQL%ROWCOUNT displayed on the screen.
Which line of code will accomplish this?
Correct Answer
D. DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT));
Explanation
The correct answer is DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT));. This line of code will display the value of SQL%ROWCOUNT on the screen using the DBMS_OUTPUT.PUT_LINE function. The TO_CHAR function is used to convert the value of SQL%ROWCOUNT to a character string before displaying it.
12.
Which command must you issue in SQL*Plus to display the result of the DBMS_OUTPUT package?
Correct Answer
D. SET SERVEROUTPUT ON
Explanation
The correct answer is SET SERVEROUTPUT ON. This command enables the display of the result of the DBMS_OUTPUT package in SQL*Plus. It allows the output from procedures, functions, and triggers to be shown in the SQL*Plus command-line interface.
13.
Which statement about packages is true?
Correct Answer
D. Package contents can be shared by multiple applications.
Explanation
Packages in programming languages like Java allow for better organization and encapsulation of code. They can contain classes, interfaces, and other packages. One of the main advantages of using packages is that their contents can be shared by multiple applications. This means that different programs can access and use the classes and resources within a package, promoting code reuse and modularity. This helps in avoiding code duplication and makes development more efficient. Therefore, the statement "Package contents can be shared by multiple applications" is true.
14.
Which statement about packages is true?
Correct Answer
D. A private package construct can only be referenced only by other constructs within the same package.
Explanation
Private package constructs are only accessible within the same package and cannot be referenced by any other constructs outside of the package. This means that they are not public and cannot be accessed by other packages or programs. Therefore, the statement "A private package construct can only be referenced only by other constructs within the same package" is true.
15.
You decide to use packages to logically group related programming constructs. Which two types of constructs
can be grouped within a package? (Choose two.)
Correct Answer(s)
B. Cursor
C. Variable
Explanation
Packages in programming are used to logically group related programming constructs. Two types of constructs that can be grouped within a package are cursors and variables. Cursors are used to retrieve and manipulate data from a database, while variables are used to store and manipulate data within a program. By grouping these constructs within a package, it allows for better organization, modularity, and reusability of code.
16.
Examine this package specification and body:
CREATE OR REPLACE PACKAGE theater_pck
IS
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER);
END theater_pck;
CREATE OR REPLACE PACKAGE BODY theater_pck
IS
current_avg_cost_per_ticket NUMBER;
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER)
IS
v_seats_sold gross_receipt.seats_sold%TYPE;
v_budget studio.yearly_budget%TYPE;
BEGIN
SELECT seats_sold
INTO v_seats_sold
FROM gross_receipt
WHERE movie_id = v_movie_id
AND theater_id = v_theater_id;
END find_seats_sold;
FUNCTION get_budget
(v_studio_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
END get_budget;
END theater_pck;
Which code will successfully assign a value to the CURRENT_AVG_COST_PER_TICKET variable within
SQL*Plus?
Correct Answer
D. This variable is private to the package and cannot be directly assigned a value within SQL*Plus.
Explanation
The explanation for the given correct answer is that the variable CURRENT_AVG_COST_PER_TICKET is declared within the package body and is not accessible outside of the package. Therefore, it cannot be directly assigned a value within SQL*Plus.
17.
Examine this package specification and body:
CREATE OR REPLACE PACKAGE theater_pck
IS
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER);
END theater_pck;
CREATE OR REPLACE PACKAGE BODY theater_pck
IS
current_avg_cost_per_ticket NUMBER;
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER)
IS
v_seats_sold gross_receipt.seats_sold%TYPE;
v_budget studio.yearly_budget%TYPE;
BEGIN
SELECT seats_sold
INTO v_seats_sold
FROM gross_receipt
WHERE movie_id = v_movie_id
AND theater_id = v_theater_id;
END find_seats_sold;
FUNCTION get_budget
(v_studio_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
END get_budget;
END theater_pck;
Which code will successfully invoke the GET_BUDGET function within SQL*Plus?
Correct Answer
D. This function cannot be referenced from outside the package.
Explanation
The code to invoke the GET_BUDGET function within SQL*Plus is not provided. However, based on the given package specification and body, the GET_BUDGET function is not declared as a public function in the package. Therefore, it cannot be referenced or invoked from outside the package.
18.
Examine this code:
CREATE OR REPLACE PACKAGE prod_pack
IS
g_tax_rate NUMBER := .08;
END prod_pack;
Which statement about this code is true?
Correct Answer
A. This package specification can exist without a body.
Explanation
The given code is a package specification, which defines the interface of a package. In Oracle PL/SQL, a package specification can exist without a body. The package specification contains declarations of variables, constants, types, cursors, and subprograms that are accessible to other program units. The package body, on the other hand, contains the implementation of the subprograms declared in the specification. However, it is not necessary to have a package body for a package specification to exist.
19.
Examine this procedure:
PROCEDURE find_cpt
(v_movie_id IN NUMBER, v_cost_per_ticket IN OUT NUMBER)
IS
BEGIN
IF v_cost_per_ticket > 8.50 THEN
SELECT cost_per_ticket
INTO v_cost_per_ticket
FROM gross_receipt
WHERE movie_id = v_movie_id;
END IF;
END;
You decide to create this procedure within the THEATER_PCK package. It will be accessible outside of the package. What will you add to the package specification?
Correct Answer
A. PROCEDURE find_cpt
(v_movie_id IN NUMBER, v_cost_per_ticket IN OUT NUMBER);
Explanation
The correct answer is "PROCEDURE find_cpt (v_movie_id IN NUMBER, v_cost_per_ticket IN OUT NUMBER);". This is the correct syntax for adding a procedure to the package specification. It includes the procedure name, the input and output parameters, and their data types.
20.
Examine this code:
BEGIN
theater_pck.v_total_seats_sold_overall := theater_pck.get_total_for_year;
END;
For this code to be successful, what must be true?
Correct Answer
D. Both the V_TOTAL_SEATS_SOLD_OVERALL variable and the GET_TOTAL_FOR_YEAR function must
exist in the specification of the THEATER_PCK package.
Explanation
For the code to be successful, both the V_TOTAL_SEATS_SOLD_OVERALL variable and the GET_TOTAL_FOR_YEAR function must exist in the specification of the THEATER_PCK package. This means that both the variable and the function must be declared and defined in the package specification, allowing them to be accessed and used in the code. If either the variable or the function is missing from the package specification, the code will not be able to compile and execute successfully.
21.
Examine this package specification and body:
CREATE OR REPLACE PACKAGE theater_pck
IS
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER);
END theater_pck;
CREATE OR REPLACE PACKAGE BODY theater_pck
IS
current_avg_cost_per_ticket NUMBER;
PROCEDURE find_seats_sold
(v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER)
IS
v_seats_sold gross_receipt.seats_sold%TYPE;
v_budget studio.yearly_budget%TYPE;
BEGIN
SELECT seats_sold
INTO v_seats_sold
FROM gross_receipt
WHERE movie_id = v_movie_id
AND theater_id = v_theater_id;
END find_seats_sold;
FUNCTION get_budget
(v_studio_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
END get_budget;
END theater_pck;
Which type of variable is CURRENT_AVG_COST_PER_TICKET?
Correct Answer
B. Private
Explanation
In the given package body, the variable CURRENT_AVG_COST_PER_TICKET is declared before the PROCEDURE find_seats_sold. It is not declared within any procedure or function, making it a private variable. Private variables can only be accessed within the package body and are not visible to other packages or outside the package.
22.
Procedures and functions are explicitly executed. This is different from a database trigger. When is a database trigger executed?
Correct Answer
B. During a data manipulation statement
Explanation
A database trigger is executed during a data manipulation statement. This means that whenever a specific action, such as an insert, update, or delete, is performed on the data in a table, the trigger associated with that table will be automatically executed. The trigger can be used to perform additional actions or enforce certain rules before or after the data manipulation statement is executed.
23.
Examine this trigger:
CREATE OR REPLACE TRIGGER audit_gross_receipt
AFTER DELETE OR UPDATE OF seats_sold, cost_per_ticket ON gross_receipt
BEGIN
...
END;
How many times will the trigger body execute upon invocation?
Correct Answer
A. Once
Explanation
The trigger body will execute once upon invocation. This is because the trigger is defined as an "AFTER" trigger, which means it will only execute after the specified event (in this case, a delete or update of seats_sold or cost_per_ticket on the gross_receipt table) has occurred. Therefore, regardless of the number of rows affected by the delete or update statement, the trigger body will only execute once.
24.
When a database trigger routine does not have to take place before the triggering event, which timing should you assign to the trigger?
Correct Answer
C. After
Explanation
When a database trigger routine does not have to take place before the triggering event, the timing that should be assigned to the trigger is "after". This means that the trigger will be executed after the triggering event has occurred.
25.
Modifications to the THEATER table are not allowed during the last week in December. When creating a database trigger to enforce this rule, which timing will you use to be most efficient?
Correct Answer
C. Before
Explanation
Using the "before" timing for the trigger will be most efficient in enforcing the rule that modifications to the THEATER table are not allowed during the last week in December. This is because the "before" timing allows the trigger to be executed before the modification takes place, effectively preventing any modifications from occurring during the specified time period. By using the "before" timing, the trigger can quickly and efficiently check the date and prevent any unauthorized modifications, saving resources and ensuring that the rule is enforced effectively.
26.
CREATE OR REPLACE TRIGGER update_studio
BEFORE UPDATE OF yearly_budget ON STUDIO
FOR EACH ROW
BEGIN
...
END;
Which event will invoke this trigger?
Correct Answer
B. YEARLY_BUDGET column update
Explanation
This trigger will be invoked when there is an update specifically on the "YEARLY_BUDGET" column of the "STUDIO" table. It will not be triggered by any other column updates or by insert, update, or delete operations on the "STUDIO" table.
27.
Examine this database trigger:
CREATE OR REPLACE TRIGGER audit_gross_modification
AFTER INSERT OR DELETE ON gross_receipt
BEGIN
INSERT INTO audit_gross
VALUES (USER, SYSDATE);
END;
To test this trigger, you delete 30 rows from the GROSS_RECEIPT table. How many rows are inserted into the AUDIT_GROSS table due to this event?
Correct Answer
A. 1
Explanation
When the trigger is fired after deleting 30 rows from the GROSS_RECEIPT table, only one row is inserted into the AUDIT_GROSS table. This is because the trigger is designed to insert a single row into the AUDIT_GROSS table every time it is fired, regardless of the number of rows affected by the DELETE statement. Therefore, regardless of the number of rows deleted, only one row will be inserted into the AUDIT_GROSS table.
28.
The auditing utility in Oracle records the type of data manipulation operation and not the actual changed values. To enhance auditing by capturing the new and old values, you create which type of trigger?
Correct Answer
A. Row only
Explanation
To enhance auditing by capturing the new and old values, you create a "row only" trigger. This type of trigger is specifically designed to capture the changes made to individual rows in a table. It allows you to track the old and new values of the modified data, providing more detailed information for auditing purposes. By using a "row only" trigger, you can ensure that the actual changed values are recorded along with the type of data manipulation operation.
29.
For which trigger timing can you reference the NEW and OLD qualifiers?
Correct Answer
A. Row only
Explanation
The NEW and OLD qualifiers can be referenced for the "row only" trigger timing. This means that the qualifiers can be used when a trigger is fired for each row affected by a DML statement. In this case, the trigger can access the old and new values of the affected row.
30.
Examine this trigger:
CREATE OR REPLACE TRIGGER budget_trig
AFTER INSERT ON studio
FOR EACH ROW
DECLARE
v_sum NUMBER;
BEGIN
SELECT sum(yearly_budget)
INTO v_sum
FROM studio;
UPDATE parent_company
SET overall_budget = v_sum;
END;
You insert a row into the STUDIO table and receive this message:
ORA-04091: table SCOTT.STUDIO is mutating, trigger/function may not see it
How do you correct this error?
Correct Answer
D. Convert it to a statement level database trigger by removing FOR EACH ROW.
Explanation
The error message "ORA-04091: table SCOTT.STUDIO is mutating, trigger/function may not see it" indicates that the trigger is trying to access the table it is defined on (STUDIO) while it is still being modified. To correct this error, the trigger should be converted to a statement level trigger by removing the "FOR EACH ROW" clause. This change ensures that the trigger operates on the entire statement rather than individual rows, avoiding the mutation error.
31.
Examine this database trigger:
CREATE OR REPLACE TRIGGER update_show_gross
{additional trigger information}
BEGIN
{additional code}
END;
This trigger should execute for each row when the SEATS_SOLD or COST_PER_TICKET columns are updated and when a row is inserted into the GROSS_RECEIPT table. Which trigger information must you add?
Correct Answer
D. BEFORE INSERT OR UPDATE OF seats_sold, cost_per_ticket ON gross_receipt
FOR EACH ROW
Explanation
The trigger should execute for each row when the SEATS_SOLD or COST_PER_TICKET columns are updated and when a row is inserted into the GROSS_RECEIPT table. Therefore, the trigger information must specify that the trigger should be executed before an insert or update operation on the SEATS_SOLD and COST_PER_TICKET columns of the GROSS_RECEIPT table. Additionally, the trigger should be executed for each row affected by the insert or update operation.
32.
Each month a SQL*Loader application is executed to insert approximately 1 million rows into the
GROSS_RECEIPT table. This table has three database triggers that execute for each row inserted. Which command can you issue immediately before the SQL*Loader operation to improve performance?
Correct Answer
D. ALTER TABLE gross_receipt DISABLE ALL TRIGGERS;
Explanation
Disabling all triggers on the "gross_receipt" table using the "ALTER TABLE" command can improve performance during the SQL*Loader operation. By disabling the triggers, the database will not have to execute them for each row inserted, which can reduce the overall processing time and improve performance. This allows the SQL*Loader application to insert the rows more efficiently into the table.
33.
The CHECK_THEATER trigger of the THEATER table has been disabled. Which command can you issue to enable this trigger?
Correct Answer
C. ALTER TRIGGER check_theater ENABLE;
Explanation
The correct command to enable a trigger in this scenario is "ALTER TRIGGER check_theater ENABLE;". This command specifically enables the "check_theater" trigger on the table. The other options are not valid commands for enabling a trigger.
34.
The AUDIT_THEATER trigger on the THEATER table is no longer needed and must be removed. Which command will successfully remove this trigger from the database?
Correct Answer
B. DROP TRIGGER audit_theater;
Explanation
The correct answer is "DROP TRIGGER audit_theater;". This command is used to remove a trigger from the database. The "DROP" keyword is used to indicate that the trigger is being dropped, and "audit_theater" specifies the name of the trigger that needs to be removed.
35.
Due to a disk failure, the AUDIT_THEATER table is unavailable until further notice. The CHECK_THEATER
database trigger references this table when a DML operation is performed on the THEATER table. Which command should you issue to prevent this database trigger from executing until this problem is resolved?
Correct Answer
C. ALTER TRIGGER check_theater DISABLE;
Explanation
The correct answer is "ALTER TRIGGER check_theater DISABLE." This command will disable the "check_theater" trigger, preventing it from executing until the problem with the AUDIT_THEATER table is resolved.
36.
You created a database trigger that will be executed for all data manipulation statements on the THEATER table. Within the code, you will determine which type of manipulation has caused the trigger to execute. Which
would you use to test for the type of manipulation being performed?
Correct Answer
D. DELETING, UPDATING, and INSERTING
Explanation
To test for the type of manipulation being performed, you would use "DELETING, UPDATING, and INSERTING". These are the options that represent the different types of data manipulation statements that can be executed on the THEATER table. By checking which type of manipulation is being performed, you can determine the appropriate action to take within the trigger code.
37.
You created a database trigger that will be executed for all data manipulation statements on the THEATER
table. Within the code, you will determine which type of manipulation has caused the trigger to execute. Which
would you use to test for the type of manipulation being performed?
Correct Answer
C. BEFORE DELETE OR INSERT OR UPDATE ON gross_receipt
Explanation
The correct answer is "BEFORE DELETE OR INSERT OR UPDATE ON gross_receipt". This is the correct syntax for creating a trigger that will be executed before any delete, insert, or update operation is performed on the gross_receipt table. The "BEFORE" keyword indicates that the trigger will be executed before the operation takes place, and the "DELETE OR INSERT OR UPDATE" keywords specify the types of operations that will trigger the execution of the trigger. The "ON gross_receipt" specifies the table on which the trigger will be applied.
38.
You created a database trigger that will be executed for all data manipulation statements on the THEATER
table. Within the code, you will determine which type of manipulation has caused the trigger to execute. Which
would you use to test for the type of manipulation being performed?
Correct Answer
D. DELETING, UPDATING, and INSERTING
Explanation
To test for the type of manipulation being performed, you would use the options DELETING, UPDATING, and INSERTING. These options represent the different types of data manipulation statements that can be executed on the THEATER table. By checking which of these options is true within the trigger code, you can determine the type of manipulation that caused the trigger to execute.
39.
Examine this function:
CREATE OR REPLACE FUNCTION set_budget
(v_studio_id IN NUMBER, v_new_budget IN NUMBER)
RETURN BOOLEAN
IS
BEGIN
UPDATE studio
SET yearly_budget = v_new_budget
WHERE id = v_studio_id;
IF SQL%FOUND THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
COMMIT;
END;
Which code will successfully invoke this function?
Correct Answer
D. DECLARE
v_updated_flag BOOLEAN;
BEGIN
v_updated_flag := set_budget(11,500000000);
END;
Explanation
The correct answer is the DECLARE block because it declares a variable v_updated_flag of type BOOLEAN and assigns the result of the set_budget function to it. This allows the function to be invoked and the result to be stored in the variable for further use.
40.
Examine this function:
CREATE OR REPLACE FUNCTION get_budget
(v_studio_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
END;
Which set of statements will successfully invoke this function within SQL*Plus?
Correct Answer
C. VARIABLE g_yearly_budget NUMBER
EXECUTE :g_yearly_budget := GET_BUDGET(11);
Explanation
The correct set of statements to successfully invoke the function within SQL*Plus is to declare a variable "g_yearly_budget" of type NUMBER using the "VARIABLE" command, and then use the "EXECUTE" command to assign the result of the function call "GET_BUDGET(11)" to the variable ":g_yearly_budget".
41.
Examine this function:
CREATE OR REPLACE FUNCTION get_budget
(v_studio_id IN NUMBER, v_max_budget IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
IF v_yearly_budget > v_max_budget THEN
RETURN v_max_budget;
ELSE
RETURN v_yearly_budget;
END IF;
END;
Which set of statements will successfully invoke this function within SQL*Plus?
Correct Answer
A. SELECT id, name, get_budget(id,200)
FROM studio;
Explanation
The correct answer is the first option. This is because it correctly invokes the function "get_budget" within the SQL query by passing the "id" column from the "studio" table as the first argument and the value 200 as the second argument. It retrieves the "id" and "name" columns from the "studio" table and also includes the result of the "get_budget" function in the output.
42.
For which purpose are formal parameters used when creating functions?
Correct Answer
B. Passing values to the function
Explanation
Formal parameters are used when creating functions to pass values to the function. These parameters act as placeholders for the values that will be provided when the function is called. By passing values to the function through formal parameters, the function can perform operations on these values and return a result or perform a specific task based on the provided values. This allows for the reuse and flexibility of functions, as different values can be passed to achieve different outcomes.
43.
A stored function can be invoked in many different ways. Which invocation example is NOT valid?
Correct Answer
D. Executing the stored function within a CHECK constraint of a table
44.
How do functions simplify maintainability?
Correct Answer
A. By limiting changes to logic to one location
Explanation
Functions simplify maintainability by limiting changes to logic to one location. This means that if there is a change needed in the logic of a function, it only needs to be made in that one location. This reduces the chances of introducing errors or inconsistencies, as the logic is centralized and can be easily managed. It also makes it easier to understand and debug the code, as the logic is contained within a specific function. By limiting changes to one location, functions promote modularity and encapsulation, making the code easier to maintain and update.
45.
A stored function can be invoked in many different ways. Which invocation example is NOT valid?
Correct Answer
D. Executing the stored function within the DEFAULT clause of the CREATE TABLE statement
46.
Examine this statement:
SELECT id, theater_pck.get_budget(id)
FROM studio;
What must be true about the GET_BUDGET function for this statement to be successful?
Correct Answer
B. It must not modify the database.
Explanation
The statement is selecting the ID and the budget of a theater from the studio table. In order for this statement to be successful, the GET_BUDGET function must not modify the database. This means that the function should only retrieve data and not make any changes to the underlying database.
47.
Examine this function:
CREATE OR REPLACE FUNCTION get_budget
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
END;
What additional code is needed to compile this function successfully?
Correct Answer
D. Add "(v_studio_id IN NUMBER)" right before the RETURN statement of the header.
Explanation
To compile the given function successfully, the additional code needed is to add "(v_studio_id IN NUMBER)" right before the RETURN statement of the header. This is necessary because the function is using the variable v_studio_id in the SELECT statement, but it is not declared in the function header. By adding this parameter in the header, the function will be able to compile and execute correctly.
48.
Which code successfully calculates commission returning it to the calling environment?
Correct Answer
D. CREATE OR REPLACE FUNCTION calc_comm
(v_emp_id IN NUMBER)
RETURN number
IS
v_total NUMBER;
BEGIN
SELECT SUM(ord.total)
INTO v_total
FROM ord,customer
WHERE ord.custid = customer.custid
AND customer.repid = v_emp_id;
RETURN (v_total * .20);
END;
Explanation
The correct answer is the third option: CREATE OR REPLACE FUNCTION calc_comm (v_emp_id IN NUMBER) IS RETURN number v_total NUMBER; BEGIN SELECT SUM(ord.total) INTO v_total FROM ord,customer WHERE ord.custid = customer.custid AND customer.repid = v_emp_id; RETURN (v_total * .20); END;
This option successfully calculates the commission by selecting the sum of the total orders for a specific employee ID and multiplying it by 0.20. It also includes the necessary syntax for creating a function in Oracle PL/SQL.
49.
You have just created a PL/SQL user-defined function called CALC_COMM. Which statement will successfully test it?
Correct Answer
D. SELECT *
FROM ord
GROUP BY ordid
HAVING calc_comm(total) > 5000;
Explanation
The correct answer is "SELECT * FROM ord GROUP BY ordid HAVING calc_comm(total) > 5000;". This statement will successfully test the PL/SQL user-defined function CALC_COMM. It selects all rows from the ORD table, groups them by the ORDID column, and then applies the CALC_COMM function to the TOTAL column. It filters out the rows where the result of the CALC_COMM function is greater than 5000. This statement ensures that the function is being used correctly and returns the desired results.
50.
Which subprogram type can be invoked from within a SQL statement?
Correct Answer
A. Function
Explanation
A function can be invoked from within a SQL statement. Functions are subprograms that can be called within SQL statements to perform a specific task and return a value. They can be used to manipulate data, perform calculations, or retrieve specific information from the database. Unlike procedures, functions always return a value and can be used in expressions or as part of a query. Therefore, a function is the correct subprogram type that can be invoked from within a SQL statement.