Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How do you declare function parameters as host variables in Pro*C/C++?
Erik Moe wrote:
> Hello,
>
> I haven't done embedded SQL in several years and then it was with
> Informix. I want to use some function parameters as host variables,
> something like this:
>
> func(int foo, char* bar)
> {
> EXEC SQL INSERT INTO FOOBAR (FOO, BAR) VALUES (:foo, :bar);
> }
>
> How do I declare foo and bar as host variables? I don't want to want
> to you K&R syntax:
>
> func(foo, bar)
> EXEC SQL BEGIN DECLARE SECTION
> int foo;
> char* bar;
> EXEC SQL END DECLARE SECTION
> {
> EXEC SQL INSERT INTO FOOBAR (FOO, BAR) VALUES (:foo, :bar);
> }
>
> Is this legal?
>
> func(
> EXEC SQL BEGIN DECLARE SECTION
> int foo, char* bar
> EXEC SQL END DECLARE SECTION
> )
> {
> EXEC SQL INSERT INTO FOOBAR (FOO, BAR) VALUES (:foo, :bar);
> }
>
> Erik Moe
What version of Pro-C do you use? If it is 2.2 or higher then you don't need explicitly declared host variables and something like your first example should be reasonable except that most likely you probably meant:
void func(int foo,const char *bar)
However, if you are using C++ then you need the semantics of having a declare section.
![]() |
![]() |