Oracle PL/SQL Stored Procedures and Functions

Test your knowledge of Oracle PL/SQL programming including stored procedures, functions, packages, cursors, and SQL*Plus commands

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which type of argument passes a value from a procedure to the calling environment?

  1. VARCHAR2
  2. BOOLEAN
  3. OUT
  4. IN
Question 2 Multiple Choice (Single Answer)

Examine this procedure: CREATE OR REPLACE PROCEDURE ADD_PLAYER (V_ID IN NUMBER, V_LAST_NAME VARCHAR2) IS BEGIN INSERT INTO PLAYER (ID,LAST_NAME) VALUES (V_ID, V_LAST_NAME); COMMIT; END; This procedure must invoke the APD_BAT_STAT procedure and pass a parameter. Which statement, when added to the above procedure will successfully invoke the UPD_BAT_STAT procedure?

  1. EXECUTE UPD_BAT_STAT(V_ID);
  2. UPD_BAT_STAT(V_ID);
  3. RUN UPD_BAT_STAT(V_ID);
  4. START UPD_BAT_STAT(V_ID);
Question 3 Multiple Choice (Single Answer)

When creating a function in SQL *Plus, you receive this message: .Warning: Function created with compilation errors.. Which command can you issue to see the actual error message?

  1. SHOW FUNCTION_ERROR
  2. SHOW USER_ERRORS
  3. SHOW ERRORS
  4. SHOW ALL_ERRORS
Question 4 Multiple Choice (Single Answer)

Examine this code: CREATE OR REPLACE FUNCTION gen_email_name (p_first_name VARCHAR2, p_last_name VARCHAR2, p_id NUMBER) RETURN VARCHAR2 is v_email_name VARCHAR2(19); BEGIN v_email_home := SUBSTR(p_first_name, 1, 1) || SUBSTR(p_last_name, 1, 7) || [email protected] .; UPDATE employees SET email = v_email_name WHERE employee_id = p_id; RETURN v_email_name; END; You run this SELECT statement: SELECT first_name, last_name gen_email_name(first_name, last_name, 108) EMAIL FROM employees; What occurs?

  1. Employee 108 has his email name updated based on the return result of the function.
  2. The statement fails because functions called from SQL expressions cannot perform DML.
  3. The statement fails because the functions does not contain code to end the transaction.
  4. The SQL statement executes successfully, because UPDATE and DELETE statements are ignoring in stored functions called from SQL expressions.
  5. The SQL statement executes successfully and control is passed to the calling environment.
Question 5 Multiple Choice (Single Answer)

Given a function CALCTAX : CREATE OR REPLACE FUNCTION calc tax (sal NUMBER) RETURN NUMBER IS BEGIN RETURN (sal * 0.05); END; If you want to run the above function from the SQL *Plus prompt, which statement is true?

  1. You need to execute the command CALCTAX(1000); .
  2. You need to execute the command EXECUTE FUNCTION calc tax; .
  3. You need to create a SQL *Plus environment variable X and issue the command :X := CALCTAX(1000); .
  4. You need to create a SQL *Plus environment variable X and issue the command EXECUTE :X := CALCTAX;
  5. You need to create a SQL *Plus environment variable X and issue the command EXECUTE :X := CALCTAX(1000);
Question 6 Multiple Choice (Single Answer)

Which statement is valid when removing procedures?

  1. Use a drop procedure statement to drop a standalone procedure.
  2. Use a drop procedure statement to drop a procedure that is part of a package. Then recompile the package specification.
  3. Use a drop procedure statement to drop a procedure that is part of a package. Then recompile the package body.
  4. For faster removal and re-creation, do not use a drop procedure statement. Instead, recompile the procedure using the alter procedure statement with the REUSE SETTINGS clause.
Question 7 Multiple Choice (Multiple Answers)

Examine this code: CREATE OR REPLACE PRODECURE add_dept (p_dept_name VARCHAR2 DEFAULT 'placeholder', p_location VARCHAR2 DEFAULT 'Boston') IS BEGIN INSERT INTO departments VALUES (dept_id_seq.NEXTVAL, p_dept_name, p_location); END add_dept; / Which three are valid calls to the add_dep procedure ? (Choose three)

  1. add_dept;
  2. add_dept( .Accounting .);
  3. add_dept(, .New York .);
  4. add_dept(p_location=> .New York .);
Question 8 Multiple Choice (Single Answer)

Examine this function: CREATE OR REPLACE FUNCTION CALC_PLAYER_AVG (V_ID in PLAYER_BAT_STAT.PLAYER_ID%TYPE) RETURN NUMBER IS V_AVG NUMBER; BEGIN SELECT HITS / AT_BATS INTO V_AVG FROM PLAYER_BAT_STAT WHERE PLAYER_ID = V_ID; RETURN (V_AVG); END; Which statement will successfully invoke this function in SQL *Plus?

  1. SELECT CALC_PLAYER_AVG(PLAYER_ID) FROM PLAYER_BAT_STAT;
  2. EXECUTE CALC_PLAYER_AVG (31);
  3. CALC_PLAYER (.RUTH.);
  4. CALC_PLAYER_AVG(31);
  5. START CALC_PLAYER_AVG(31)
Question 9 Multiple Choice (Single Answer)

When creating store procedures and functions which construct allows you to transfer values to and from the calling environment?

  1. Local variables.
  2. Arguments.
  3. Boolean variables.
  4. Substitution variables.
Question 10 Multiple Choice (Single Answer)

Which type of argument passes a value from a calling environment?

  1. VARCHAR2.
  2. BOOLEAN.
  3. OUT.
  4. IN.
Question 11 Multiple Choice (Single Answer)

Under which situation do you create a server side procedure?

  1. When the procedure contains no SQL statements.
  2. When the procedure contains no PL/SQL commands.
  3. When the procedure needs to be used by many client applications accessing several remote databases.
  4. When the procedure needs to be used by many users accessing the same schema objects on a local database.
Question 12 Multiple Choice (Single Answer)

Examine this package body:CREATE OR REPLACE PACKAGE BODY forward_packISV_sum NUMBER;- 44 -PROCEDURE calc_ord(. . . );PROCEDURE generate_summary(. . . )ISBEGINCalc_ord(. . . );. . .END calc_ord;END forward_pack;/ Which construct has a forward declaration?

  1. V_SUM
  2. CALC_ORD.
  3. FORWARD_PACK
  4. GENERATE_SUMMARY.
Question 13 Multiple Choice (Single Answer)

Examine this procedure:CREATE OR REPLACE PROCEDURE ADD_PLAYER(V_ID IN NUMBER, V_LAST_NAME VARCHER2(30))ISBEGININSERT INTO PLAYER(ID, LAST_NAME)VALUES(V_ID, V_LAST_NAME);COMMIT;END; Why does this command fail when executed?

  1. When declaring arguments length is not allowed.
  2. When declaring arguments each argument must have a mode specified.
  3. When declaring arguments each argument must have a length specified.
  4. When declaring a VARCHAR2 argument it must be specified.
Question 14 Multiple Choice (Multiple Answers)

All users currently have the INSERT privileges on the PLAYER table. You want only your users to insert into this table using the ADD_PLAYER procedure. Which two actions must you take? (Choose two)

  1. a) GRANT SELECT ON ADD_PLAYER TO PUBLIC;
  2. b) GRANT EXECUTE ON ADD_PLAYER TO PUBLIC;
  3. c) GRANT INSERT ON PLAYER TO PUBLIC;
  4. d) GRANT EXECUTE, INSERT ON ADD_PLAYER TO PUBLIC;
  5. e) REVOKE INSERT ON PLAYER FROM PUBLIC;
Question 15 Multiple Choice (Single Answer)

The PROCEDURE_ADD_PRODUCT is defined within a package specifications as follows: PROCEDURE_ADD_PRODUCT (P_PRODNO NUMBER,P_PRODNAME VARCHER2); Which procedure declaration can’t be added to package specifications?

  1. a) PROCEDURE add_product (p_order_date DATE);
  2. b) PROCEDURE add_product (p_name VARCHER2, P_ORDERED DATE);
  3. c) PROCEDURE add_product (p_prodname VARCHER2, P_PRISE NUMBER);
  4. d) PROCEDURE add_product (p_prize NUMBER, P_DESCRIPTION VARCHER2);
Question 16 Multiple Choice (Single Answer)

Command to see the current user ?

  1. show users;
  2. display user;
  3. show name;
  4. show user;
Question 17 Multiple Choice (Single Answer)

Command to change SQL prompt name ?

  1. SQL> set sqlprompt “Qwest > “
  2. SQL> set prompt “Qwest > “
  3. SQL> sqlprompt set “Qwest > “
  4. SQL> prompt “Qwest > “
Question 18 Multiple Choice (Single Answer)

Command to switch to UNIX prompt ?

  1. bye
  2. end
  3. host
  4. None of above
Question 19 Multiple Choice (Single Answer)

Which one of the following is not an Explicit Cursor attributes

  1. cursor_name%Found
  2. cursor_name%NOTFOUND
  3. cursor_name%OPEN
  4. cursor_name%ROWCOUNT
Question 20 Multiple Choice (Single Answer)

Which one of the following is not an Implicit Cursor attributes

  1. SQL%Found
  2. SQL%ISOPEN
  3. SQL%NOTFOUND
  4. SQL%ROWCOUNT