Solved

order by in subquery

Posted on 2009-07-01
6
1,684 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 74

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 74

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 74

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to take different types of Oracle backups using RMAN.

809 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