Solved

order by in subquery

Posted on 2009-07-01
6
1,687 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

730 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