PL/SQL Basics Practice Questions Set 2

PL/SQL fundamentals: block structure, data types, operators, conditions and loops, procedures, functions and packages. This set has 40 multiple-choice questions, each with a short explanation (set 2 of 2). Click Start quiz to answer one question at a time and get instant feedback, or use Study mode to read every question with its answer.

All 40 questions with answers

  1. The following are Oracle supplied packages
    1. DBMS_OUTPUT
    2. DBMS_SQL
    3. UTL_FILE
    4. All of the above
    Show answer

    Answer: D. All of the above

    DBMS_OUTPUT, DBMS_SQL and UTL_FILE are all supplied by Oracle.

  2. PL/SQL is referred to as a
    1. block structured language
    2. unstructed langugage
    3. SQL language
    4. ANSI language
    Show answer

    Answer: A. block structured language

    PL/SQL code is organized into blocks that can be nested, which is why it is called a block-structured language.

  3. PL/SQL block can contain the following
    1. variable declarations
    2. program code
    3. other PL/SQL blocks
    4. All of the above
    Show answer

    Answer: D. All of the above

    A block can declare variables, contain executable code and nest other blocks, as well as local procedures and functions.

  4. A PL/SQL block cannot contain the below
    1. other PL/SQL blocks
    2. error handlers
    3. functions
    4. none
    Show answer

    Answer: D. none

    A block can contain nested blocks, exception handlers and local functions, so none of these are excluded.

  5. Every PL/SQL statement is followed by a
    1. delimeter
    2. quote
    3. semi colon
    4. comma
    Show answer

    Answer: C. semi colon

    Every PL/SQL statement ends with a semicolon.

  6. PL/SQL commands are case sensitive
    1. Yes
    2. No
    3. depends on the OS
    4. defined at the database parameter
    Show answer

    Answer: B. No

    PL/SQL keywords and identifiers are not case-sensitive. Only string literals and quoted identifiers are.

  7. PL/SQL blocks can be nested
    1. Yes
    2. No
    3. Maximum limit 10
    4. only for packages
    Show answer

    Answer: A. Yes

    Blocks can be nested inside the executable and exception sections of another block.

  8. Which symbol is used in assignment statement
    1. =
    2. :=
    3. ==
    4. .=
    Show answer

    Answer: B. :=

    PL/SQL assigns values with :=. A single = is a comparison operator.

  9. VARCHAR2 data type is used to store
    1. Variable length character strings
    2. Character string with 2 bytes size
    3. Any data type can be stored
    4. Used to limit at the maximum 2K size data
    Show answer

    Answer: A. Variable length character strings

    VARCHAR2 stores variable-length character strings.

  10. CHAR data type is used to store
    1. Character data types
    2. Fixed length character strings
    3. char data types
    4. Not a valid data type
    Show answer

    Answer: B. Fixed length character strings

    CHAR is fixed-length and pads values with spaces up to the declared length.

  11. BINARY_INTEGER variables are stored using
    1. same as number data type
    2. binary format
    3. Integer format
    4. Oracle database format
    Show answer

    Answer: B. binary format

    BINARY_INTEGER and PLS_INTEGER use machine binary arithmetic, which is faster and more compact than NUMBER.

  12. Among NUMBER and BINARY_INTEGER data types which one takes less space
    1. NUMBER
    2. BINARY_INTEGER
    3. Both use the same space
    Show answer

    Answer: B. BINARY_INTEGER

    BINARY_INTEGER is stored in 4 bytes of binary. NUMBER is stored in decimal form and can take up to 22 bytes.

  13. The syntax for declaring a procedure
    1. PROCEDURE <name> BEGIN <program code> END
    2. PROCEDURE <name> IS BEGIN <program code> END
    3. PROCEDURE <name> AS BEGIN <program code> END
    4. B & C
    Show answer

    Answer: D. B & C

    A stored procedure body is introduced by IS or AS; the two keywords are interchangeable.

  14. The syntax for declaring a function
    1. FUNCTION <name> RETURN <datatype> DECLARE BEGIN <program code> END
    2. FUNCTION <name> RETURN <datatype> IS BEGIN <program code> END
    3. FUNCTION <name> AS RETURN <datatype> DECLARE BEGIN <program code> END
    4. FUNCTION <name> RETURN <datatype> AS DECLARE BEGIN <program code> END
    Show answer

    Answer: B. FUNCTION <name> RETURN <datatype> IS BEGIN <program code> END

    The form is FUNCTION name RETURN type IS … BEGIN … RETURN value; END; Named subprograms do not use the DECLARE keyword.

  15. Which functions are useful when comparing case-insensitive string comparisons
    1. LOWER
    2. UPPER
    3. A & B
    4. BETWEEN
    Show answer

    Answer: C. A & B

    Wrap both sides in UPPER or LOWER, for example UPPER(name) = UPPER(:p), to compare strings without regard to case.

  16. Operators of the same precedence level are evaluated
    1. RIGHT to LEFT
    2. LEFT to RIGHT
    3. RANDOM
    4. RUNTIME
    Show answer

    Answer: B. LEFT to RIGHT

    Operators with the same precedence are evaluated from left to right.

  17. Use of parentheses in complex expressions
    1. is necessary
    2. not permitted
    3. to make the intended order of evaluation clear
    4. is aesthetic
    Show answer

    Answer: C. to make the intended order of evaluation clear

    Parentheses override the default precedence and make the order of evaluation clear to anyone reading the code.

  18. Expression TRUE OR FALSE evaluates
    1. FALSE
    2. TRUE
    3. NO ROWS FOUND
    4. RAISES syntax eror
    Show answer

    Answer: B. TRUE

    OR returns TRUE if either operand is TRUE, so TRUE OR FALSE is TRUE.

  19. Condition X IN (1,2,3) is equivalent to
    1. X=1 AND X=2 AND X=3
    2. X BETWEEN 1 AND 3
    3. X=1 OR X=2 OR X=3
    4. X >= 1 AND X<=3
    Show answer

    Answer: C. X=1 OR X=2 OR X=3

    IN is shorthand for a list of equality checks joined by OR.

  20. Which operator needs only one operand
    1. binary
    2. unary
    3. Logical
    4. Arithmetic
    Show answer

    Answer: B. unary

    A unary operator takes one operand, for example negation (-x) or NOT.

  21. Which is the right syntax for IF statement
    1. IF <condition> THEN <program_code> ELSE <program_code> END IF;
    2. IF <condition> THEN <program_code> ELSE <program_code> END;
    3. IF <condition> <program_code> ELSE <program_code> END;
    4. IF <condition> <program_code> ELSEIF <program_code> END;
    Show answer

    Answer: A. IF <condition> THEN <program_code> ELSE <program_code> END IF;

    The correct form is IF … THEN … ELSE … END IF; Use ELSIF (not ELSEIF) for extra conditions.

  22. Does Oracle allow you to create your own functions
    1. Yes
    2. No
    Show answer

    Answer: A. Yes

    CREATE FUNCTION lets you write your own stored functions. They can also be called from SQL if they follow the purity rules.

  23. Can you call functions from any PL/SQL code
    1. Yes
    2. No
    Show answer

    Answer: A. Yes

    A function can be called anywhere an expression is allowed in PL/SQL, provided you have EXECUTE privilege on it.

  24. Syntax for GO TO statement
    1. GO TO lable_name
    2. GOTO label_name
    3. GOTO is not a valid statement
    4. GO TO Exit
    Show answer

    Answer: B. GOTO label_name

    The syntax is GOTO label_name; and the label is written as <<label_name>> before a statement.

  25. How many times must the WHILE loop execute
    1. Atleast once
    2. might never have to execute
    3. More than once
    4. While loop does not exists in Oracle as in JAVA
    Show answer

    Answer: B. might never have to execute

    WHILE checks its condition before each pass, so if the condition is FALSE at the start the body never runs.

  26. Which command is used to exit from a simple LOOP
    1. EXIT
    2. EXIT WHEN
    3. A & B
    4. Not needed
    Show answer

    Answer: C. A & B

    A simple LOOP is ended with EXIT or EXIT WHEN condition.

  27. Can you potentially write a WHILE loop that never ends
    1. FALSE
    2. TRUE
    3. WHILE loop always ends
    4. gives syntax error
    Show answer

    Answer: B. TRUE

    If the WHILE condition never becomes FALSE or NULL, the loop runs forever.

  28. What statement(s) allow you to abort the processing of a loop
    1. EXIT
    2. EXIT WHEN
    3. A & B
    4. Not needed
    Show answer

    Answer: C. A & B

    EXIT and EXIT WHEN both leave a loop. RETURN or an unhandled exception also stop it.

  29. A Procedure is a
    1. logically grouped set of SQL and PL/SQL statements that perform a specific task
    2. logically grouped set of database functions that perform a specific task
    3. logically grouped set of stored events that perform a specific task
    4. logically grouped set of SQL statements that perform a specific task
    Show answer

    Answer: A. logically grouped set of SQL and PL/SQL statements that perform a specific task

    A procedure is a named PL/SQL block of SQL and PL/SQL statements that performs a task and can be stored in the database.

  30. A stored procedure is
    1. stored in the database and compiled
    2. stored in the database as uncomiled
    3. compilation is performed during run time
    Show answer

    Answer: A. stored in the database and compiled

    CREATE PROCEDURE compiles the code and stores both the source and the compiled form in the data dictionary.

  31. How do you drop a procedure
    1. using a replace command
    2. using drop procedure command
    3. using remove procedure command
    4. using del procedure command
    Show answer

    Answer: B. using drop procedure command

    Use DROP PROCEDURE procedure_name;

  32. What is a recursive procedure
    1. a procedure that goes into infinite loop
    2. a procedure that always returns 1
    3. a procedure that calls itself
    4. a procedure that does not have a return statement
    Show answer

    Answer: C. a procedure that calls itself

    A recursive procedure calls itself. It needs an end condition, otherwise it runs until it hits a stack error.

  33. How do you recompile a package
    1. ALTER PACKGE <name> compile body
    2. ALTER PACKGE <name> compile package
    3. A & B
    Show answer

    Answer: C. A & B

    ALTER PACKAGE name COMPILE (or COMPILE PACKAGE) recompiles the spec and body; ALTER PACKAGE name COMPILE BODY recompiles only the body.

  34. PL/SQL table functions
    1. COUNT
    2. EXISTS
    3. FIRST
    4. All of the above
    Show answer

    Answer: D. All of the above

    COUNT, EXISTS, FIRST, LAST, NEXT, PRIOR and DELETE are all collection methods for PL/SQL tables.

  35. What is the variable attribute you use to base a variable on a table column
    1. %type
    2. %rowtype
    3. %recordtype
    4. %table of
    Show answer

    Answer: A. %type

    %TYPE anchors a variable to a column’s data type, for example v_sal emp.sal%TYPE;

  36. What is a PL/SQL record
    1. It is a dynamic variable
    2. variable with the type record
    3. It is a variable of type table
    4. variable with fixed number of columns
    Show answer

    Answer: B. variable with the type record

    A record is a composite variable with named fields, declared with TYPE … IS RECORD or with %ROWTYPE.

  37. Is there any diff between the below two statements a char(20) := ‘name’; a Varchar(20) := ‘name’; ?
    1. No difference.
    2. In Char type spaces will be padded after ‘name’ upto max length 20.in Varchar spaces will not be padded
    3. Both the cases the space will be padded after ‘name’ upto max length 20
    4. In Char type spaces will be padded after ‘name’ uptp max length 20.in Varchar spaces will padded before ‘name’ upto max length 20
    Show answer

    Answer: B. In Char type spaces will be padded after ‘name’ upto max length 20.in Varchar spaces will not be padded

    CHAR pads the value with trailing spaces to its full length. VARCHAR2 stores only the characters assigned.

  38. What is the difference between using IS and AS while creating a procedure, function package and package body?
    1. There absolutely no difference
    2. Using IS will throw error
    3. Using AS will throw error while compilation
    4. After AS keyword we specify the return datatype. After IS keyword we do the variable declaration
    Show answer

    Answer: A. There absolutely no difference

    IS and AS are interchangeable in CREATE PROCEDURE, FUNCTION and PACKAGE statements.

  39. Is it possible to have same name for package and the procedure in a package
    1. Yes
    2. No
    Show answer

    Answer: A. Yes

    Packaged subprograms are referenced as package.procedure, so a procedure may share the package’s name without a clash.

  40. Which PL/SQL data type can be stored as a column in a data base table
    1. nested tables
    2. Associative array
    3. Both a and b
    4. none
    Show answer

    Answer: A. nested tables

    Nested tables (and varrays) can be SQL types and used as column types. Associative arrays exist only inside PL/SQL.

More Oracle practice questions

These questions come from interview and training material collected over years of Oracle EBS project work by Amol Jadhav. They are not copied from Oracle certification exams.