Oracle interview Questions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Qus. 8. To see current user name ?
Ans: SQL> show user;
Qus. 9. Change SQL prompt name ?
Ans: SQL> set sqlprompt “R4R > “
Qus. 0. Switch to DOS prompt ?
Ans: SQL> host
Qus. 1. How do I eliminate the duplicate rows ?
Ans: SQL> delete from table_name where rowid not in (select max(rowid) from
table group by duplicate_values_field_name);
or
SQL> delete duplicate_values_field_name dv from table_name ta where rowid
<(select min(rowid) from table_name tb where ta.dv=tb.dv);
Example.
Table Emp
Empno Ename
101 Scott
102 Jiyo
103 Millor
104 Jiyo
105 Smith
delete ename from emp a where rowid < ( select min(rowid) from emp b where
a.ename = b.ename);
The output like,
Empno Ename
101 Scott
102 Millor
103 Jiyo
104 Smith
Qus. 2. How do I display row number with records?
Ams:To achive this use rownum pseudocolumn with query, like
SQL> select rownum, ename from emp;
Output:
1 Scott
2 Millor
3 Jiyo
4 Smith
Qus. 3. Display the records between two range
Ans: select rownum, empno, ename from emp where rowid in
(select rowid from emp where rownum <=&upto
minus
select rowid from emp where rownum<&Start);
Enter value for upto: 10
Enter value for Start: 7
ROWNUM EMPNO ENAME
--------- --------- ----------
1 7782 CLARK
2 7788 SCOTT
3 7839 KING
4 7844 TURNER
Qus. 4. I know the nvl function only allows the same data type(ie. number or
char or date Nvl(comm, 0)), if commission is null then the text “Not
Applicable” want to display, instead of blank space. How do I write the query?
Ans: SQL> select nvl(to_char(comm.),'NA') from emp;
Output :
NVL(TO_CHAR(COMM),'NA')
-----------------------
NA
300
500
NA
1400
NA
NA
Qus. 5. Oracle cursor ?
Ans: Implicit & Explicit cursors
Oracle uses work areas called private SQL areas to create SQL statements.
PL/SQL construct to identify each and every work are used, is called as
Cursor.
For SQL queries returning a single row, PL/SQL declares all implicit cursors.
For queries that returning more than one row, the cursor needs to be
explicitly declared.
Qus. 6. Explicit Cursor attributes ?
Ans: There are four cursor attributes used in Oracle
cursor_name%Found, cursor_name%NOTFOUND, cursor_name%ROWCOUNT,
cursor_name%ISOPEN
Qus. 7. Implicit Cursor attributes ?
Ans: Same as explicit cursor but prefixed by the word SQL
SQL%Found, SQL%NOTFOUND, SQL%ROWCOUNT, SQL%ISOPEN
Tips : 1. Here SQL%ISOPEN is false, because oracle automatically closed
the implicit cursor after executing SQL statements.
: 2. All are Boolean attributes.
11. 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);
Enter value for n: 2
SAL
---------
3700
Qus. 8. To view installed Oracle version information
Ans: SQL> select banner from v$version;
1 2 3 4 5 6 7 8 9 10 11 12 13
14 15