-
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);For Eg:-Enter value for n: 2SAL---------3700
-
-
-
How to retrieve 2nd highest sal in each departement from emp and dept tables using GROUP BY?
EMP table (empno,deptno,sal)
DEPT table(deptno,dname)
i need Deptno, Dname, 2nd_highest_sal_in_dept
in output.
I can easily do this using row_number, Rank,Dense_rank etc but I am unable to do this using Group By.
Please suggest if this can be done using Group By. -
Difference between an implicit & an explicit cursor.
PL/SQL declares a cursor implicitly for all SQL data manipulation statements, including quries that return only one row. However,queries that return more than one row you must declare an explicit cursor or use a cursor FOR loop.Explicit cursor is a cursor in which the cursor name is explicitly assigned to a SELECT statement via the CURSOR...IS statement. An implicit cursor is used for all SQL statements...
-
To get second highest age from the student table
I am trying to get second highest age from the student table.Student table:SQL> desc student; Name Null? Type ----------------------------------------- -------- ----------------- ROLLNO NUMBER NAME VARCHAR2(20) AGE NUMBERAnd...
-
-
Select from table without using column name
How can I select column values from a table without knowing the column name ?Suppose , select employee_id from employees , now I don't know the column name and I want to select the column.Please let me know the answer
-
-
Display Middle Record
How to display middle record in a given table?
-
-
-
HAVING vs WHERE Clause
Where clause restricts rows, what does having clause restricts ?1. only group results.2. rows results.3. both rows and groups result.
-
Rename a Column
How to rename a column in a SQL table?
-
-
There is a % sign in one field of a column. What will be the query to find it?
'' Should be used before '%'.
-
-
-
What is difference between UNIQUE and PRIMARY KEY constraints?
A table can have only one PRIMARY KEY whereas there can be any number of UNIQUE keys. The columns that compose PK are automatically define NOT NULL, whereas a column that compose a UNIQUE is not automatically defined to be mandatory must also specify the column is NOT NULL.
-
What is difference between SQL and SQL*PLUS?
SQL*PLUS is a command line tool where as SQL and PL/SQL language interface and reporting tool. Its a command line tool that allows user to type SQL commands to be executed directly against an Oracle database. SQL is a language used to query the relational database(DML,DCL,DDL). SQL*PLUS commands are used to format query result, Set options, Edit SQL commands and PL/SQL.
Oracle SQL Interview Questions
Ans