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
- The following are Oracle supplied packages
- DBMS_OUTPUT
- DBMS_SQL
- UTL_FILE
- All of the above
Show answer
Answer: D. All of the above
DBMS_OUTPUT, DBMS_SQL and UTL_FILE are all supplied by Oracle.
- PL/SQL is referred to as a
- block structured language
- unstructed langugage
- SQL language
- 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.
- PL/SQL block can contain the following
- variable declarations
- program code
- other PL/SQL blocks
- 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.
- A PL/SQL block cannot contain the below
- other PL/SQL blocks
- error handlers
- functions
- none
Show answer
Answer: D. none
A block can contain nested blocks, exception handlers and local functions, so none of these are excluded.
- Every PL/SQL statement is followed by a
- delimeter
- quote
- semi colon
- comma
Show answer
Answer: C. semi colon
Every PL/SQL statement ends with a semicolon.
- PL/SQL commands are case sensitive
- Yes
- No
- depends on the OS
- 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.
- PL/SQL blocks can be nested
- Yes
- No
- Maximum limit 10
- only for packages
Show answer
Answer: A. Yes
Blocks can be nested inside the executable and exception sections of another block.
- Which symbol is used in assignment statement
- =
- :=
- ==
- .=
Show answer
Answer: B. :=
PL/SQL assigns values with :=. A single = is a comparison operator.
- VARCHAR2 data type is used to store
- Variable length character strings
- Character string with 2 bytes size
- Any data type can be stored
- Used to limit at the maximum 2K size data
Show answer
Answer: A. Variable length character strings
VARCHAR2 stores variable-length character strings.
- CHAR data type is used to store
- Character data types
- Fixed length character strings
- char data types
- 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.
- BINARY_INTEGER variables are stored using
- same as number data type
- binary format
- Integer format
- 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.
- Among NUMBER and BINARY_INTEGER data types which one takes less space
- NUMBER
- BINARY_INTEGER
- 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.
- The syntax for declaring a procedure
- PROCEDURE <name> BEGIN <program code> END
- PROCEDURE <name> IS BEGIN <program code> END
- PROCEDURE <name> AS BEGIN <program code> END
- B & C
Show answer
Answer: D. B & C
A stored procedure body is introduced by IS or AS; the two keywords are interchangeable.
- The syntax for declaring a function
- FUNCTION <name> RETURN <datatype> DECLARE BEGIN <program code> END
- FUNCTION <name> RETURN <datatype> IS BEGIN <program code> END
- FUNCTION <name> AS RETURN <datatype> DECLARE BEGIN <program code> END
- 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.
- Which functions are useful when comparing case-insensitive string comparisons
- LOWER
- UPPER
- A & B
- 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.
- Operators of the same precedence level are evaluated
- RIGHT to LEFT
- LEFT to RIGHT
- RANDOM
- RUNTIME
Show answer
Answer: B. LEFT to RIGHT
Operators with the same precedence are evaluated from left to right.
- Use of parentheses in complex expressions
- is necessary
- not permitted
- to make the intended order of evaluation clear
- 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.
- Expression TRUE OR FALSE evaluates
- FALSE
- TRUE
- NO ROWS FOUND
- RAISES syntax eror
Show answer
Answer: B. TRUE
OR returns TRUE if either operand is TRUE, so TRUE OR FALSE is TRUE.
- Condition X IN (1,2,3) is equivalent to
- X=1 AND X=2 AND X=3
- X BETWEEN 1 AND 3
- X=1 OR X=2 OR X=3
- 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.
- Which operator needs only one operand
- binary
- unary
- Logical
- Arithmetic
Show answer
Answer: B. unary
A unary operator takes one operand, for example negation (-x) or NOT.
- Which is the right syntax for IF statement
- IF <condition> THEN <program_code> ELSE <program_code> END IF;
- IF <condition> THEN <program_code> ELSE <program_code> END;
- IF <condition> <program_code> ELSE <program_code> END;
- 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.
- Does Oracle allow you to create your own functions
- Yes
- 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.
- Can you call functions from any PL/SQL code
- Yes
- 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.
- Syntax for GO TO statement
- GO TO lable_name
- GOTO label_name
- GOTO is not a valid statement
- 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.
- How many times must the WHILE loop execute
- Atleast once
- might never have to execute
- More than once
- 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.
- Which command is used to exit from a simple LOOP
- EXIT
- EXIT WHEN
- A & B
- Not needed
Show answer
Answer: C. A & B
A simple LOOP is ended with EXIT or EXIT WHEN condition.
- Can you potentially write a WHILE loop that never ends
- FALSE
- TRUE
- WHILE loop always ends
- gives syntax error
Show answer
Answer: B. TRUE
If the WHILE condition never becomes FALSE or NULL, the loop runs forever.
- What statement(s) allow you to abort the processing of a loop
- EXIT
- EXIT WHEN
- A & B
- Not needed
Show answer
Answer: C. A & B
EXIT and EXIT WHEN both leave a loop. RETURN or an unhandled exception also stop it.
- A Procedure is a
- logically grouped set of SQL and PL/SQL statements that perform a specific task
- logically grouped set of database functions that perform a specific task
- logically grouped set of stored events that perform a specific task
- 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.
- A stored procedure is
- stored in the database and compiled
- stored in the database as uncomiled
- 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.
- How do you drop a procedure
- using a replace command
- using drop procedure command
- using remove procedure command
- using del procedure command
Show answer
Answer: B. using drop procedure command
Use DROP PROCEDURE procedure_name;
- What is a recursive procedure
- a procedure that goes into infinite loop
- a procedure that always returns 1
- a procedure that calls itself
- 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.
- How do you recompile a package
- ALTER PACKGE <name> compile body
- ALTER PACKGE <name> compile package
- 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.
- PL/SQL table functions
- COUNT
- EXISTS
- FIRST
- 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.
- What is the variable attribute you use to base a variable on a table column
- %type
- %rowtype
- %recordtype
- %table of
Show answer
Answer: A. %type
%TYPE anchors a variable to a column’s data type, for example v_sal emp.sal%TYPE;
- What is a PL/SQL record
- It is a dynamic variable
- variable with the type record
- It is a variable of type table
- 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.
- Is there any diff between the below two statements a char(20) := ‘name’; a Varchar(20) := ‘name’; ?
- No difference.
- In Char type spaces will be padded after ‘name’ upto max length 20.in Varchar spaces will not be padded
- Both the cases the space will be padded after ‘name’ upto max length 20
- 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.
- What is the difference between using IS and AS while creating a procedure, function package and package body?
- There absolutely no difference
- Using IS will throw error
- Using AS will throw error while compilation
- 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.
- Is it possible to have same name for package and the procedure in a package
- Yes
- 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.
- Which PL/SQL data type can be stored as a column in a data base table
- nested tables
- Associative array
- Both a and b
- 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.
