Updated June 15, 2023
Introduction to Oracle Interview Questions
It’s a must for everyone to learn SQL. The demand for SQL is yet to decrease, and SQL expertise is highly valued in the market. Many vendors provide database solutions, with Oracle being the world’s most famous for executing OLTP (Online Transaction Processing) and DW (Data Warehousing).
So if you have finally found your dream job in Oracle but are wondering how to crack the Oracle Interview and what could be the probable Oracle Interview Questions for 2023, every interview is different, and the job scope is different too. Keeping this in mind, we have designed the most common Oracle Interview Questions and answers for 2021 to help you get success in your interview.
This article will cover the most common 2023 Oracle Interview Questions primarily asked in an interview.
Part 1 – Oracle Interview Questions (Basic)
This first part covers basic Oracle interview questions and answers
1. Find the error from the below SQL Query?
Answer:
SELECT Name, YEAR(BirthDate) AS BirthYear
FROM StudentDetails
WHERE BirthYear >= 1998;
This query will throw an error on the WHERE clause. Although an alias is specified in the SELECT clause, it is not visible in the WHERE clause. The correct code can be written as follows:
SELECT Name, YEAR(BirthDate) AS BirthYear
FROM StudentDetails
WHERE YEAR(BirthDate) >= 1998;
2. What is Semijoin? How to implement it in SQL?
Answer:
Semijoin returns records from the left table which match the right table. Even if multiple matching records exist on the right table, the Semijoin returns a single record of the left table. It prevents duplications. Semijoin can be implemented using the WHERE EXISTS clause.
3. What is PL/SQL?
Answer:
PL/SQL is a procedural language extension over SQL provided by Oracle. It facilitates the declaration of variables, functions, and conditional operators in SQL syntax, thereby giving the developer more freedom and ease to design complex queries.
Let us move to the next Oracle Interview Questions.
4. How to handle errors in PL/SQL?
Answer:
In PL/SQL, an error condition is called an exception, and PL/SQL errors are handled using the EXCEPTION block. The syntax for handling exceptions is written below:
DECLARE
...
BEGIN
...
EXCEPTION
WHEN exception1 THEN
...
WHEN exception2 THEN
...
WHEN others THEN
...
END;
5. What are the constraints? How to add a named PRIMARY KEY constraint in SQL?
Answer:
These are the most common Oracle Interview Questions asked in an interview. Constraints are the rules defined over data. Named constraints for a primary key can be added in two ways:
1. During table creation:
CREATE TABLE Employees (
Eid int NOT NULL,
Name varchar(255) NOT NULL,
Salary number(8),
Age int,
CONSTRAINT PK_ID PRIMARY KEY (Eid)
);
2. In the Alter statement
ALTER TABLE Employees
ADD CONSTRAINT PK_ID PRIMARY KEY (Eid);
6. What are savepoints?
Answer:
Savepoints are like markers. When executing a long transaction, it is a good programming practice to set up periodic savepoints to roll back to the save point in case the transaction fails.
Let us move to the next Oracle Interview Questions.
7. What is BLOB?
Answer:
BLOB is a binary large object datatype. It stores unstructured data such as video, audio, or image. The maximum capacity of a BLOB is 4GB-1 in Oracle.
Part 2 – Oracle Interview Questions (Advanced)
Let us now have a look at the advanced Oracle Interview Questions.
8. Find the error in the below code snippet if any?
Answer:
SELECT student_id s_id, student_name name, birthdate date, student_number s_no FROM students;
Here, a reserved keyword, ‘date’ has been used as an alias for the column birthdate. This action is illegal in Oracle SQL. In order to set a reserved keyword as an alias, we can use quotation marks.
SELECT student_id s_id, student_name name, birthdate “date”, student_number s_no FROM students;
9. Write a query to display a list of tables owned by the user.
Answer:
The query can be written as:
SELECT tablespace_name, table_name FROM user_tables;
10. What is dynamic SQL? When to use dynamic SQL?
Answer:
Dynamic SQL is an enhancement over static SQL. It enables writing SQL queries at run-time. It comes into the picture when we need to customize SQL queries during execution.
Here are a few common cases where Dynamic SQL can be utilized:
- If database objects do not exist at compile time, we can use dynamic SQL to reference them.
- Dynamic SQL can be used for executing Dynamic PL/SQL block. By using EXECUTE IMMEDIATE clause, PL/SQL calls can be determined at runtime.
11. What is a database trigger? How to create it?
Answer:
A database trigger is a stored PL/SQL block. We can choose to enable or disable it using the ENABLE and DISABLE clauses of the ALTER TABLE or ALTER TRIGGER statement.
Let us move to the next Oracle Interview Questions.
12. Tell me about set operations in SQL?
Answer:
The UNION operator combines the result of two or more SQL queries and returns the result without duplication. The UNION ALL operators work the same as the UNION operator while keeping duplicate records. The INTERSECT operator returns the results which are common to all the queries. The MINUS operator returns results that are unique to the first query and not present in the second query.
13. What is the answer to the below query? Additionally, implement a correction so that the query below behaves as expected.
Answer:
SELECT CASE WHEN NULL = NULL THEN 'equals' ELSE 'not equals' END AS ANSWER FROM DUAL;
The answer to this query is “not equals”. This is because NULL in SQL is checked for equality using the IS operator.
The modification to the above query so that it evaluates the equality condition correctly is as follows:
SELECT CASE WHEN NULL IS NULL THEN 'equals' ELSE 'not equals' END AS ANSWER FROM DUAL;
14. What is the purpose of COALESCE and NVL functions?
Answer:
Both functions are used to check for nulls in a specified column and replace it with a different value in case the null check is successful.
Sample usage:
SELECT NVL(null, 12) FROM DUAL;
SELECT COALESCE(null, null, 12) FROM DUAL;
The COALESCE function can take multiple arguments, while NVL takes two arguments.
15. What is the use of the HAVING clause?
Answer:
HAVING clause limits the aggregated queries. After performing aggregation using the GROUP BY clause, we can use the HAVING clause to add additional conditions to the result.
Final Thoughts
Here, we have covered questions focused not only on the fundamentals of SQL programming but also on theoretical understanding. A quick look at this article should make you better understand what to expect during an interview.
Recommended Article
We hope that this EDUCBA information on “Oracle Interview Questions” was beneficial to you. You can view EDUCBA’s recommended articles for more information.