Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Top queries in SQL

1) Query to display senior most employee details from emp table?


sql> select * from emp where hiredate= ( select min(hiredate) from emp);

2) Query to display second highest salary from emp table?


sql> select max(sal) from emp where sal< ( select max(sal) from emp);

3) Query to display employee details who are getting max salary in each department from emp
table?
sql> select * from emp where (deptno, sal) in ( select deptno, max(sal) from emp group by deptno);

4) Query to display last two rows from emp table?


sql> select * from emp minus select * from emp where rownum<= (select count(*) - 2 from emp);

5) Query to display first row and last row from emp table?
sql> select * from ( select rownum r, ename, sal from emp) where r=1 or r= ( select count(*) from
emp);

6) Query to display even number of records from emp table?


sql> select * from ( select rownum r, ename, sal from emp) where mod(r,2)=0;

7) Query to display 5th highest salary employee from emp table?


sql> select * from ( select rownum r, ename, sal from ( select * from emp order by sal desc)) where
r=5;

8) Query to display nth highest salary employee from emp table?


sql> select * from ( select rownum r, ename, sal from ( select * from emp order by sal desc )) where
r=&n;

9) Query to display first five rows from emp table?


sql> select * from emp where rownum <=5;

10) Query to display first five highest salary employees from from emp table?
sql> select * from ( select * from emp order by sal desc ) where rownum<=5;

11) Query to display second row from emp tablle?


sql> select * from ( select rownum r,ename,sal from emp) where r=2;

12) Query to display 2nd, 3rd, 4th, 5th, 7th, 9th row from emp table?
sql> select * from ( select rownum r, ename, sal from emp)
where r in (2,3,4,5,7,9);
Interview questions for experienced PLSQL Developers

1) when to use cursor and when to use collection?


2) what is triggering events or trigger predicate clauses?
3) can we use DDL, DML commands in PLSQL block?
4) How to trace error line number in PLSQL?
5) what is instead of trigger?
6) what is exception in PLSQL? types of exception?
7) what is cursor for loop?
8) what is pragma exception_init?
9) what is raise_application_error?
10) what is SQL CODE and SQL ERRM?
11) what is exception propagation?
12) what is parameterized cursor?
13) how to handle exception in PLSQL?
14) what is follows clause in trigger?
15) what is mutating error? how to avoid mutating error using compound trigger?
16) what is pragma autonomous_transaction?
17) what are advantages of the packages in oracle?
18) what is use of limit clause in bulk collect?
19) Can we use commit / rollback commands in trigger?
20) what is index by table, nested table, varray diff between them?
21) what is overloading procedure?
22) what is Bulk Exception in PLSQL? what is save exceptions?
23) diff between cursor and refcursor?
24) diff between strong refcursor and weak refcursor?
25) diff between constraints and triggers?
26) what are the types of the triggers?
27) when to use procedure, when to use function?
28) what is cursor? it's types?
29) diff between row level trigger and statement level trigger?
30) diff between cursor and collection?
31) diff between procedure and packages?
32) diff between procedure and function?
33) what is DDL trigger or system trigger?
34) diff between index by table, nested table, varray

Diff between LONG and LOB datatype

LONG
1) It can store up to 2GB data.
2) Table can have only one long column.
3) Subquery can not select a LONG datatype.
4) LONG datatype does not work with regular expressions.

LOB
1) It can store up to 4GB data.
2) Table can have more than one LOB columns.
3) Subquery can select LOB column.
4) CLOB datatype work with regular expressions.

Interview questions for freshers ( Oracle-PLSQL Developers )

1) Diff between procedures and functions?


2) What is trigger? Types of trigger?
3) Diff between index by table, nested table and varray?
4) What are the exceptions in PLSQL?
5) What is cursor? Types of cursor?
6) What is SQLCODE, SQLERRM?
7) Explain pragma exception INIT?
8) What is raise_application_error?
9) Diff between cursor and collection?
10) What are the cursor attributes?
11) What is instead of trigger, compound trigger?
12) How to trace line number at which error is occur?
13) What are the packages? Advantages of packages?
14) What are the variable attributes?
15) What is dynamic SQL?
16) Explain SQL Loader?
17) What is external table?
18) Diff between static cursor and refcursor?
19) What is cursor for loop?
20) What is Autonomous transactions?
21) What is refcursor? Types of refcursor?
22) Explain utl file package?
23) What is mutating error?
24) What is Large Objects?
25) What is parameterized cursor?
26) Can we use DML Statements in functions?
27) What is overloading procedure?
28) What is bulk bind process?
29) Explain DDL trigger?
30) Diff between row level trigger and statement level trigger?

Query running slow what will be approach?

1) There could have lot of DML's would have happened recently. Hence statistics might be outdated.
Since oracle engine generates the explain plan based on the available statistics information chances
are there that it might comes with wrong execution plan because of the outdated statistics.

2) Because of the lot of DML operations chances are there that data in the underlying tables would
have drastically changed which might impact on the access path.
e.g. Till yesterday it was using index for access tables but suddenly from today because of the huge
volume of the data or because of huge drastic changes in data it started using full table scan.

3) Chances are there that indexes on underlying base tables have been dropped.

4) Any database parameter have modified recently because few database parameters have direct
impact over execution of the query.

5) We need to check whether any background process is running at the time of query execution.

6) Is there any scheduled job which is executing in the system where database is installed. This will
affect performance of overall database activity.

7) Chances are there that suddenly huge increase in number of online users to the application which
will increase in number of transaction in the database which will impact query performance.

8) We need to check is there any version is upgraded or any data migration activity is happen.

9) Is there any network issue which affect data transmission.

10) Is the database memory usage is perfect.

11) Is the database machine is performing good.

12) Always keep check is there any change in execution plan.

You might also like