RSS Feed for SQL Interview QuestionsCategory: SQL Interview Questions

What is the difference between Truncate and Delete interms of Referential Integrity? »

DELETE removes one or more records in a table, checking referential Constraints (to see if there are dependent child records) and firing any DELETE triggers. In the order you are deleting (child first then parent) There will be no problems. TRUNCATE removes [...]

What are steps required tuning this query to improve its performance? »

-Have an index on TER_MASTER.REPNO and one on ERMAST.REPNO
-Be sure to get familiar with EXPLAIN PLAN. This can help you determine the execution
path that Oracle takes. If you are using Cost Based Optimizer mode, then be sure that
your statistics on TER_MASTER are up-to-date. -Also, you can change your SQL to:
SELECT a.* FROM ter.ter_master a WHERE [...]

How to Select last N records from a Table? »

select * from (select rownum a, CLASS_CODE,CLASS_DESC from clm) where a > ( select (max(rownum)-10) from clm) Here N = 10
The following query has a Problem of performance in the execution of the following
query where the table ter.ter_master have 22231 records. So the results are obtained
after hours.
Cursor rem_master(brepno VARCHAR2) IS
select a.* [...]

How to implement ISNUMERIC function in SQL *Plus ? »

Method 1:
Select length (translate(trim (column_name),’+-.0123456789′,”))from dual;
Will give you a zero if it is a number or greater than zero if not numeric
(actually gives the count of non numeric characters)
Method 2:
select instr(translate(’wwww’,’abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ’,’XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX’),’X’) FROM dual;
It returns 0 if it is a number, 1 if [...]

A stored function must return a value based on conditions that are determined at runtime. Therefore, the SELECT statement cannot be hard-coded and must be created dynamically when the function is executed. Which Oracle supplied package will enable this feature? »

1. DBMS_DDL
2. DBMS_DML
3. DBMS_SYN
4. DBMS_SQL

What occurs if a procedure or function terminates with failure without being handled? »

1. Any DML statements issued by the construct are still pending and can be committed or rolled back.
2. Any DML statements issued by the construct are committed
3. Unless a GOTO statement is used to continue processing within the BEGIN section,the construct terminates.
4. The construct rolls back any DML statements issued and returns the [...]

Which Oracle supplied package can you use to output values and messages from database triggers, stored procedures and functions within SQL*Plus? »

1. DBMS_DISPLAY
2. DBMS_OUTPUT
3. DBMS_LIST
4. DBMS_DESCRIBE

Procedure and Functions are explicitly executed. This is different from a database trigger. When is a database trigger executed? »

1. When the transaction is committed
2. During the data manipulation statement
3. When an Oracle supplied package references the trigger
4. During a data manipulation statement and when the transaction
is committed