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

Posted on 2001-07-30
Last Modified: 2012-08-13
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);
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.
Question by:mogunek

Expert Comment

ID: 6339609
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
MINInd from (select mobile_id from customerTable) where rownum < (:n) order by mobile_id;


Author Comment

ID: 6346841
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.

Expert Comment

ID: 6402602
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.
Community Support Moderator @ Experts Exchange
LVL 54

Expert Comment

ID: 7284070

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.



Accepted Solution

ComTech earned 0 total points
ID: 7315803
This question will be placed in PAQ and points refunded.

Best regards,
Community Support
Administrator @ EE

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Link Quickbooks point of sale to server 12 82
Folder Replication 4 46
MSSQL Convert Char To Date 4 44
Data center mess 4 49
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

9 Experts available now in Live!

Get 1:1 Help Now