Pro*C sql query to retrive n'th row in sorted order??

when i compile this embedded sql with oracle 8.1.6 Pro*C compiler in SUN-SOLARIS environment. I am getting the following error.

EXEC SQL select min(mobile_id), max(mobile_id) into :FromMIN INDICATOR :FromMINInd, :ToMIN INDICATOR :To
MINInd from (select mobile_id from customerTable order by mobile_id)  where rownum < (:n);



Syntax error at line 76, column 187, file minrange.pc:
Error at line 76, column 187 in file minrange.pc
EXEC SQL select min(mobile_id), max(mobile_id) into :FromMIN INDICATOR :FromMINInd, :ToMIN INDICATOR :ToMINInd from (select mobile_id from customerTable order by mobile_id)  where rownum < (:n);
..........................................................................................................................................................................................1
PCC-S-02201, Encountered the symbol "by" when expecting one of the following:

   , ) union, connect, group, having, intersect, minus, start,
   where, with,
The symbol "group," was substituted for "by" to continue.

Error at line 0, column 0 in file minrange.pc
PCC-F-02102, Fatal error while doing C preprocessing



Above sql stmt. has to retrieve the n'th mobile-id from table customerTable. Is there any other way of retrieving n'th mobile id number without the inner query. Pls. Remember we cannot use rownum = :n in oracle. & Result should be based on sorted order of mobile-id.
Thanks,
mogunekAsked:
Who is Participating?
 
ComTechConnect With a Mentor Commented:
This question will be placed in PAQ and points refunded.

Best regards,
ComTech
Community Support
Administrator @ EE
0
 
dbaoraCommented:
Hi,
you cannot use an order by experssion when selecting from select clause (just like creating a view with a order by).
try using:
EXEC SQL select min(mobile_id), max(mobile_id) into :FromMIN INDICATOR :FromMINInd, :ToMIN INDICATOR
:To
MINInd from (select mobile_id from customerTable) where rownum < (:n) order by mobile_id;

regards,
dbaora.
0
 
mogunekAuthor Commented:
dbaora,
You know "order by" will work after the where clause, So if the table is not in sorted order then it will pickup the first n records and finds n'th record out of these.

If you have some other query, Pls. give me.
Thanks,
0
 
MoondancerCommented:
This question was LOCKED with a PROPOSED ANSWER and awaits your decision today.  Once a question is LOCKED with a Proposed Answer, few new experts will step in to help on that question, since the assumption is, you've been helped.  If the Proposed Answer helped you, please accept it and award that expert.  If it did not help you, please reject it and add comments as to status and what else is needed.
 
If you wish to award multiple experts, just comment here with detail, I'll respond as soon as possible.  As it stands today, you asked the question, got help and not one expert was awarded for the contribution(s) made.  Your response is needed.  I'll monitor through month end, and if you've not returned to complete this, we'll need to decide.  Expert input is welcome (as always) to determine the outcome here if the Asker does not respond.
 
Your response in finalizing this (and ALL) your question(s) is appreciated.
 
Moondancer
Community Support Moderator @ Experts Exchange
0
 
nico5038Commented:

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
 - PAQ'd and pts refunded
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.