If you don't like the last one I sent try this one
1: #include <stdio.h>
2: exec sql include sqlca; /* communication area
*/
4: main()
5: {
6: exec sql begin declare section;
7: VARCHAR cid[5], user_name[20], user_pwd[10];
8: double dollars;
9: int cnt;
10: exec sql end declare section;
11: exec sql declare dollars_cursor cursor for /* to calculate media
*/
12: select dollars from orders
13: where cid=:cid order by dollars desc; /* ... order important
*/
14: exec sql whenever sqlerror stop;
15: strcpy(user_name.arr,"poneilsql");
16: user_name.len=strlen(user_name.arr);
17: strcpy(user_pwd.arr,"XXXX");
18: user_pwd.len=strlen(user_pwd.arr);
19: exec sql connect :user_name
20: identified by :user_pwd; /* ORACLE: connect
*/
22: while (prompt("Please enter a cutomer ID: ", cid.arr) >0 )
23: /* main loop: get cid
*/
24: {
25: cid.len=strlen(cid.arr) /* set cid length
*/
26: exec sql select cound(cid) into :cnt /* count orders by cid
*/
27: from order where cid=:cid;
28: if (cnt==0)
29: {
30: printf("No orders retrieved for cid value %s\n",cid);
31: continue; /* go loop again
*/
32: }
33: exec sql open dollars_cursor;
35: /* open cursor and loop until midpoint of ordered list */
36: do /* loop at least once
*/
37: exec sql fetch dollars_cursor into :dollars;
38: while ((cnt-=2)>0); /* fetch thru midpoint
*/
39: exec sql close dollars_cursor; /* loop completed
*/
40: exec sql commit work; /* release locks
*/
41: printf("Median dollar amount = %f\n",dollars);
42: } /* end main loop
*/
43:
44: exec sql disconnect;
45: }
--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: Dawn White
INET: [EMAIL PROTECTED]
Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
San Diego, California -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).