List of Top Oracle Interview Questions
List of Top Oracle Interview Questions
Syntax:
ALTER TABLE CHILD_T1 ADD CONSTRAINT CHILD_PARENT_FK REFERENCES
PARENT_T1 (COLUMN1) ON DELETE CASCADE;
Q #10) What is an NVL function? How can it be used?
Answer: NVL is a function that helps the user to substitute value if null is
encountered for an expression.
It can be used as the below syntax.
NVL (Value_In, Replace_With)
Q #11) What is the difference between a Primary Key & a Unique
Key?
Answer: Primary Key is used to identify each table row uniquely, while a
Unique Key prevents duplicate values in a table column.
Given below are a few differences:
The primary key can be only one on the table while unique
keys can be multiple.
The primary key cannot hold a null value at all while the
unique key allows multiple null values.
The primary key is a clustered index while a unique key is a
non-clustered index.
Q #12) How TRANSLATE command is different from REPLACE?
Answer: TRANSLATE command translates characters one by one in the
provided string with the substitution character. REPLACE command will
replace a character or a set of characters with a complete substitution
string.
For Example:
TRANSLATE (‘Missisippi’,’is’,’15) => M155151pp1
REPLACE (‘Missisippi’,’is’,’15) => M15s15ippi
Q #13) How can we find out the current date and time in Oracle?
Answer: We can find the current date & time using SYSDATE command in
Oracle.
Syntax:
SELECT SYSDATE into CURRENT_DATE from dual;
Q #14) Why do we use COALESCE function in Oracle?
Answer: COALESCE function is used to return the first non-null expression
from the list of arguments provided in the expression. There must be a
minimum of two arguments in an expression.
Syntax:
COALESCE (expr 1, expr 2, expr 3…expr n)
Q #15) How will you write a query to get 5th RANK students from
the table STUDENT_REPORT?
Answer: The query will be as follows:
SELECT TOP 1 RANK
FROM (SELECT TOP 5 RANK
FROM STUDENT_REPORT
ORDER BY RANK DESC) AS STUDENT
ORDER BY RANK ASC;
Q #16) When do we use the GROUP BY clause in SQL Query?
Answer: GROUP BY clause is used to identify and group the data by one
or more columns in the query results. This clause is often used with
aggregate functions like COUNT, MAX, MIN, SUM, AVG, etc.
Syntax:
SELECT COLUMN_1, COLUMN_2
FROM TABLENAME
WHERE [condition]
GROUP BY COLUMN_1, COLUMN_2
Q #17) What is the quickest way to fetch the data from a table?
Answer: The quickest way to fetch the data would be to use ROWID in
the SQL query.
Q #18) Where do we use DECODE and CASE Statements?
Answer: Both DECODE & CASE statements will function like IF-THEN-ELSE
statements and they are the alternatives for each other. These functions
are used in Oracle to transform the data values.
For Example:
DECODE Function
Select ORDERNUM,
DECODE (STATUS,'O', ‘ORDERED’,'P', ‘PACKED,’S’,’SHIPPED’,’A’,’ARRIVED’)
FROM ORDERS;
CASE Function
Select ORDERNUM
, CASE (WHEN STATUS ='O' then ‘ORDERED’
WHEN STATUS ='P' then PACKED
WHEN STATUS ='S' then ’SHIPPED’
ELSE ’ARRIVED’) END
FROM ORDERS;
Both the commands will display order numbers with their
respective status as,
If,
Status O= Ordered
Status P= Packed
Status S= Shipped
Status A= Arrived
%TYPE is used for declaring a variable that needs to have the same data
type as of a table column.