NiC IT Academy

PLSQL Interview Questions Set 01

Published On: 24 July 2024

Last Updated: 11 September 2024

No Responses

1. What is PL/SQL?

Oracle PL/SQL is a procedural language that has both interactive SQL and procedural programming language constructs such as iteration and conditional branching.

2. How can you Rollback a particular part of a procedure or any PL/SQL Program?

It can be done using Save points during the definition of a PL/SQL program.

3. What is set server output function used for in PL/SQL?

In PL/SQL, we frequently require to produce the Output on the console. We generally do it using dbms_output.put_line() function. For this to work properly and display the output on the console screen, we need to first set the server output to ON state. For this, the command is set server output on.

4. What are the disadvantages of Cursors and is there any alternative to it?

The processing of Cursors is very slow as compared to Joins. Hence, Joins can be an alternative to Cursors.

5. What are the different Loop Control Structures used in PL/SQL?

The different Loop Control Structures in PL/SQL are as follows:
1. Exit
2. Exit-When
3. Continue
4. Goto

6. What is PL/SQL, Why do we need PL/SQL instead of SQL, Describe your experience working with PLSQL and What are the difficulties faced while working with PL SQL and How did you overcome?

PL/SQL is a procedural language extension with SQL Language.

Oracle introduced PL/SQL It is a combination of SQL and Procedural Statements and used for creating applications.
Basically, PL/SQL is a block-structured programming language whenever we are submitting PL/SQL Blocks then all SQL statements are executing separately by using SQL engine and also all procedure statements are executed separately. Explain your current and previous projects along with your roles and responsibilities, mention some of the challenging difficulties you’ve faced in your project while working with PL/SQL.

7. What is Mutating Trigger?

Into a row-level trigger based on a table, trigger body cannot read data from the same table and also we cannot perform DML operation on the same table. If we are trying this oracle server returns mutating error oracle-4091: table is mutating. This error is called mutating error, and this trigger is called a mutating trigger, and the table is called a mutating table.
Mutating errors are not occurred in statement-level trigger because through this statement-level trigger when we are performing DML operations automatically data committed into the database, whereas in the row-level trigger when we are performing transaction data is not committed and also again we are reading this data from the same table then only mutating errors occur.

8. What are Views and why they are used?

A View logically represents subsets of data from one or more table. A View is a logical table based on a table or another view. A View contains no data of its own but is like a window through which data from tables can be viewed or changed. The tables on which a view is based are called Base Tables. The View is stored as a SELECT statement in the data dictionary. View definitions can be retrieved from the data dictionary table: USER_VIEWS.

Views are used:
To restrict data access
To make complex queries easy
To provide data Independence Views provide groups of the user to access data according to their requirement.
Oracle PL/SQL Interview Questions And Answers For 7 Years Experience.

9. What is a difference between ON DELETE CASCADE and ON DELETE SET NULL?

ON DELETE CASCADE Indicates that when the row in the parent table is deleted, the dependent rows in the child table will also be deleted. ON DELETE SET NULL Coverts foreign key values to null when the parent value is removed. Without the ON DELETE CASCADE or the ON DELETE SET NULL options, the row in the parent table cannot be deleted if it is referenced in the child table.

10. Describe types of Constraints in brief?

NOT NULL: NOT NULL Constraint ensures that the column contains no null values.

UNIQUE KEY: UNIQUE Key Constraint ensures that every value in a column or set of columns must be unique, that is, no two rows of a table can have duplicate values in a specified column or set of columns. If the UNIQUE constraint comprises more than one column, that group of columns is called a Composite Unique Key. There can be more than one Unique key on a table. Unique Key Constraint allows the input of Null values. Unique Key automatically creates an index on the column it is created.

PRIMARY KEY: Uniquely identifies each row in the Table. Only one PRIMARY KEY can be created for each table but can have several UNIQUE constraints. PRIMARY KEY ensures that no column can contain a NULL value. A Unique Index is automatically created for a PRIMARY KEY column. PRIMARY KEY is called a Parent key.

FOREIGN KEY: Is also called Referential Integrity Constraint. FOREIGN KEY is one in which a column or set of columns take references of the Primary/Unique key of the same or another table. FOREIGN KEY is called a child key. A FOREIGN KEY value must match an existing value in the parent table or be null.

CHECK KEY: Defines a condition that each row must satisfy. A single column can have multiple CHECK Constraints. During CHECK constraint following expressions is not allowed:

1) References to CURRVAL, NEXTVAL, LEVEL, and ROWNUM Pseudo columns.
2) Calls to SYSDATE, UID, USER, and USERENV Functions.

11. What is the difference between a Rollback Command and a Commit Command?

A Commit command is used to save the current transaction in the database in which modification is done to the database using Database Manipulation Language (DML) commands. A Rollback command is however used to undo the modifications done by the DML commands previously.

12. What is the cursor and why it is required?

A cursor is a temporary work area created in system memory when an SQL statement is executed. A cursor contains information on a select statement and the row of data accessed by it. This temporary work area stores the data retrieved from the database and manipulate this data. A cursor can hold more than one row but can process only one row at a time. The cursor is required to process rows individually for queries.

13. How is the process of PL/SQL compiled?

The compilation process includes syntax check, bind, and p-code generation processes. Syntax checking checks the PL/SQL codes for compilation errors. When all errors are corrected, a storage address is assigned to the variables that hold data. It is called Binding. P-code is a list of instructions for the PL/SQL engine. P-code is stored in the database for named blocks and is used the next time it is executed.

14. what is Flashback Query?

Flashback query is handled by Database Administrator only flashback queries along allows the content of the table to be retrieved with reference to a specific point of time by using as of clause that is flashback queries retrieves accidental data after committing the transaction also. Flashback queries generally use undo file that is flashback queries retrieve old data before committing the transaction oracle to provide two methods for flashback queries.

15. What is REF CURSOR (or) CURSOR VARIABLE (or) DYNAMIC CURSOR?

Oracle 7.2 introduced ref cursor, This is a user-defined type which is used to process multiple records and also this is a record by record process.
In static cursor, database servers execute only one select statement at a time for a single active set area wherein ref cursor database servers execute a number of select statement dynamically for a single active set area that’s why those cursors are also called as a dynamical cursor.
Generally, we are not allowed to pass static cursor as parameters to use subprograms whereas we can also pass ref cursor as a parameter to the subprograms because basically precursor is a user-defined type in oracle we can also pass all user-defined type as a parameter to the subprograms.
Generally, the static cursor does not return multiple records into client application whereas ref cursor is allowed to return multiple records into client application (Java, .Net, PHP, VB, C++).
This is an user-defined type so we are creating it in 2 steps process i.e first we are creating type then only we are creating a variable from that type that’s why this is also called as cursor variable.

16. Describe naming rules for creating a Table?

Naming rules to be considered for creating a table are:

The table name must begin with a letter, The table name can be 1-30 characters long, Table name can contain only A-Z, a-z, 0-9,_, $, #.The table name cannot duplicate the name of another object owned by the same user. The table name cannot be an oracle server reserved word.

17. Explain all Joins used in Oracle?

Cartesian Join: When a Join condition is invalid or omitted completely, the result is a Cartesian product, in which all combinations of rows are displayed. To avoid a Cartesian product, always include a valid join condition in a “where” clause. To Join ‘N’ tables together, you need a minimum of N-1 Join conditions.

Forex: to join four tables, a minimum of three joins is required. This rule may not apply if the table has a concatenated primary key, in which case more than one column is required to uniquely identify each row.

Equi Join: This type of Join involves primary and foreign key relation. Equi Join is also called Simple or Inner Joins.
Non-Equi Joins A Non-Equi Join condition containing something other than an equality operator. The relationship is obtained using an operator other than equal operator (=). The conditions such as <= and >= can be used, but BETWEEN is the simplest to represent Non-Equi Joins.

Outer Joins: Outer Join is used to fetch rows that do not meet the join condition. The outer join operator is the plus sign (+), and it is placed on the side of the join that is deficient in information. The Outer Join operator can appear on only one side of the expression, the side that has information missing. It returns those rows from one table that has no direct match in the other table. A condition involving an Outer Join cannot use IN and OR operator.

18. Explain all Joins used in Oracle 21C and later release?

Cross Join: Cross Join clause produces the cross-product of two tables. This is same as a Cartesian product between the two tables.
Natural Joins: Is used to join two tables automatically based on the columns which have matching data types and names, using the keyword NATURAL JOIN. It is equal to the Equi-Join. If the columns have the same names but different data types, then the Natural Join syntax causes an error.
Join with the USING clause: If several columns have the same names but the data types do not match, then the NATURAL JOIN clause can be modified with the USING clause to specify the columns that should be used for an equi Join. Use the USING clause to match only one column when more than one column matches. Do not use a table name or alias in the referenced columns. The NATURAL JOIN clause and USING clause are mutually exclusive.
Forex: Select a.city, b.dept_name from loc a Join dept b USING (loc_id) where loc_id=10;Joins with the ON clause: Use the ON clause to specify a join condition. The ON clause makes code easy to understand. ON clause is equals to Self Joins. The ON clause can also be used to join columns that have different names.
Left/ Right/ Full Outer Joins: Left Outer Join displays all rows from the table that is Left to the LEFT OUTER JOIN clause, right outer join displays all rows from the table that is right to the RIGHT OUTER JOIN clause, and full outer join displays all rows from both the tables either left or right to the FULL OUTER JOIN clause.

19. Explain the character, number, and date function in detail?

Character functions: accept character input and return both character and number values.

Types of character function are:

a) Case-Manipulation Functions: LOWER, UPPER, INITCAP
b) Character-Manipulation Functions: CONCAT, SUBSTR, LENGTH,INSTR, LPAD/RPAD, TRIM, REPLACE
c) Number Functions: accept Numeric input and return numeric values. Number Functions are: ROUND, TRUNC, and MOD
d) Date Functions: operates on values of the Date data type. (All date functions return a value of DATE data type except the
MONTHS_BETWEEN Function, which returns a number. Date Functions are MONTHS_BETWEEN, ADD_MONTHS, NEXT_DAY,
LAST_DAY, ROUND, TRUNC.

20. What is an alias in SQL statements?

Alias is a user-defined alternative name given to the column or table.By default column, alias headings appear in upper case. Enclose the alias in double quotation marks (“ “) to make it case sensitive. “AS” Keyword before the alias name makes the SELECT clause easier to read.
Forex: Select emp_name AS name from employee; (Here AS is a keyword and “name” is an alias).

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *

Login with your email & password

Sign up with your email & password

Signup/Registration Form

Registred Email:

- Not Updated -

Set/Update Password