Solved

order by in subquery

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

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
oracle 10G 5 48
Case Statement in SQL Delminted Query 9 56
Oracle RMAN Database Restore 5 32
PAYER_ID has both atributes 4 19
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
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…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

760 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

19 Experts available now in Live!

Get 1:1 Help Now