PL/SQL Interview Questions


Advertisements


Dear readers, these PL/SQL Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your interview for the subject of PL/SQL. As per my experience good interviewers hardly plan to ask any particular question during your interview, normally questions start with some basic concept of the subject and later they continue based on further discussion and what you answer:

PL/SQL is an extension of SQL. SQL is non-procedural. PL/SQL is a procedural language designed by oracle to overcome the limitations that exist in SQL.

True.

False. PL/SQL has all features of a structured programming language including data types, variables, subroutines, modules and procedural constructs.

  • Block-structured language.

  • Stored procedures help better sharing of application.

  • Portable to all environments that support Oracle.

  • Integration with the Oracle data dictionary.

  • Stored procedures and functions
  • Packages
  • Triggers
  • Cursors
  • Variables and constants
  • Embedded SQL support
  • Flow control
  • Cursor management
  • Exception handling
  • Stored procedures and packages
  • Triggers
  • Declaration section
  • Execution section
  • Exception section

Use of wrong assignment operator. The correct syntax is: balance := balance + 2000;

greeting := ‘Hello’ || ‘World’;

NOT

OR

The colon (: )sign implies that the variable :deficit is an external variable.

It assigns a variable the same data type used by the column, for which the variable is created. For example,

dcode := dept.detpno%type;

The variable dcode is created with the same data type as that of the deptno column of the dept table.

It declares a composed variable that is equivalent to the row of a table. After the variable is created, the fields of the table can be accessed, using the name of this variable.

For example

emptype := emp%rowtype;

name := emptype.empname;

A package is a file that groups functions, cursors, stored procedures, and variables in one place.

A trigger is a PL/SQL program that is stored in the database and executed immediately before or after the INSERT, UPDATE, and DELETE commands.

Oracle uses workspaces to execute the SQL commands. In other words, when Oracle processes a SQL command, it opens an area in the memory called Private SQL Area. A cursor is an identifier for this area. It allows programmers to name this area and access it’s information.

True.

False. The BEGIN declaration starts the execution section.

True.

False. PL/SQL doesn’t support the data definition commands like CREATE.

It returns the number of rows that are processed by a SQL statement.

It returns the Boolean value TRUE if at least one row was processed.

It returns the Boolean value TRUE if no rows were processed.

LOOP command, FOR.. LOOP command, WHILE command.

A trigger is automatically executed without any action required by the user, whereas, a stored procedure needs to be explicitly invoked.

Basically triggers are used to create consistencies, access restriction and implement securities to the database. Triggers are also used for −

  • Creating validation mechanisms involving searches in multiple tables

  • Creating logs to register the use of a table

  • Update other tables as a result of inclusion or changes in the current table.

True.

False. When a trigger is associated to a view, the base table triggers are normally enabled.

True.

A trigger cannot execute the COMMIT, ROLLBACK, or SAVEPOINT commands.

A WHEN clause specifies the condition that must be true for the trigger to be triggered.

True.

The optional argument [OR REPLACE] in a CREATE TRIGGER command re-creates an existing trigger. Using this option allows changing the definition of an existing trigger without having to delete it first.

False. INSTEAD OF is a valid option only for views. INSTEAD OF trigger cannot be specified in a table.

ALTER TRIGGER update_marks DISABLE;

DROP TRIGGER command.

DROP PROCEDURE command.

A function returns a value and a stored procedure doesn’t return a value.

User defined exceptions are declared under the DECLARE section, with the keyword EXCEPTION. Syntax −

<exception_name> EXCEPTION;

Explicit cursors are defined explicitly using the CURSOR statement, with a general syntax −

CURSOR cursor_name [(parameters)] IS query_expression;

It allows processing queries that return multiple rows.

The steps that need to be performed on explicit cursor are −

  • DECLARE − assigns a name to the cursor and defines the structure of query within it.

  • OPEN − executes the query, whereby the rows returned by the query are available for fetching.

  • FETCH − assigns values from the current row (cursor position) into specified variables.

  • CLOSE − releases the memory space.

PL/SQL packages have two parts −

  • Specification part − where the interface to the application are defined.

  • Body part − where the implementation of the specification are defined.

CREATE PACKAGE command is used for creating the specification part. CREATE PACKAGE BODY command is used for creating the body part.

The types, objects, and subprograms declared within a package are referred to using the dot notation as −

package_name.type_name

package_name.object_name

package_name.subprogram_name

True.

The DROP PACKAGE command.

Oracle implicitly declares a cursor to all the DDL and DML commands that return only one row. For queries returning multiple rows, an explicit cursor is created.

False. The %NOTFOUND attribute returns true when the last row of the cursor is processed and no other row is available.

True.

What is Next ?

Further you can go through your past assignments you have done with the subject and make sure you are able to speak confidently on them. If you are fresher then interviewer does not expect you will answer very complex questions, rather you have to make your basics concepts very strong.

Second it really doesn't matter much if you could not answer few questions but it matters that whatever you answered, you must have answered with confidence. So just feel confident during your interview. We at tutorialspoint wish you best luck to have a good interviewer and all the very best for your future endeavor. Cheers :-)


plsql_questions_answers.htm

Advertisements
E-Books Store