sql interview questions

7
SQL Interview Questions SQL Interview Questions for Fresher’s and experienced whatever i have faced in my Interviews, these sql interview questions are very helpful for the people who are trying to get the job on Oracle SQL, PL/SQL. Explain briefly NVL, NVL2, NULLIF functions I have a table and created two indexes on two columns but i want create 3rd index how you can create an index What is data modelling and how to create relation between A and B tables. Difference between truncate and delete, why truncate faster rather than delete. Difference between view and materialized view What is correlated subquery? What is complex query and have you ever work on that. Difference between btree and bitmap index Difference between Translate and Decode. Difference between Delete and Truncate. Which is faster Case or Decode. Difference between case and decode What are pseudo columns in oracle What is driving table? As a developer how to tune sql query, explain the steps. Can we create a primary key constraint on 2 columns and foreign key on other column is it possible? Create sequence sequence_name; , this sequence generate a sequence value or not. Write a query to find 4th highest salary (without analytical function). 10 records in excel file, i wan to load 8 records only through sql * loader, is it possible. I have created a simple view but there is no base table, what happens. I found bottlenecks in sql statement as below Select * from emp where dept_no in (10,20); Is it possible to change select * from emp where dept_no=10 or dept_no=20; in production? Can we create index on virtual columns. What is invisible column? How many types of partitions, explain interval partition, virtual partitions and Reference Partition.

Upload: nagesh-rao

Post on 12-Apr-2017

22 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Sql interview questions

SQL Interview QuestionsSQL Interview Questions for Fresher’s and experienced whatever i have faced in my Interviews, these sql interview questions are very helpful for the people who are trying to get the job on Oracle SQL, PL/SQL.

Explain briefly NVL, NVL2, NULLIF functionsI have a table and created two indexes on two columns but i want create 3rd index how you can create an indexWhat is data modelling and how to create relation between A and B tables.Difference between truncate and delete, why truncate faster rather than delete.Difference between view and materialized viewWhat is correlated subquery?What is complex query and have you ever work on that.Difference between btree and bitmap indexDifference between Translate and Decode.Difference between Delete and Truncate.Which is faster Case or Decode.Difference between case and decodeWhat are pseudo columns in oracleWhat is driving table?As a developer how to tune sql query, explain the steps.Can we create a primary key constraint on 2 columns and foreign key on other column is it possible?Create sequence sequence_name; , this sequence generate a sequence value or not.Write a query to find 4th highest salary (without analytical function).

10 records in excel file, i wan to load 8 records only through sql * loader, is it possible.I have created a simple view but there is no base table, what happens.I found bottlenecks in sql statement as belowSelect * from emp where dept_no in (10,20);Is it possible to change select * from emp where dept_no=10 or dept_no=20; in production?Can we create index on virtual columns.What is invisible column?How many types of partitions, explain interval partition, virtual partitions and Reference Partition.Can we update complex view, i want to insert, delete and update operation on view, what are the steps of instead of dml operations.What is the purpose of materialized view?I have trying to create a sequence like 1 2 3 4 5 next row i want start 1 2 3 4 5 is it possible?I want to truncate a table before loading data through sql loader is it right way?What is reverse key index.What is hash partition, when you create a hash partition?

Page 2: Sql interview questions

When you create a function based index, why you go for function based index,What is hash join, explain how to use,What is the difference between primary key and unique key,I have create a composite primary key on two columns and inserting on value and null value, is it possible, and create a unique index on other columns, inserting 3 rows and inserting 3 null value on unique column, is it possible.Have you ever create sequence on primary key columnTell me the query to retrieve top 5 salaries in each dept wise using analytical function.Types of materialized view refreshing methodsFast refresh working on complex materialized view,can we create a index on materialized view.what is view and materialized view, types of refreshing methods.have you ever worked on dynamic sql.how to get top 10 salaries from two different tableswrite a query to get more then 2 employees under managerlistaggintersetwhich is the faster left outer join and right outer joinhow to delete duplicate recordswhat is primary and unique constraintin and exist which is the faster, why exist is faster?Write a query to find 3rd highest salary

Using DENSE_RANKSELECT *FROM ( SELECT emp.*,DENSE_RANK() OVER(ORDER BY Sal DESC) Rno FROM EMP )WHERE Rno=3;Using ROWNUM

--------------------------------------------------------------------------SELECT salFROM (SELECT rownum rn, sal FROM ( SELECT DISTINCT sal FROM emp ORDER BY sal DESC ) )WHERE rn = 3;----------------------------------------------------------------------------------------SELECT *FROM empWHERE sal = (SELECT sal

Page 3: Sql interview questions

FROM (SELECT rownum rn, sal FROM ( SELECT DISTINCT sal FROM emp ORDER BY sal DESC ) ) WHERE rn = 3 );Using SELF JOINSELECT *FROM emp aWHERE 3 = (SELECT COUNT(DISTINCT(Sal)) FROM emp b WHERE a.sal<=b.sal )ORDER BY sal;Write a query to find 10 highest salaryCan you write syntax of case statement?Can we create a table on exiting table?How to create a synonym, write syntax of synonymWhat are partitions, when we go for partitions?How to rebuild index, syntax of rebuild indexHow to create a BLOB, syntax of blobWhat is control file, syntax of control file?What truncate and delete?How to check the table or view exiting or notSelect * from a where hiredate+60 < sysdate; (here hiredate is non-unique index, so query scanning index range or full table scanning.Have you worked on explain plan, how to tune sql queryCan you write pivot query? What are analytical functions? Difference between sql *loader and external table, explain requirements for thatHave you ever worked on partitions, explain Virtual column based partitioningwhat is nvl and nvl2 function and examplesExplain about TK-proof , syntax of TK-proofMerge statement syntaxPartition Exchange(One table have 5 partitions like P1...P5, I want to move P5 partition insert into another Table)?Difference between 10g and 11gCOLN---------AAABBBB

Write a query output like as

Page 4: Sql interview questions

coln------34coln-----ABCDEI want output like thisTEXT--------A,B,C,D,EEMPNO ENAME ----------- -----------12345 REDDYI want to count of empno and enamecoln-------1-2-3-10187I want to count of positive and negativeselect sum(decode(sign(value),1,value)) pos, sum(decode(sign(value),-1,value)) neg from pnselect ( select sum(value) from pn where 0<value) as positive, (select sum(value) from pn where 0>value) as negative from dualselect unique ( select sum(value) from pn where 0<value) as positive, (select sum(value) from pn where 0>value) as negative from pnHave you ever created tables, tell me 3 differences between primary key and unique key.Have you ever worked on partitions, why should we go to partitions?Have you ever worked on indexes, what is the default index? Why we can create a Function based index?Have you created Materialized view, what is it?What is the difference between view and materialized view?Difference between import/export and sql loaderWhat is conventional path and direct path, which is the faster?What is the requirement you have used import/export?What are the functions you have worked on every day? What is the usage of decode?Have you ever worked on Analytical functions?COLUMN_NO VALUE----------------------------------------------1 A1 B

Page 5: Sql interview questions

1 C2 A2 B3 A4 A

I want to show the output like as

COLUMN_NO VALUE----------------------------------------------1 A,B,C2 A,B3 A4 A

What is your database version, what are 11g features,How to find duplicate records on table, please find below table.

COL1 COL2----------------------------------------A 1A 2A 3A 4B 5B 6B 7C 8C 9

I want to show the output like as

A B C-----------------------4 3 2

SELECT A1.A,B1.B,C1.C FROM (SELECT COUNT(NAME)A FROM Ta WHERE Name ='A')A1,(SELECT COUNT(NAME)B FROM Ta WHERE Name='B')B1,(SELECT COUNT(Name)C FROM Ta WHERE Name='C')C1

select decode(col1,'A',count(1)) "A",decode(col1,'B',count(1)) "B",decode(col1,'C',count(1)) "C" from table1Group by col1

Select * from( select col1,col2 from table_name ) pivot( count(col2) for col1 in ('A','B','C') );

select count(decode(col1,'A',col2)) A,count(decode(col1,'B',col2)) B,count(decode(col1,'C',col2)) C from r6;

Page 6: Sql interview questions

I have a csv file in outside database, every 10 minutes added new records in csv file. My requirement is load csv file in database, which method you to approach to load csv file to database.If you created primary key which index created and if you created index which constraint created automatically?What is nvl and nvl2?Can you write syntax of decodeCount(*) status-------------------------1 s1 s1 s2 a2 a3 cCan you write a query for this output?Difference between primary and unique and i am retrieving unique column, that time unique column firing or not?Difference between nvl and nvl2