PL/SQL

Which of the following is a good reason to use two cursors in a single PL/SQL block?
It is the only way to declare a cursor with a parameter
When two tables are related to each other (often by a foreign key) and we want to produce a multilevel report using data from both tables
To speed up the execution of the PL/SQL block
To allow one cursor to be opened twice at the same time
To allow one cursor to be opened twice at the same tim
N the following example, what statement belongs in Line A? ALTER SESSION SET PLSQL_CCFLAGS = ‘debug:true’; CREATE OR REPLACE PROCEDURE testproc IS BEGIN … $IF $$debug $THEN DBMS_OUTPUT.PUT_LINE(‘This code was executed’); — Line A … END testproc; ALTER SESSION SET PLSQL_CCFLAGS = ‘debug:false’;
$ENDIF
$$END;
$END (*)
$ELSIF
$END;
Which of the following statements is true?
PL/SQL is an Oracle proprietary, procedural, 3GL programming language.
PL/SQL is an Oracle proprietary, procedural, 4GL programming language.
PL/SQL is an Oracle proprietary, nonprocedural, 3GL programming language.
PL/SQL is an ANSI-compliant, procedural programming language.
Nquiry directives are used to selectively include or exclude PL/SQL code based on values of pre-defined variables that are set using the PLSQL_CCFLAGS parameter.
True
False
What is wrong with this assignment statement? myvar := 'To be or not to be'; 'That is the question';
An assignment statement must be a single line of code
Nothing is wrong, the statement is fin
An assignment statement must have a single semicolon at the end
"myvar" is not a valid name for a variable
Character literals should not be enclosed in quotes
DECLARE v_age1 NUMBER(3); v_age2 NUMBER(3); v_message VARCHAR2(20); BEGIN CASE WHEN v_age1 = v_age2 THEN v_message := 'Equal'; WHEN v_age1 <> v_age2 THEN v_message := 'Unequal'; ELSE v_message := 'Undefined'; END CASE; DBMS_OUTPUT.PUT_LINE(v_message); END;
Equal
Undefined
Unequal
Nothing will be displayed because V_MESSAGE is set to NULL.
What would you code at Line A?
OPEN country_cur (p_region_id);
OPEN country_cur (wf_world_regions.region_id);
OPEN country_cur (v_region_rec.region_id)
OPEN country_cur (region_cur.region_id);
OPEN country_cur;
What kind of block is defined by the following PL/SQL code? BEGIN DBMS_OUTPUT.PUT_LINE('My first quiz'); END;
Procedure
subroutine
function
anonymous
You have declared a cursor as follows: CURSOR loc_curs IS SELECT * FROM locations; How should you code a FOR loop to use this cursor?
FOR loc_rec IN loc_curs LOOP
WHILE loc_rec IN loc_curs LOOP
IF loc_rec IN loc_curs LOOP
FOR loc_rec IN 1 .. loc_curs%ROWCOUNT LOOP
FOR loc_curs IN loc_rec LOOP
What will happen when the following procedure is called as format_phone(8005551234)?CREATE OR REPLACE PROCEDURE format_phone(p_phone_no IN OUT VARCHAR2) ISBEGINp_phone_no := SUBSTR(p_phone_no,1,3) ||'.' || SUBSTR(p_phone_no,4,3) ||'.' || SUBSTR(p_phone_no,7);END format_phone;
The phone number 800.555.1234 is printed to the screen
The phone number (800) 555-1234 is printed to the screen
The phone number 800.555.1234 is placed into the p_phone_no variable
The procedure does not execute because the input variable is not properlydeclared
Why is it better to use DBMS_OUTPUT only in anonymous blocks, not inside stored subprograms such as procedures?
Because DBMS_OUTPUT cannot be used inside procedures
Because anonymous blocks display messages while the block is executing, while procedures do not display anything until their execution has finished
Because DBMS_OUTPUT should be used only for testing and debugging PL/SQL code
Because DBMS_OUTPUT can raise a NO_DATA_FOUND exception if used inside a packaged procedure
Which of the following will display the number of invalid package bodies in your schema?
SELECT COUNT(*) FROM user_objects WHERE object_type = ‘PACKAGE BODY’ AND status = ‘INVALID’;
SELECT COUNT(*) FROM user_dependencies WHERE type = ‘PACKAGE BODY’ AND status = ‘INVALID’;
SELECT COUNT(*) FROM user_packages WHERE status = ‘INVALID’;
SELECT COUNT(*) FROM user_objects WHERE object_type LIKE ‘PACKAGE%’ AND status = ‘INVALID’;
You can create a trigger which prevents DDL statements on an individual table, while still allowing DDL on other tables in the same schema.
True
False
Which of the following can be done using PL/SQL
Create complex applications
Retrieve and modify data in Oracle database tables
Manage database tasks such as security.
Create custom reports
All of the above (*)
Look at the following code:DECLARECURSOR emp_cursor IS SELECT * FROM employees;BEGINFOR emp_record IN emp_cursor LOOPDBMS_OUTPUT.PUT_LINE( --Point A -- );END LOOP;END; To display the salary of an employee, what code should you write at Point A?
Emp_record.salary
Emp_cursor.salary
Employees.salary
Emp_record.employees.salary
TO_CHAR(salary)
Which data dictionary view allows you to see the setting for PLSQL_OPTIMIZE_LEVEL?
USER_PLSQL_OBJECTS
USER_PLSQL_OPTIMIZE
USER_PLSQL_OBJECT_SETTINGS
USER_OUSER_PLSQL_CODE_TYPEBJECT_SETTINGS
USER_OBJECT_SETTINGS
Which of the following will delete all employees who work in the Sales department?
DELETE FROM employees WHERE department_id = SELECT department_id FROM departments WHERE department_name = 'Sales';
DELETE FROM employees WHERE department_id = (SELECT department_id FROM departments WHERE department_name = 'Sales');
DELETE (SELECT department_id FROM departments WHERE department_name = 'Sales') FROM employees;
DELETE FROM employees e, departments d WHERE e.department_id = d.department_id AND department_name = 'Sales';
Variables can be assigned a value in both the Executable and Declaration sections of a PL/SQL program. True or False?
True
False
When creating a procedure, where in the code must the parameters be listed?
After the procedure name.
After the keyword IS or AS.
Before the procedure name.
After the keyword PROCEDURE.
What type of database object would you create to write an auditing record automatically every time a user connects to the database?
A complex view
A trigger
A function
A procedure
A package
Examine the following code. What is the scope of variable v_myvar? DECLARE v_myvar NUMBER; BEGIN v_myvar := 6; DECLARE v_hervar NUMBER; BEGIN v_hervar := 4; END; END;
Only the outer block
Both the inner and the outer block
Only the inner block
Neither block
Which of the following statements about a package initialization block is true?
It cannot contain any SQL statements.
It is an anonymous block at the end of a package body
It is a procedure in a package that must be invoked before the rest of the package can be used.
It is an anonymous block in the package specification.
It is executed automatically every time any global variable in the package is referenced.
You want to calculate and display the multiplication table for "sevens": 7x1=7, 7x2=14, 7x3=21 and so on. Which kind of PL/SQL construct is best for this?
A loop
A CASE statement
IF ... END IF;
A Boolean variable.
You want to create a function which drops a table. You write the following code: CREATE OR REPLACE FUNCTION droptab (p_tab_name IN VARCHAR2) RETURN BOOLEAN IS BEGIN DROP TABLE p_tab_name; RETURN TRUE; EXCEPTION WHEN OTHERS THEN RETURN FALSE; END; Why will this procedure not compile successfully?
Because you cannot use RETURN in the exception section
Because the PL/SQL compiler cannot check if the argument of p_tab_name is a valid table-name
Because you can never drop a table from inside a function
Because you do not have the privilege needed to drop a table
In an INDEX BY table of records the record can be______
%ROWTYPE
Either one.
A user-defined record
Which of the following is a PL/SQL programming environment?
Oracle Cdeveloper
Java*Plus
PL/SQL Express
SQL*Workshop in Application Express
Which of the following database objects are created when the utldtree.sql script is run?
The utldtree table
The deptree_temptab table
The deptree and ideptree views
The deptree_fill procedure
The deptree table
The following table has been created: CREATE TABLE student_table (stud_id NUMBER(6), last_name VARCHAR2(20), first_name VARCHAR2(20), lunch_num NUMBER(4)); Which one of the following INSERT statements will fail?
NSERT INTO student_table (stud_id, last_name, lunch_num) VALUES (143354, 'Roberts', 6543, 'Cameron');
INSERT INTO student_table VALUES (143354, 'Roberts', 'Cameron', 6543);
INSERT INTO student_table (stud_id, last_name, first_name, lunch_num) VALUES (143354, 'Roberts', 'Cameron', 6543);
INSERT INTO student_table (stud_id, lunch_num, first_name, last_name) VALUES (143352, 6543, 'Cameron', 'Roberts');
Package NEWPACK contains several procedures and functions, including private function PRIVFUNC. From where can PRIVFUNC be invoked? (Choose two.)
From an anonymous block
From any procedure in NEWPACK
From any private function in another package
From any function in NEWPACK
From any public procedure in another package
A DML statement trigger fires only once for each triggering DML statement, while a row trigger fires once for each row processed by the triggering statement. True or False?
True
False
Which PL/SQL warning message identifies code that can cause unexpected behavior or wrong results when executed?
INFORMATIONAL
PERFORMANCE
ALL
SEVERE
ERROR
Package emp_pack contains two public procedures: get_emps and upd_emps. A separate procedure emp_proc invokes emp.pack.get_emps. The upd_emps package body code is now altered, and the package body (but not the package specification) is recreated. emp_proc will be marked invalid and needs to be recompiled. True or False?
True
False
You can use a database trigger to prevent invalid transactions from being committed. True or False?
True
False
Package OLDPACK is in your schema. What will happen when the following statement is executed? DROP PACKAGE oldpack;
The body will be dropped but the specification will be retained.
The specification will be dropped but the body will be retained.
Both the specification and the body will be dropped
The statement will fail because you must drop the body before you can drop the specification
A warning in PL/SQL is the same as an error in PL/SQL, but can only be viewed through the USER_ERRORS data dictionary view. True or False?
True
False
What value will v_answer contain after the following code is executed? DECLARE v_age NUMBER:= 18; v_answer VARCHAR2(10); BEGIN v_answer := CASE WHEN v_age < 25 THEN 'Young' WHEN v_age = 18 THEN 'Exactly 18' ELSE 'Older' END CASE; END;
Exactly 18
Young
Null
Older
In the following example, where do you place the phrase BULK COLLECT? … BEGIN SELECT — Position A salary — Position B INTO v_saltab — Position C FROM employees WHERE department_id = 20 ORDER BY salary — Position D ;
Position A
Position B
Position C
Position D
You have declared a cursor as follows: CURSOR loc_curs IS SELECT * FROM locations; How should you code a FOR loop to use this cursor?
FOR loc_rec IN loc_curs LOOP
WHILE loc_rec IN loc_curs LOOP
IF loc_rec IN loc_curs LOOP
FOR loc_rec IN 1 .. loc_curs%ROWCOUNT LOOP
FOR loc_curs IN loc_rec LOOP
The DBMS_OUTPUT package is useful for which of the following activities? (Choose two)
Interact with a user during execution of a function or procedure
Display results to the developer during testing for debugging purposes
Trace the code execution path for a function or procedure
Write operating system text files to the user’s screen
Which of the following are NOT allowed within a database trigger?
COMMIT
A call to a packaged procedure
INSERT
A Boolean variable
SAVEPOINT
What is wrong with the following code? CREATE OR REPLACE TRIGGER emp_dept_trigg BEFORE UPDATE OR DELETE ON employees, departments BEGIN
DML triggers must be row triggers, so FOR EACH ROW is missing
The second line should be: BEFORE UPDATE OR DELETE ON employees OR departments
The second line should be: BEFORE (UPDATE,DELETE) ON employees, departments
One trigger can be associated with only one table
Which of the following statements about implicit conversions is NOT true?
Code containing implicit conversions typically runs faster than code containing explicit conversions.
Code containing implicit conversions may not work in the future if Oracle changes the conversion rules.
Code containing implicit conversions is harder to read and understand.
Examine the following code: DECLARE CURSOR region_cur IS SELECT * FROM wf_world_regions; v_region_rec region_cur%ROWTYPE; CURSOR country_cur (p_region_id NUMBER) IS SELECT * FROM wf_countries WHERE region_id = p_region_id; v_country_rec country_cur%ROWTYPE; BEGIN OPEN region_cur; LOOP FETCH region_cur INTO v_region_rec; EXIT WHEN region_cur%NOTFOUND; DBMS_OUTPUT.PUT_LINE (v_region_rec.region_name); -- Line A -- LOOP FETCH country_cur INTO v_country_rec; EXIT WHEN country_cur%NOTFOUND; ...... What would you code at Line A?
OPEN country_cur (p_region_id);
OPEN country_cur (wf_world_regions.region_id);
OPEN country_cur (v_region_rec.region_id);
OPEN country_cur (region_cur.region_id);
OPEN country_cur;
Which of the following keywords MUST be included in every PL/SQL procedure definition? (Choose three.) (Choose all correct answers)
REPLACE
BEGIN
IS or AS
DECLARE
END
Which of the following statements is true?
PL/SQL is an Oracle proprietary, procedural, fourth-generation programming language.
PL/SQL is an ANSI-compliant, procedural programming language.
SQL is an ANSI-compliant, nonprocedural, fourth-generation programming language.
PL/SQL is an Oracle proprietary, procedural, third-generation programming language
There are three employees in department 90. What will be displayed when this code is executed? DECLARE v_last_name employees.last_name%TYPE; BEGIN DBMS_OUTPUT.PUT_LINE(‘Message 1’); BEGIN SELECT last_name INTO v_last_name FROM employees WHERE department_id = 90; DBMS_OUTPUT.PUT_LINE(‘Message 2’); END; DBMS_OUTPUT.PUT_LINE(‘Message 3’); EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(‘Message 4’); END;
Message 1 Message 3 Message 4
Message 1 Message 4
Message 1
An unhandled exception will be propagated back to the calling environment.
None of the above
A trigger can be a public subprogram within a PL/SQL package. True or False?
True
False
What will be displayed when the following block is executed? DECLARE v_age NUMBER(3); v_gender VARCHAR2(6) := 'Female'; v_status VARCHAR2(20); BEGIN CASE WHEN v_age >= 18 AND v_gender = 'Male' THEN v_status := 'Adult Male'; WHEN v_age >= 18 AND v_gender = 'Female' THEN v_status := 'Adult Female'; WHEN v_age < 18 AND v_gender = 'Male' THEN v_status := 'Junior Male'; WHEN v_age < 18 AND v_gender = 'Female' THEN v_status := 'Junior Female'; ELSE v_status := 'Other Value'; END CASE; DBMS_OUTPUT.PUT_LINE(v_status); END;
Adult Male
Junior Female
Other Value
Nothing will be displayed because V_STATUS is set to NULL.
While editing a document in Microsoft Word, you go to the FILE menu and SAVE your work. To do this, Microsoft Word has executed an application trigger. True or False?
True
False
An INDEX BY TABLE primary key cannot be negative.
True
False
Which good programming practice guideline would make this code easier to read? DECLARE v_sal NUMBER(8,2); BEGIN SELECT salary INTO v_sal FROM employees WHERE employee_id = 100; UPDATE employees SET salary = v_sal; END;
Declaring variables using %TYPE
Indenting each level of code
Avoiding implicit data type conversions
Using a consistent naming convention for variables
What is wrong with the following trivial IF statement: IF (v_job=’President’) THEN v_salary := 10000;
IF and THEN must be on the same line: IF (v_job=’President’) THEN
The condition should be coded: IF (v_job := ‘President’)
END IF; is missing
ELSE is missing
{"name":"PL\/SQL", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"Which of the following is a good reason to use two cursors in a single PL\/SQL block?, n the following example, what statement belongs in Line A? ALTER SESSION SET PLSQL_CCFLAGS = ‘debug:true’; CREATE OR REPLACE PROCEDURE testproc IS BEGIN … $IF $$debug $THEN DBMS_OUTPUT.PUT_LINE(‘This code was executed’); — Line A … END testproc; ALTER SESSION SET PLSQL_CCFLAGS = ‘debug:false’;, Which of the following statements is true?","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}
Make your own Survey
- it's free to start.