Pro*C question

From: Alexander L. Makovsky <amakovsk_at_sovam.com>
Date: 1995/09/10
Message-ID: <42v12e$hcl_at_news.sovam.com>#1/1


Hello!
I've got a new job recently, and have some question about ORACLE Pro*C because I am novice in RDBMS and, in particular, in SQL. I cannot RTFM, because there is none, and my colleagues are not experienced enough to help me. So I'll appreciate any advice.

I'd like to use the following method of SQL Pro*C programming

S="INSERT INTO TABLE1(FIELD1,FIELD2) VALUES(:v1,:v2)"; /* of course I actually do it with sprintf, S is properly declared and memory is allocated */

EXEC SQL PREPARE S1 FROM :S;
EXEC SQL EXECUTE S1 USING :field1,:field2;

It works fine in the example above.

But if I try
S="SELECT FIELD1 INTO :v1 FROM TABLE2 WHERE FIELD2 = :v2;

EXEC SQL PREPARE S1 FROM :S;
EXEC SQL EXECUTE S1 USING :field1,:field2; I get SQLERROR and "bind variable does not exist" in

        sqlca.sqlerrm.sqlerrmc

I have to make a CURSOR and move INTO to FETCH phrase to force it work.
I don't like this if I know for sure that there is only one record with specified criteria.
I also cannot write SQL phrases directly (EXEC SQL SELECT FIELD1 INTO :var FROM TABLE;, which works), because I don't know the actual names of the table and fields at the compile time.

Another problem arises when I want to know if there are records with specified criteria, no matter how many.  "SELECT * FROM FOO " does not raise NOT FOUND situation; I must "SELECT FIELD1 FROM FOO" and again use CURSOR, because without it nothing works.

Reading output of Pro*C I decide that it is smart enough to do what I want, the only thing I need is to ask him correctly.

It would be great if someone send a piece of WORKING source code, written in the DESCRIBED manner that accomplishes the requested task.

Thank you in advance

                Sincerely yours,
                        Konstantin Kivi,
                        Russia.
Received on Sun Sep 10 1995 - 00:00:00 CEST

Original text of this message