Oracle SQL and PLSQL Interview Questions and Answers
Oracle SQL and PLSQL Interview Questions and Answers
1. What is Normalization?
Ans: Normalization is the process of organizing the tables to remove the redundancy. There
are mainly 5 Normalization rules.
1st Normal Form: A table is said to be in 1st normal form when the attributes are atomic and
there is no repeating groups
2nd Normal Form: A table is said to be in 2nd Normal Form when it is in 1st normal form and all
the non-key columns are functionally dependant on the primary key. .
3rd Normal Form: A table is said to be in 3rd Normal form when it is in 2nd normal form and all
non key attributes not dependant transitively.
4th Normal Form: A table is said to be in 4th normal form when it is in 3rd normal form and has
no multi -valued dependencies.
5th Normal Form: A table is said to be in 5th normal form when it is in 4th normal forma and
every join dependency for the entity is a consequence of its candidate keys.
3. What are the DDL Commands and the Purpose of these commands?
DDL (Data Definition Language) command is used for defining the structure of the
Data. DDL Statements are auto commit.
CREATE - to create objects in the database
ALTER - alters the structure of the database
DROP - delete objects from the database
TRUNCATE - remove all records from a table, including all spaces allocated for the
records are removed
COMMENT - add comments to the data dictionary
RENAME - rename an object
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
9. What is NULL?
NULL in Oracle is an Absence of information. A NULL can be assigned but not evaluated
by it self also.
NULL not equal to null
NULL Can not be Not equal to NULL (Neither Equal Not Not Equal)
NULL Does not equal to empty String or doe not equal to ZERO.
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
3) OUTER JOIN:
In EQUI JOIN rows that does not satisfy specified condition would not be displayed. Example:
consider EMO and DEPT table as Example
DEPTNO 40 is not displayed in the Equi example because there are no employees in it. If we
want to diplay its detail also then we have to use OUTER JOIN.Otherwise OUTER JOIN is
imilar to EQUI JOIN except for the difference it uses outer join (+) operator. (A plus within
parenthesis) towards the side not having required data. Outer join operator will substitute null
values when there are no values available.
SQL> SELECT E.DEPTNO,ENAME,DNAME FROM EMP E , DEPT D
2 WHERE E.DEPTNO (+) = D.DEPTNO;
4) SELF JOIN:
When we join a table to itself it is called self join.To join a table itself means that each row of
the table is combined with itself and with every other row of the table. The self join can be seen
as join of two copies of the same table.
SQL> SELECT E.ENAME,M.ENAME FROM EMP E,EMP
WHERE E.MGR=M.EMPNO;
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
SUBQUERY :
A query within another quey. A select statement whose output is substituted in the
condition of another select statement .(A query is a statement written for returning specific
data). The subquery is executed only once. A subquery is enclosed in parenthesis.
EX: SQL> SELECT ENAME FROM EMP
WHERE DEPTNO = (SELECT DEPTNO FROM EMP
WHERE ENAME = 'SMITH');
CORRELATED QUERY:
In a correlated subquery the table used in outer query refers to the table used in the
inner query. The correlated subquery is executed repeatedly once
for each row of the main query table.
Query to display name of highest salary taker.
SQL> SELECT EMPNO, ENAME FROM EMP A
WHERE 1 > (SELECT COUNT (*) FROM EMP B
WHERE A.SAL < B.SAL)
20. You are updating the table, you ask some another user to logon to database to check your
changes before you issue the commit command ? Can he see the changes done by you?
Another user can’t see the the changes done by you until you have given commit.
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
24. What are the Difference between UNION and UNION ALL?
UNION Query displays the Unique rows ( No duplicate rows)
UNION ALL Query displays the Duplicate rows also.
25. If you a Table A, You want to create table B having the same fields in TABLE A ? That
means you have to copy only structure not the data?
CREATE TABLE TABLEB AS (SELECT * FROM TABLE A where 1=2);
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
A pseudocolumn behaves like a table column, but is not actually stored in the table. You can
select from pseudocolumns, but you cannot insert, update, or delete their values. This section
describes these pseudocolumns:
* CURRVAL
* NEXTVAL
* LEVEL
* ROWID
* ROWNUM
Rowid
Rowid is pseudo column that uniquely identifies a row with in the table but not with in the database.
It is possible for two rows of different tables stored in the same cluster have the same row id.
Connect By Prior
A condition that identifies the relationship between parent rows and child rows of the
heirarchy.
Level
For each row returned by heirachical query the level pseudo columns returns 1 for root row , 2
for child row of the root and so on.
It is Best to use CASE Statement when comparing ranges or more complex logic
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
A common use for inline views in oracle sql is to simplify the complex queries by removing
join operations and condensinfg several separate queries into single query.
37. What are Constraints? And what are the constraint Types?
Constraints Enforced rules at the table level.
Constraints prevent the deletion of a table if there are decencies.
NOTNULL:
Ensures the null values are not permitted for the column. Defined at column Level.
CREATE TABLE Tablename( Empname VARCHAR2(10) NOTNULL)
UNIQUE:
Not allow already existing value
Is defined either table level or column level
PRIMARY KEY:
Doesn’t allow Nulls and already existing values.
CREATE TABLE T1( X1 NUMBER,
X2 VARCHAR2(10),
CONSTRAINT x2_UK PRIMARY KEY(X2))
FOREIGN KEY:
Foreign Key defines the column in the child table at table constraint level.
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
REFERENCES TABLE2(field2))
CHECK
Defines a condition that each row must satisfy
CONSTRAINT emp_salary CHECK(SAL>0)
If view is complex View and View contains the following then we can’t modify
the view
--GROUP Functions
-- A Group By clause
-- DISTINCT Keyword
-- Not null columns in Base table that are not selected by View
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
1) 2 rows selected
2) No rows selected
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
56. What is the difference Between Primary Key and Unique Key?
Primary Key Unique Key
You can have only one primary key in a You can have more than one Unique key
table in a table
Primary disallows the duplicates and Unique key disallows only duplicates, it
Nulls also accepts the Nulls.
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
PL/SQL:
1. What is the difference between %TYPE and %ROWTYPE?
%TYPE : It provides the datatype of a variable or database column
%ROWTYPE : It provides the record type that represents a row in a table.
Syntax:
TYPE type_name AS TABLE OF element_type
Ex:
CREATE TYPE Stulist AS TABLE OF VARCHAr2(10)
/
CREATE TYPE student AS OBJECT (
id NUMBER,
name VARCHAR2(10),
stuinfo stulist)
5. What is VARRY?
Varrays allow you to associate a single identifier with an entire collection.
Varray has the maximum size which you must specify in its type definition.
Syntax:
TYPE type_name AS VARRAY(size limit) OF element_type
Ex:
CREATE TYPE Stulist AS VARRAY(50) OF VARCHAr2(10)
/
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
Syntax :
TYPE type_name IS TABLE OF element type
INDEX BY BINARY_INTEGER
Associated Arrays are appropriate for relatively small lookup tables where the
collection can be constructed in memory each time a procedure is called or Package is
initialized. These are good for collecting information whose value is unknown before hand,
because there is no fixed limit on their size.
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
FOR c1 in C2 LOOP
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
Var1 =c2.ename;
Var2 = c2.empno;
END LOOP;
16. What is the difference between OPEN-FETCH-CLOSE and FOR LOOP in CURSORS?
FOR LOOP in CURSOR:
A cursor FOR loop implicitly declares its loop index as a %ROWTYPE record, opens
a cursor, repeatedly fetches rows of values from the result set into fields in the record, and
closes the cursor when all rows have been processed.
OPEN-FETCH-CLOSE:
Explicitly we have to open the query and closing the query.
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
BEGIN
executable statements
[EXCEPTION
exception handlers]
END [name];
Ex: update_sal(empnum,sal);
Variables declared in subprogram specification and referenced in the subprogram body
are formal parameters.
Ex: PRCODURE update_sal(empnum number,sal number)
Positional Notation :
Acc_update(acct,amt);
Named Notation : acc_update(amount =>amt, acct_no => acct);
Or
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
Acc_update(acct_no=>acct,amount=>amt);
Mixed Notation:
Positional Notation must precede named notation. And the reverse notation is not
allowed.
Acc_update(acct,amount => amt);
35. What are the Parameter Modes and what is the default parameter mode?
Parameter Modes are IN,OUT,INOUT
IN parameter is the default parameter mode.
36. In Parameter modes which are pass by Reference and Pass by Value?
Pass By Reference : IN
Pointer to the actual parameter is passed to the corresponding formal
parameters. Both Parameters use the same memory location.
39. What is PL/SQL Package? And what are the parts of the package?
Package groups logically related PL/SQL types, procedures, functions.
Package having the two parts: Package specification and Package Body.
When you call the Packaged Procedure for the first time ,the whole package is
loaded in to memory. So later calls to related subprograms in the package require no disk I/O.
Packages stop cascading dependencies and thereby avoid unnecessary
recompiling.
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
42. Which Package can we use to display the output from the PL/SQL blocks or
subprogram?
DBMS_OUTPUT
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
50. What is the difference Between Row Level Trigger and Statement Level Trigger?
Row level trigger executes once for each row after (or before) the event. This is defined
By using FOR EACH ROW
Statement Level trigger executes once after (or before) the event, independent how
many rows are affected by the event.
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
55. Can we give the Commit and Roll back in side the Trigger?
NO
RAJU CHINTHAPATLA
Oracle SQL and PL/SQL Interview Questions and Answers OracleApps88
ROW LEVEL
Each row in the table locked individually
TABLE LEVEL
Entire Table Locked
Plsql Tables
Plsql table is one dimentional, unbounded, collection of elements indexed by binary interger.
plsql table can have only one column,it is similar to one dimentional array.
it is onbounded there is no predefined limit of the number od rows in plsql table.
The plsql table is in this way very different from aray.
plsql table can have only single column, all rows in plsql table contain of the values of same data type.
Indexed by binary integer
Plsql tables correctly supports a single index mode by binary integer.
This number acts as primary key od plsql table.
You can’t commit information to plsql table or rollback changes from the table.
You can’t select from plsql table.
You can’t isssue DML statemts.
Materialiazed Views
It is special kind of views which physically exists inside the database,it can contain joins or aggragate
functions to improve performances .
The existances of materiliazed views is transparent to sql applications,so DBA can create or drop
materiliazed views of any time without affecting the sql applications.
RAJU CHINTHAPATLA