Section 8

Test: Quiz: Creating Procedures Review your answers, feedback, and question scores below. An asterisk (*) indicates a co

Views 1,544 Downloads 37 File size 7MB

Report DMCA / Copyright

DOWNLOAD FILE

Recommend stories

Citation preview

Test: Quiz: Creating Procedures Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 (Answer all questions in this section) 1. Which of the following are characteristics of anonymous PL/SQL blocks but not PL/SQL subprograms? (Choose three.)

Mark for Review (1) Points

(Choose all correct answers) Can take parameters Are stored in the database Can begin with the keyword DECLARE (*) Are unnamed (*) Are compiled every time they are executed (*) Correct 2. Which of the following keywords MUST be included in every PL/SQL procedure definition? (Choose two.)

Mark for Review (1) Points

(Choose all correct answers) BEGIN (*) REPLACE EXCEPTION DECLARE END (*) Correct 3. PL/SQL subprograms, unlike anonymous blocks, are compiled each time they are executed. True or False?

Mark for Review (1) Points

True False (*) Correct 4. Which of the following are benefits of using PL/SQL subprograms rather than anonymous blocks? (Choose three.) (Choose all correct answers) Better data security (*) Code reuse (*) Stored externally Easier code maintenance (*)

Mark for Review (1) Points

Do not need to define exceptions Correct 5. A stored procedure add_dept may be invoked by the following command in Application Express. True or False?

Mark for Review (1) Points

BEGIN add_dept; END; True (*) False Correct 6. The following are the steps involved in creating, and later modifying and re-creating, a PL/SQL procedure in Application Express. Which step is missing?

1. 2. 3. 4. 5.

Mark for Review (1) Points

Type the procedure code in the SQL Commands window Click on the "Save" button and save the procedure code Retrieve the saved code from "Saved SQL" in SQL Commands Modify the code in the SQL Commands window Execute the code to re-create the procedure

Enter parameters and data type Exe ute the procedure from USRE_SOURCE data dictionary view Execute the code to create the procedure (*) Invoke the procedure from an anonymous block Correct 7. Subprograms and anonymous blocks can be called by other applications. True or False?

Mark for Review (1) Points

True False (*) Correct 8. Procedures are generally used to perform what?

A SELECT statement An action (*) A return of values All of the above None of the above Correct

Mark for Review (1) Points

9. When modifying procedure code, the procedure code statement must be re-executed to validate and store it in the database. True or False?

Mark for Review (1) Points

True False (*) Correct 10. A programmer wants to create a PL/SQL procedure named MY_PROC. What will happen when the following code is executed?

Mark for Review (1) Points

CREATE OR REPLACE PROCEDURE my_proc IS v_empid employees.empid%TYPE; BEGIN SELECT employee_id INTO v_empid FROM employees WHERE region_id = 999; DBMS_OUTPUT.PUT_LINE('The salary is: ' || v_salary); The statement will raise a NO_DATA_FOUND exception because region_id 999 does not exist. The statement will fail because the last line of code should be END my_proc; (*) The statement will fail because you cannot declare variables such as v_empid inside a procedure. Correct 11. A nested subprogram can be called from the main procedure or from the calling environment. True or False?

Mark for Review (1) Points

True False (*) Correct 12. Why will the following procedure fail? CREATE OR REPLACE PROCEDURE mainproc ... IS PROCEDURE subproc (...) IS BEGIN ... BEGIN ... subproc (...); ... END; Procedure main proc must use the keyword AS not IS Procedure mainproc does not need the keyword BEGIN Procedure subproc does not need the keyword BEGIN Procedure subproc does not have an END; statement (*) Correct

Mark for Review (1) Points

13. A stored PL/SQL procedure can be invoked from which of the following?

1. 2. 3. 4.

A PL/SQL anonymous block A calling application A SELECT statement Another PL/SQL procedure

Mark for Review (1) Points

A only A and B A and C A, B and D (*) B and C Correct Test: Quiz: Using Parameters in Procedures Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 (Answer all questions in this section) 1. A procedure has been created as: CREATE PROCEDURE myproc (p_left NUMBER, p_right NUMBER) IS BEGIN ....

Mark for Review (1) Points

You want to call the procedure from an anonymous block. Which of the following calls is valid? myproc(p_left, p_right); myproc(v_left, v_right); myproc(v_left, 30); All of the above. (*) Incorrect. Refer to Section 8 Lesson 2. 2. Which of the following can be used as an argument for a procedure parameter?

The name of a variable. A literal value. An expression. All of the above. (*) None of the above. Correct

Mark for Review (1) Points

3. What is the correct syntax to create procedure MYPROC that accepts two number parameters X and Y?

Mark for Review (1) Points

CREATE PROCEDURE myproc (x NUMBER, y NUMBER) IS ... (*) CREATE PROCEDURE (x NUMBER, y NUMBER) myproc IS ... CREATE PROCEDURE myproc IS (x NUMBER, y NUMBER) ... CREATE PROCEDURE IS myproc (x NUMBER, y NUMBER) ナ Correct 4. What is the purpose of using parameters with stored procedures?

Mark for Review (1) Points

They prevent the procedure from modifying data in the database. They allow values to be passed between the calling environment and the procedure. (*) They count the number of exceptions raised by the procedure. They speed up the execution of the procedure. Correct 5. Which of the following best describes the difference between a parameter and an argument?

Mark for Review (1) Points

They are both names of variables. A parameter is passed into the procedure, while an argument is passed out of the procedure A parameter is the name of a variable, while an argument is the datatype of that variable A parameter is the name of a variable that is passed into or out of a procedure, while an argument is the value of that variable (*) There is no difference, parameters and arguments are the same thing Correct Test: Quiz: Passing Parameters Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 (Answer all questions in this section) 1. Three IN parameters for procedure ADD_EMPLOYEE are defined as: (p_name VARCHAR2 , p_salary NUMBER := 1000, p_hired DATE DEFAULT SYSDATE) The procedure is invoked by: add_employee('Jones'); What is the value of P_SALARY when the procedure starts to execute? NULL

Mark for Review (1) Points

1000 (*) The procedure will not compile because P_SALARY should have been coded as DEFAULT 1000 The call will fail because P_SALARY is a required parameter Correct 2. When creating a procedure, where in the code must the parameters be listed?

Mark for Review (1) Points

After the procedure name. (*) After the keyword IS or AS. Before the procedure name. After the keyword PROCEDURE. Correct 3. A procedure is invoked by this command: myproc('Smith',salary=>5000);

Mark for Review (1) Points

What is the method of passing parameters used here? Positional Named A combination of positional and named (*) None of the above Correct 4. Procedure NUMPROC has been created as: CREATE PROCEDURE numproc (x NUMBER, y NUMBER := 100, z NUMBER) IS BEGIN ....

Mark for Review (1) Points

You want to call the procedure, passing arguments of 10 for X and 20 for Z. Which one of the following calls is correct? numproc(10,,20); numproc(x=10,z=20); numproc(10,z=>20); (*) numproc(x=>10,20); Correct 5. Which of the following statements about IN OUT parameters is true? (Choose two.)

(Choose all correct answers)

Mark for Review (1) Points

The data type for the parameter must be VARCHAR2. The parameter value passed into the subprogram is always returned unchanged to the calling environment. The parameter value can be returned as the original unchanged value. (*) The parameter value can be returned as a new value that is set within the procedure. (*) Correct 6. A procedure is invoked by this command: myproc('Smith',100,5000);

Mark for Review (1) Points

What is the method of passing parameters used here? Positional (*) Named A combination of positional and named. None of the above Correct 7. What are the three parameter modes for procedures?

Mark for Review (1) Points

IN, OUT, IN OUT (*) R(ead), W(rite), A(ppend) CONSTANT, VARIABLE, DEFAULT COPY, NOCOPY, REF Correct 8. 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) IS BEGIN p_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 properly declared. Correct

Mark for Review (1) Points

9. If you don't specify a mode for a parameter, what is the default mode?

Mark for Review (1) Points

OUT IN (*) COPY DEFAULT R(ead) Correct 10. Which kind of parameters cannot have a DEFAULT value?

Mark for Review (1) Points

OUT (*) IN CONSTANT R(ead) W(rite) Correct 11. The following procedure has been created: CREATE OR REPLACE PROCEDURE myproc (p_p1 NUMBER, p_p2 VARCHAR2) IS BEGIN ... Which one of the following calls to the procedure will NOT work? myproc(80, 'Smith'); myproc(p_p1 => 80, 'Smith'); (*) myproc(80, p_p2 => 'Smith'); myproc(p_p1 => 80, p_p2 => 'Smith'); Correct

Mark for Review (1) Points