Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Any expert Pro*C/C++ programmer out there?
On Mar 13, 7:37 am, "sybrandb" <sybra..._at_gmail.com> wrote:
> On Mar 13, 6:21 am, "Ramon F Herrera" <r..._at_conexus.net> wrote:
>
>
>
> > I have programmed using the OCI for years, but decided to move to
> > Pro*C/C++. I have ran and modified the simplest examples so far. But
> > now I ma stuck.
>
> > In my application, the critical variable which is only known at run
> > time is none less than the table name. It is something like this:
>
> > SELECT emp_name FROM $table_name WHERE emp_id = :some_unique_id;
>
> > So, per the manual, I guess I should use Method 3. The doubt that I
> > have is this. If I know for a fact that there will be a single record
> > being retrieved, do I still have to use the specifics of Method 3
> > described in sample8.pc, with CURSOR, FETCH a loop and everything?
> > It sounds like such a waste. It seems to me that there should be a
> > simpler way, given that the contents of only one row will be
> > retrieved.
>
> > -Ramon
>
> Never used Pro*C, though did work with Pro*Pascal for a few years.
>
> The fact a single record will be retrieved is irrelevant to the
> implementation, which requires a CURSOR etc.
> If you want to assume there is always 1 record, and you can avoid the
> LOOP, you should by all means do so.
> However you probably are aware that 'assume' is an acronym for 'I made
> an ass out of me and you'.
> I would probably judge such code as ready for the garbage bin.
>
> --
> Sybrand Bakker
> Senior Oracle DBA
Sybrand:
I can see that the years haven't softened you. :-) Anyway, you have helped me many times and I thank you for that.
If I have a column with a unique key and I am doing my search based on such key, I know for a fact that there will be a single hit (or zero, of course).
The first statement is this. We cannot eliminate it:
EXEC SQL PREPARE S FROM :dynstmt;
I removed the loop below and the program is working properly. Now I am trying to figure out how (or whether it is possible) to remove the rest of the "unnecessary" (?) statements:
EXEC SQL DECLARE C CURSOR FOR S;
EXEC SQL OPEN C USING :deptno;
loop {
EXEC SQL FETCH C INTO :ename;
}
In other words, the statement that I need in order to replace everything above, is something like:
EXEC SQL S; But I am not sure if such thing exists. If Oracle cares about efficiency, such statement should be available.
-Ramon Received on Tue Mar 13 2007 - 18:10:03 CDT