RSS Feed for This PostCurrent Article

Oracle Interview Questions-II

Display the records between two range

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

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?

SQL> select nvl(to_char(comm.),’NA’) from emp;
Output :
NVL(TO_CHAR(COMM),’NA’)
———————–
NA
300
500
NA
1400
NA
NA

Oracle cursor : 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.

Explicit Cursor attributes

There are four cursor attributes used in Oracle
cursor_name%Found, cursor_name%NOTFOUND, cursor_name%ROWCOUNT, cursor_name%ISOPEN

Implicit Cursor attributes

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.

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

Trackback URL

  1. 6 Comment(s)

  2. By Shiv on Sep 30, 2007 | Reply

    Very good article.Thanks very much for this.

  3. By divya on Oct 8, 2007 | Reply

    Hello

    For the oracle interview as a fresher which book should i read and which all topics should I cover.

  4. By admin on Oct 8, 2007 | Reply

    @divya

    I can if u want to prepare oracle i can suggest you to use black.

  5. By Aditi on Apr 6, 2008 | Reply

    i was looking for answer to this question “Find out nth highest value from a table” thanks for the post..

  6. By Jayant Singh on Apr 30, 2008 | Reply

    Suppose i hav a table R_PRCT with coloum AMT

    so from this query u can retrive nth highest AMT(amount) from table (R_PRCT)

    SELECT DISTINCT (A.AMT) FROM R_PRCT A WHERE &N = (SELECT COUNT (DISTINCT (B.AMT)) FROM R_PRCT B WHERE A.AMT<=B.AMT)
    /

  7. By Ajay on Jun 11, 2008 | Reply

    Hello,
    This is Ajay, working for IBM.
    I am looking for change, what all area we need to go through for interviews..i am one yesr exp.Thnaks in advance..

Post a Comment