Oracle SQL & PL/SQL: SQL Interview Questions

http://sql-plsql.blogspot.com/2009/04/sql-interview-questions.html

Share

Report Abuse

Next Blog»

Create Blog

Sign In

Ads by Google

RSS Feed

SQL Query Interview Questions SQL Server Tutorial Function PL SQL

Oracle SQL & PL/SQL
Oracle SQL SQL Introduction SQL Syntax SQL Select SQL Insert SQL Update SQL Delete SQL Joins SQL Examples of Joins SQL Explicit vs. Implicit Joins SQL Group By SQL Group By Examples SQL Having SQL - IN SQL - NULLs Functional Dependencies Normalization ACID Properties SQL SubQueries SQL - Queries With Examples SQL Views Insert, Update, Delete Views SQL Join Views SQL Inline Views SQL - Nth Highest Salary SQL Second Highest Salary SQL - Difference Truncate / Delete SQL - Difference Truncate / Drop SQL - Difference HAVING / WHERE SQL - Difference CAST / CONVERT SQL - Difference NOT IN / NOT EXIST SQL - Difference IN / EXISTS SQL - Difference UNION / UNION ALL SQL - Difference Nested / Correlated Subquery SQL - REPLACE SQL - TOP SQL - LIKE SQL - SELECT INTO SQL - CREATE TABLE SQL - CREATE TABLE (More Examples) SQL - ALTER TABLE SQL - Difference views / Materialized views SQL Count SQL Update SQL Clustered / Non-Clustered Indexes SQL - Delete Duplicate Records SQL - Difference Unique/Primary Key SQL - GETDATE() SQL - DATEDIFF() SQL - DATEADD() SQL - DATEPART() SQL - Convert() SQL - SUM() SQL - AVG()

SQL Interview Questions
SQL Interview Questions (few questions are repeated with small differences in their answers) What Is SQL? SQL Interview SQL (pronounced as the letters S-Q-L or as sequel) is an abbreviation for Structured Questions Query Language. SQL is a language designed specifically for communicating with databases. SQL is designed to do one thing and do it well—provide you with a simple and efficient way to read and write data from a database. Which command displays the SQL command in the SQL buffer, and then SQL executes it? Interview Questions RUN What is the difference between Truncate & Drop? SQL Interview Answer Questions Explain SQL Having? SQL Interview Answer Questions Difference between SQL Having & Where? SQL Interview Answer Questions Difference between SQL IN/SQL Exists? SQL Interview Answer Questions

1 of 6

10-10-11 6:37 AM

SQL Interview Answer Questions How to delete duplicate records in a table? SQL Interview Answer Questions How to find duplicate records with the number they are duplicated? SQL Interview Questions SELECT Id. Questions What is a FOREIGN KEY? SQL Interview A FOREIGN KEY is one or more columns whose values are based on the PRIMARY Questions or CANDIDATE KEY values from the database.sp_who SQL . Questions What is the difference between UNIQUE and PRIMARY KEY? SQL Interview The UNIQUE KEY column restricts entry of duplicate values but entry of NULL value is Questions allowed.com/2009/04/sql-interview-questions.Default Constraint SQL . SQL Interview Answer Questions Explain SQL Group by and give examples.Insert Multiple Values In Table SQL .Session SQL .html Difference between SQL NOT IN/SQL NOT Exists? SQL Interview Answer Questions Difference between SQL UNION/SQL UNION ALL? SQL Interview Answer Questions Explain SQL TOP.Count_Big SQL .STUFF() SQL .Oracle SQL & PL/SQL: SQL Interview Questions http://sql-plsql. SQL Interview Answer 1 Questions Answer 2 How can you call a PL/SQL procedure from SQL? SQL Interview By use of the EXECUTE (short form EXEC) command. count (*) as num_records from table group by id having count (*) > 1 SQL .Insert Into Select SQL . SQL Interview Answer Questions Difference between Cast & Convert.MAX() SQL .Foreign Key Constraint SQL . Questions Which is the subset of SQL commands used to manipulate Oracle Database SQL 2 of 6 10-10-11 6:37 AM .Not Null Constraint SQL . Difference between Unique Key and Primary Key.Primary Key Constraint SQL .sp_columns SQL .SQL Server Execution Plan SQL Interview Questions Oracle PL/SQL PL/SQL Introduction PL/SQL Procedures PL/SQL Functions PL/SQL Collections PL/SQL Records PL/SQL Table Based Records PL/SQL Programmer Defined Records PL/SQL Cursor Based Records PL/SQL Tables PL/SQL Varrays PL/SQL Nested Tables PL/SQL Loops PL/SQL Triggers PL/SQL Cursors PL/SQL Implicit Cursors PL/SQL Explicit Cursors PL/SQL REF Cursors PL/SQL Cursor For Loop PL/SQL Cursors with Parameters PL/SQL Where Current Of and For Update Examples of PL/SQL Cursors PL/SQL Exceptions PL/SQL Interview Questions SQL PL/SQL Sitemap What is a PRIMARY KEY? SQL Interview The PRIMARY KEY is the column(s) used to uniquely identify each row of a table.Referential Integrity SQL . What is a UNIQUE KEY? SQL Interview A UNIQUE KEY is one or more columns that must be unique for each row of the table.Stored Procedure SQL .Check Constraint SQL . In case of PRIMARY KEY columns entry of duplicate as well as <null> value is also restricted.blogspot.Diff Local/Global Temporary Tables SQL .ROLLUP SQL .Index Include SQL .CUBE SQL .MIN() SQL .Binary_Checksum SQL .Covered Query SQL .Identity SQL .Unique Constraint SQL .Dynamic SQL SQL .Checksum_AGG SQL .

TRUNCATE is a DDL command whereas DELETE is a DML command.html Interview structures? Questions Data Definition Language (DDL) Write a query to select the Nth highest salary from a table. SQL Interview Answer Questions Write a query to select the 2nd highest salary from a table. SQL Interviewmin(salary) AS high5 SELECT Questions FROM employee WHERE salary IN(SELECT DISTINCT TOP 5 salary FROM employee ORDER BY salary DESC) What command is used to get back the privileges offered by the GRANT SQL command? Interview Questions Revoke How do you execute a host operating system command from within SQL? SQL Interview By use of Questions the exclamation point “!” (in UNIX and some other OS) or the HOST (HO) command. however the Questions truncate command can not be rolled back as delete can be. The delete command can be used for selected records using the where clause but with the truncate command we have to loose data. SQL Interview Questions SELECT max(salary) AS salary_2 FROM emp WHERE salary < (SELECT max(salary) AS salary_1 FROM emp) Write a query to select the 5th highest salary from a table. SQL Interview Answer Questions Write a query to select the second highest salary from a table. DELETE statement is a logged operation and hence takes more time then truncate.Oracle SQL & PL/SQL: SQL Interview Questions http://sql-plsql.. AS SELECT command Give examples of Create Table? SQL Interview Answer Questions What is the difference between Delete and Truncate command in SQL? SQL Interview Answer Questions What is the difference between Delete and Truncate command in SQL? SQL Interview Delete command and truncate command both will delete the data.com/2009/04/sql-interview-questions.blogspot. How can variables be passed to a SQL routine? SQL Interview 3 of 6 10-10-11 6:37 AM . What command is used to create a table by copying the structure of another SQL table? Interview Questions CREATE TABLE .

Can Primary key is a Foreign Key on the same table? SQL Interview Yes Questions You want to determine the location of identical rows in a table before SQL attempting to place a unique index on the table. y. What is the use of the DROP option in the ALTER TABLE command? SQL Interview It is used Questionsto drop constraints specified on the table. LOC (VARCHAR2(13) EMPLOYEE EMPNO (NOT NULL .html Questions of the & symbol. For passing in variables the numbers 1-8 can be used By use (&1. This option can be shortened to TERM. a parent table can be dropped even when a child table exists. Which function is used to find the largest integer less than or equal to a SQL specific value? Interview Questions FLOOR Consider the below DEPT and EMPLOYEE table and answer the below queries. DNAME (VARCHAR2(14))..Oracle SQL & PL/SQL: SQL Interview Questions http://sql-plsql. the rowid column.. NUMBER(4)).blogspot. How do you prevent output from coming to the screen? SQL Interview The SET option TERMOUT controls output to the screen.. place the ampersanded variable in the code itself: “select * from dba_tables where owner=&owner_name. how can this be done? Interview Questions Oracle tables always have one guaranteed unique column.rowid) from emp x where x. z correspond to the number of rows in each table involved in the join.&8) to pass the values after the command into the SQLPLUS session. What is a Cartesian product? SQL Interview A Cartesian Questions product is the result of an unrestricted join of two or more tables. What SQLPlus command is used to format output from a select? SQL Interview This is best Questions done with the COLUMN command. &2..” . If you use a min/max function against your rowid and then select against the proposed primary key you can squeeze out the rowids of the duplicate rows pretty quick.emp_no). 4 of 6 10-10-11 6:37 AM . NUMBER(2)).rowid > (select min(x.emp_no = e. What is the use of CASCADE CONSTRAINTS? When this clause is used with the DROP command. The result set of a three table Cartesian product will have x * y * z number of rows where x. Setting TERMOUT OFF Questions turns off screen output. DEPT DEPTNO (NOT NULL . Use of double ampersands tells SQLPLUS to resubstitute the value for each subsequent use of the variable.com/2009/04/sql-interview-questions. For example: select rowid from emp e where e. a single ampersand will cause a reprompt for the value unless an ACCEPT statement is used to get the value from the user. To be prompted for a specific variable.

7.Oracle SQL & PL/SQL: SQL Interview Questions http://sql-plsql. 5. which are inserted. OF EMPLOYEES" FROM EMPLOYEE GROUP BY TO_CHAR(HIREDATE. that already exist) in the EMPLOYEE table. SELECT ENAME. Write a correlated sub-query to list out the Employees who earn more than the average salary of their department.SAL FROM EMPLOYEE E WHERE SAL > (SELECT AVG(SAL) FROM EMPLOYEE F WHERE E. MAX(SAL) FROM EMPLOYEE GROUP BY JOB 3. 5 of 6 10-10-11 6:37 AM . COUNT(EMPNO) "NO.'YYYY')). Select the duplicate records (Records.blogspot.com/2009/04/sql-interview-questions. List the highest salary paid for each job. 6. Find the nth maximum salary.ROWID!=MIN (ROWID)). 1. HIREDATE (DATE). SELECT JOB. DEPTNO (NUMBER(2)) MGR is the EMPno of the Employee whom the Employee reports to.'YYYY') HAVING COUNT(EMPNO) = (SELECT MAX(COUNT(EMPNO)) FROM EMPLOYEE GROUP BY TO_CHAR(HIREDATE.2)). 2. SELECT TO_CHAR(HIREDATE. COMM (NUMBER(7.DEPTNO). SAL (NUMBER(7. JOB (VARCHAR2(9)).html ENAME (VARCHAR2(10)).2)).EMPNO IN (SELECT EMPNO FROM EMPLOYEE GROUP BY EMPNO HAVING COUNT(EMPNO)>1) AND A. List all the Employees who have at least one person reporting to them. Write a query to list the length of service of the Employees (of the form n years and m months). In which year did most people join the company? Display the year and the number of Employees.SAL).DEPTNO = F. SELECT ENAME FROM EMPLOYEE WHERE EMPNO IN (SELECT MGR FROM EMPLOYEE). 4. MGR (NUMBER(4)).'YYYY') "YEAR".SAL<=B. SELECT * FROM EMPLOYEE A WHERE A. SAL FROM EMPLOYEE A WHERE &N = (SELECT COUNT (DISTINCT(SAL)) FROM EMPLOYEE B WHERE A. DEPTNO is a foreign key. SELECT ENAME.

com/2009/04/sql-interview-questions. Home 6 of 6 10-10-11 6:37 AM .html SELECT ENAME "EMPLOYEE".Oracle SQL & PL/SQL: SQL Interview Questions http://sql-plsql.12)))||' MONTHS ' "LENGTH OF SERVICE" FROM EMPLOYEE.HIREDATE)/12)) ||' YEARS '|| TO_CHAR(TRUNC(MOD(MONTHS_BETWEEN (SYSDATE.TO_CHAR(TRUNC(MONTHS_BETWEEN(SYSDATE. HIREDATE).blogspot.