PL/SQL fundamentals: block structure, data types, operators, conditions and loops, procedures, functions and packages. This set has 37 multiple-choice questions, each with a short explanation (set 1 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 37 questions with answers
- What is difference between %ROWTYPE and TYPE RECORD?
- No difference
- % ROWTYPE is to be used whenever query returns a entire row of a table or view. TYPE rec RECORD is to be used whenever query returns columns of different table or views and variables.
- TYPE rec RECORD is to be used whenever query returns a entire row of a table or view. % ROWTYPE is to be used whenever query returns columns of different table or views and variables.
Show answer
Answer: B. % ROWTYPE is to be used whenever query returns a entire row of a table or view. TYPE rec RECORD is to be used whenever query returns columns of different table or views and variables.
%ROWTYPE gives a record that matches a whole table, view or cursor row. A user-defined RECORD type lets you combine fields of any type, such as columns from several tables plus local variables.
- Which column in the USER_SOURCE view reflects the line number of a particular line of source code?
- LINE
- LINE_NO
- LINE_NUMBER
- NO
Show answer
Answer: A. LINE
USER_SOURCE has the columns NAME, TYPE, LINE and TEXT. LINE holds the line number of each source line.
- The syntax for Loops
- FOR loop_index low_value..high_value LOOP <program_code END LOOP;
- FOR loop_index IN low_value..high_value LOOP <program_code END LOOP;
- FOR loop_index IN high_value..low_value LOOP <program_code END LOOP;
- FOR loop_index IN high_value..low_value LOOP <program_code END;
Show answer
Answer: B. FOR loop_index IN low_value..high_value LOOP <program_code END LOOP;
A numeric FOR loop is written FOR i IN low..high LOOP … END LOOP; To count down you add REVERSE, but the bounds are still written low..high.
- Keyword DECLARE is used while defining
- anonymous block
- procedure
- functions
- Packages
Show answer
Answer: A. anonymous block
An anonymous block starts with DECLARE when it has declarations. Procedures, functions and packages use IS or AS instead of DECLARE.
- Why do we type / at the end of PL/SQL block
- to compile the code
- does not have any meaning
- tells SQL & PLUS that we are done typing PL/SQL code
- used as a standard, semicolon can be used instead
Show answer
Answer: C. tells SQL & PLUS that we are done typing PL/SQL code
In SQL*Plus a slash on its own line tells SQL*Plus the PL/SQL block is finished and should be sent to the database to run. A semicolon alone only ends a statement inside the block.
- Which command is used to display a line of text
- DBMS_OUTPUT.PUT_LINE
- DBMS_OUTPUT.GET_LINE
- UTL_FILE.WRITE
- UTL_FILE.FOPEN
Show answer
Answer: A. DBMS_OUTPUT.PUT_LINE
DBMS_OUTPUT.PUT_LINE writes a line to the output buffer, which SQL*Plus shows when SERVEROUTPUT is ON. GET_LINE reads from that buffer; UTL_FILE writes to server files.
- Where does PL/SQL code execution take place
- Server
- Client
- A & B
Show answer
Answer: C. A & B
PL/SQL runs in the database server, and tools such as Oracle Forms and Reports carry their own PL/SQL engine, so code can also run on the client or application tier.
- Oracle products such as Oracle Forms have the capability to execute PL/SQL code at client side
- No
- Yes
Show answer
Answer: B. Yes
Oracle Forms has its own PL/SQL engine, so form triggers and program units run in the Forms runtime rather than in the database.
- Which of these is a fundamental unit of PL/SQL programming
- variable
- function
- declare section
- block
Show answer
Answer: D. block
The block (DECLARE, BEGIN, EXCEPTION, END) is the basic unit of PL/SQL. Procedures, functions and triggers are all named blocks.
- What is the maximum size limit allowed for VARCHAR2 variable in PL/SQL block
- 32767
- 2000
- 4000
- No limit
Show answer
Answer: A. 32767
A PL/SQL VARCHAR2 variable can hold up to 32,767 bytes. A VARCHAR2 table column is limited to 4,000 bytes unless MAX_STRING_SIZE is EXTENDED.
- Number data type is used for declaring
- fixed point numbers
- floating pointing number
- Both A & B
- None
Show answer
Answer: C. Both A & B
NUMBER stores both fixed-point values, such as NUMBER(7,2), and floating-point values when declared without precision and scale.
- Number data type allows maximum precision of
- There is no limit
- 108 demimal digits
- 1008 decimal digits
- 38 decimal digits
Show answer
Answer: D. 38 decimal digits
NUMBER supports a precision of 1 to 38 significant decimal digits.
- Precision in number data type specifies
- how many digits are used to represent the number
- where the decimal point is
- the size and number of decimal points
- none
Show answer
Answer: A. how many digits are used to represent the number
Precision is the total number of significant digits. NUMBER(7,2) can hold values up to 99999.99.
- Scale in number data type specifies
- how many digits are used to represent the number
- where the decimal point is
- the size and number of decimal points
- none
Show answer
Answer: B. where the decimal point is
Scale is the number of digits to the right of the decimal point, so it fixes where the point sits. NUMBER(7,2) keeps two decimal places.
- BINARY_INTEGER datatype is used for declaring
- signed integer variables
- unsigned integer variables
- both
- none
Show answer
Answer: A. signed integer variables
BINARY_INTEGER (the same as PLS_INTEGER since 10g) holds signed integers from -2,147,483,648 to 2,147,483,647.
- Which data type is used to store strings of byte-oriented data?
- LONG
- RAW
- VARCHAR2
- TYPE
Show answer
Answer: B. RAW
RAW holds binary, byte-oriented data such as images or encrypted values. Oracle does not convert RAW data between character sets.
- Size of RAW data type in PL/SQL
- 32767
- 255
- block size
- 2000
Show answer
Answer: A. 32767
A RAW variable in PL/SQL can be up to 32,767 bytes. A RAW table column is limited to 2,000 bytes unless extended strings are enabled.
- While evaluating expressions, Oracle evaluates operators with a higher precedence
- FIRST
- LAST
- LEFT
- RIGHT
Show answer
Answer: A. FIRST
Operators with higher precedence, such as ** and *, are evaluated before those with lower precedence, such as + and comparisons.
- Legal or not legal DECLARE emp_rec emp_rec_type
- Not legal because emp_rec_type must be declared prior to this declaration
- Not legal because emp_rec_type must be declared after this declaration
- Legal because emp_rec takes the type of emp_rec_type
Show answer
Answer: A. Not legal because emp_rec_type must be declared prior to this declaration
PL/SQL does not allow forward references. The type emp_rec_type must be declared before any variable that uses it.
- Legal or not legal DECLARE emp_last_name %type
- Not legal because it should include table reference
- Not legal because it should include table and column reference
- Legal because it can reference any table and column type
- Legal because %type is new data type available in higher versions
Show answer
Answer: B. Not legal because it should include table and column reference
%TYPE needs something to anchor to, such as table.column or another variable, for example: emp_last_name employees.last_name%TYPE;
- How do you run Native Dynamic SQL
- use “Execute immediate”
- use “dbms_execute”
- use “utl_file”
Show answer
Answer: A. use “Execute immediate”
Native dynamic SQL uses EXECUTE IMMEDIATE, or OPEN … FOR for multi-row queries. DBMS_SQL is the older, package-based way.
- What will happen to an anonymous block,if there is no statement inside the block?
- Compilation error
- Statement Compiled successfully.but gives run time error
- No action is performed
Show answer
Answer: A. Compilation error
A block needs at least one executable statement between BEGIN and END, so an empty block fails to compile. Use NULL; as a placeholder.
- When one procedure calls another procedure, which of the following is true?
- The called procedure executes to completion, and this terminates all execution, the calling block cannot resume
- The calling block continues executing with the statements that follow the procedure call, while the called procedure starts up simultaneously
- The called procedure executes and, upon completion, the calling block resumes where the called procedure was invoked and only then continues execution
- The cannled procedure cannot be called from another procedure
Show answer
Answer: C. The called procedure executes and, upon completion, the calling block resumes where the called procedure was invoked and only then continues execution
Procedure calls are synchronous. The caller waits until the called procedure finishes, then carries on with the next statement.
- Which value in the TYPE column of USER_OBJECTS indicates the object is a procedure?
- PROCEDURE
- PROCED?URE_OR_FUNCTION
- PROGRAM_UNIT
- PROC
Show answer
Answer: A. PROCEDURE
USER_OBJECTS.OBJECT_TYPE shows values such as PROCEDURE, FUNCTION, PACKAGE and PACKAGE BODY.
- You have created a procedure and attempted to store it in the database using the CREATE PROCEDURE command, When you submitted it to the datbase, you received a syntax error. From the perspective of the schema that ateempted the creation, which f the following data dictionary objects now contains the source code for this procedure?
- ALL_SOURCE
- USER_SOURCE
- None fo them
- A&B
Show answer
Answer: D. A&B
Oracle stores the source even when compilation fails, so it is visible in USER_SOURCE and ALL_SOURCE. The compile errors are in USER_ERRORS.
- An —————- is a user-defined composite datatype representing a data structure and functions and procedures to manipulate the data.
- Object type
- Attribute
- Method
- Object attribute
Show answer
Answer: A. Object type
An object type, created with CREATE TYPE … AS OBJECT, holds attributes plus member functions and procedures that work on them.
- Which statement is wrong?
- Variable must be declared before the usage
- Only TRUE or FALSE can be assigned to BOOLEAN type of variable
- Users can customize the variable types by using TYPE … IS … statement.
- Variable Declaration is done in the Begin section of PL/SQL code structure
Show answer
Answer: D. Variable Declaration is done in the Begin section of PL/SQL code structure
Variables are declared in the declaration section (after DECLARE, IS or AS), not in the BEGIN section.
- Which Statement is Wrong about Functions in PL/SQL?
- A functions must returns a value.
- Function can be called as a part of a expression
- A Function is a standalone executable statement in PL/SQL
- A function will returns a Scalar value and must have a return statement in the Begin section
Show answer
Answer: C. A Function is a standalone executable statement in PL/SQL
A function returns a value and is called as part of an expression. It cannot run as a standalone statement the way a procedure can.
- Which is not a oracle package?
- DBMS_OUT
- DBMS_PIPE
- DBMS_JOB
- UTL_FILE
Show answer
Answer: A. DBMS_OUT
DBMS_PIPE, DBMS_JOB and UTL_FILE are Oracle-supplied packages. The output package is DBMS_OUTPUT; DBMS_OUT does not exist.
- The —– returns the actual error message for the last error encountered
- SQLERROR
- SQLCODE
- SQLMSG
- SQLERRM
Show answer
Answer: D. SQLERRM
SQLERRM returns the error message text for the last error. SQLCODE returns the error number.
- How we can create a table through procedure ?
- EXECUTE SQL ‘CREATE TABLE table_name AS query’;
- EXECUTE IMMEDIATE ‘CREATE TABLE table_name AS query’;
- CREATE TABLE table_name AS query;
- A table cannot created through a procdure
Show answer
Answer: B. EXECUTE IMMEDIATE ‘CREATE TABLE table_name AS query’;
DDL cannot be written directly in PL/SQL, so use dynamic SQL: EXECUTE IMMEDIATE ‘CREATE TABLE …’. The owner also needs CREATE TABLE granted directly, not through a role.
- What are the components of PL/SQL blocks?
- Declarative Part
- Definition Part
- Execution part
- Option 1,3
Show answer
Answer: D. Option 1,3
A block has a declarative part (optional), an executable part (required) and an exception-handling part (optional).
- Name the tables where characteristics of Package, procedure and functions are stored ?
- User_objects
- user_source
- user_error
- all of these
Show answer
Answer: D. all of these
USER_OBJECTS holds the object and its status, USER_SOURCE holds the code and USER_ERRORS holds compile errors.
- What are the modes of parameters that can be passed to a procedure ?
- IN
- OUT
- IN-OUT
- ALL of these
Show answer
Answer: D. ALL of these
Parameters can be IN (the default), OUT or IN OUT.
- What is the difference in calling functions and procedure in a PL/SQL block
- Procudute is called as a part of an expression . Functions are called as a PL/SQL statement
- Procedure is called as PL/SQL statement.Function is called as a part of an expression
- Both procedure and functions are called a apart of the expression
- Both procedure and functions are called as PL/SQL statement
Show answer
Answer: B. Procedure is called as PL/SQL statement.Function is called as a part of an expression
A procedure is called as a statement on its own. A function returns a value, so it is used inside an expression, for example v := get_total(10);
- How to call packaged procedure from SQL *PLUS
- EXCECUTE package_name.procedure,if procedure doesnot have any in,in-out p[arameters.
- Variable a NUMBER; EXCECUTE package_name.procuder(:a); , if the procedure have a out or inout parameter of type NUMBER
- EXCECUTE package_name.procuder(1); , if the procedure have a IN parameter of type NUMBER
- All of these
Show answer
Answer: D. All of these
Use EXECUTE pkg.proc when there are no parameters, pass literals for IN parameters, and declare a SQL*Plus VARIABLE to receive an OUT parameter.
- Which of the following commands can be used to interrupt processing of a While loop?
- BREAK
- HALT
- EXIT
- CONTINUE
Show answer
Answer: C. EXIT
EXIT or EXIT WHEN leaves any loop, including a WHILE loop. CONTINUE (11g and later) skips to the next pass, and BREAK does not exist in 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.
