Oracle SQL Interview Questions and Answers

What is SQL?
Structured Query Language (SQL) is a language that provides an interface to relational database systems. The proper pronunciation of SQL is "sequel". SQL was developed by IBM in the 1970.
Difference between TRUNCATE, DELETE and DROP commands?

DELETE command is used to remove some or all rows from a table. A WHERE clause can be used to only remove some rows. If no WHERE condition is specified, all rows will be removed. After performing a DELETE operation you need to COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. Note that this operation will cause all DELETE triggers on the table to fire.

TRUNCATE removes all rows from a table. The operation cannot be rolled back and no triggers will be fired. As such, TRUNCATE is faster and doesn't use as much undo space as a DELETE.

DROP command removes a table from the database. All the tables' rows, indexes and privileges will also be removed. No DML triggers will be fired. The operation cannot be rolled back.

DROP and TRUNCATE are DDL commands, whereas DELETE is a DML command. Therefore DELETE operations can be rolled back (undone), while DROP and TRUNCATE operations cannot be rolled back.

DELETE will not free up used space within a table. This means that repeated DELETE commands will severely fragment the table and queries will have to navigate this "free space" in order to retrieve rows.

How does one eliminate duplicates rows from a table?

Choose one of the following queries to identify or remove duplicate rows from a table leaving only unique records in the table:

Delete from table_name where rowid not in (select max(rowid) from table group by duplicate_values_field_name);
What the difference between UNION and UNIONALL?
Union will remove the duplicate rows from the result set while Union all doesn't.

How to Change a SQL prompt name?
SQL> set sqlprompt "oracle >" oracle >
Find out nth highest salary from emp table?
SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);
What is the difference between VARCHAR, VARCHAR2 and CHAR data types?

CHAR should be used for storing fixed length character strings. String values will be space/blank padded before stored on disk. If this type is used to store variable length strings, it will waste a lot of disk space. 

VARCHAR Currently VARCHAR behaves exactly the same as VARCHAR2. However, this type should not be used as it is reserved for future usage. 

VARCHAR2 is used to store variable length character strings. The string value's length will be stored on disk with the value itself.

What is difference between Co-related sub query and nested sub query?

Correlated sub query runs once for each row selected by the outer query. It contains a reference to a value from the row selected by the outer query.

Select e1.empname, e1.basicsal, e1.deptno
from emp e1
where e1.basicsal = (select max (basicsal)
from emp e2
where e2.deptno = e1.deptno)

Nested sub query runs only once for the entire nesting (outer) query. It does not contain any reference to the outer query row.

Select empname, basicsal, deptno
from emp
where (deptno, basicsal) in
(select deptno, max (basicsal)
from emp
group by deptno)
What are the more common pseudo-columns?
its associated with table but its a not a part of the table. for example SYSDATE, USER, UID, CURVAL, NEXTVAL, ROWID, ROWNUM
What is the difference between group by and order by?
Group by controls the presentation of the rows, Order by controls the presentation of the columns.
What keyword does an SQL SELECT statement use for a string search?
The LIKE keyword used for string searches. The % sign is used as a wildcard and _ for single.
What are various constraints / Integrity Constraints used in SQL?

Data integrity allows defining certain data quality requirements that the data in the database needs to meet.

Five type of constraints :-

Primary key uniquely identifies each record in the table.
Unique Key uniquely identifies each record in a database table. but may be null.
Foreign Key is a field (or fields) that points to the primary key of another table. The purpose of the foreign key is to ensure referential integrity of the data.
Not Null enforces a column to NOT accept NULL values
Check allows stating a minimum requirement for the value in a column.

Latest Updates

Trigonometry

What is the value of cot 4π/3 ?

Indian Politics

Article-24 of the Indian Constitution ‘Prohibition of employment of children in factories, etc’ deals with?

Article-134A of the Indian Constitution ‘Certificate for appeal to the Supreme Court’ deals with?

Chemistry

Who invented Aspirin?

Physics

A larger force on a rotating body results in larger?

What is the unit of the physical quantity, magnetic flux density?

Algebra

The system of equations 2x + 4y = 6 and 4x + 8y = 8 is ?

Time and Distance

A thief is spotted by a policeman from a distacne of 100 m. When the policeman starts the chase, the thief also starts running. If the speed of the theif is 8 km / hour and that of the policeman is 10 km/hour, then how far will the theif have to run before he is overtaken?

Algebra

Aman and Alok attempted to solve a quadratic equation. Aman made a mistake in writing down the constant term and ended up in roots (4, 3). Alok made a mistake in writing down the coefficient of x to get roots (3, 2). The correct roots of the equation are?

Compound Interest

The effective annual rate of interest corresponding to a nominal rate of 22% per annum payable half-yearly is?

Volume and Surface Area

If the volume of a cylinder is 2156 cubic cm and height is 14 cm, find its radius?

Algebra

What is the equation of the line which passes through the points (2, 3) and (- 4, 1)?

Triangles

In △ABC, the angle bisector of ∠A cuts BC at E. Find length of AC, if lengths of AB, BE and EC are 9 cm, 3.6 cm and 2.4 cm?

In a triangle, the length of the opposite side of the angle which measures 45° is 8√2 cm, what is the length of the side opposite to the angle which measures 90°?

General Knowledge of India

The boundary line between India and Pakistan is called?

Which city is located on the banks of the river Mahanadi?

Indian History

When was the battle of Haldighati fought?

In 1498, which Portuguese explorer discovered a new sea route from Europe to India?

General Knowledge of India

Chapchar Kut is a festival of which State?

Chemistry

In chemistry, soap is a salt of a ?

Indian Economy

Which of the following is a Direct tax?

Biology

Sauria lacertidae is the scientific name of?

Which of the following is a primary function of haemoglobin?

Average

A factory buys 8 machines.3 Machine A, 2 Machine B and rest Machine C. Prices of the machines are 100000, 80000 and 45000 respectively.Calculate the average cost of these machines?

Discount

Ticket for an adult is 500 and a child is 200. 1 child goes free with two adults. If a group has 20 adults and 8 children what will be the discount the group get?