Solved

order by in subquery

Posted on 2009-07-01
6
1,673 Views
Last Modified: 2013-12-11
  CURSOR amd
   IS
      SELECT   SID, NAME, phoneno, CLASS
          FROM (SELECT ROWNUM c, SID, NAME, CLASS, phoneno
                  FROM student
                 WHERE CLASS = :classes AND branch = :student.br
                       AND edate IS NULL)
         WHERE c <= 20
      ORDER BY SID;

is working fine in forms 6i.
but i want ORDER BY IN subquery

   CURSOR amd
   IS
      SELECT   SID, NAME, phoneno, CLASS
          FROM (SELECT ROWNUM c, SID, NAME, CLASS, phoneno
                  FROM student
                 WHERE CLASS = :classes AND branch = :student.br
                       AND edate IS NULL order by SID)
         WHERE c <= 20;
In SQL*Plus both working fine but in forms the 2nd creates problems

I know it is odd to use order by in subquery but i need it here because of rownum
any solutions
0
Comment
Question by:leoahmad
  • 3
6 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 250 total points
ID: 24763954
oracle forms 6i and lower has its own sql and pl/sql parser which doesn't support everything the server does

in any case you will probably want another level of nesting your subqueries
because ROWNUM is applied before order by.
If you want your data ordered then numbered try this...

CURSOR amd
   IS
      SELECT   SID, NAME, phoneno, CLASS
          FROM (SELECT ROWNUM c,  sid,name,class,phoneno from
                   (select SID, NAME, CLASS, phoneno
                  FROM student
                 WHERE CLASS = :classes AND branch = :student.br
                       AND edate IS NULL order by SID))
         WHERE c <= 20;

In order to get your cursor to work in forms you will either have to put it in a server side pl/sql block and return it as  reference cursor or you will need to use dynamic sql so the server will parse it instead of the form.
Or, wrap query in a view on the server side and query it.  Note, that will likely preclude your parameters.  Unless you write it with analytics


0
 
LVL 14

Author Comment

by:leoahmad
ID: 24777160
No, it still acts as a sub-query.

??
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 24784902
yes, that was just an example illustrating the fix for the problem with your order by and rownum usage.

To solve the subquery problem you will have to follow one of the other suggestions.
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 25008654
http:#24763954  answers the question.  bulk of it explains what is wrong, last two lines provide alternatives for forms limitations
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now