Question

Is it safe to use same host variable for both input and output in an embedded SQL query ? I'm using C and DB2 static embedded SQL.

Example:

EXEC SQL 
     SELECT someCol 
     INTO :someHostVar 
     FROM SomeTable 
     WHERE :someHostVar = someOtherCol;
Was it helpful?

Solution

Yes, you can do that. The value of someHostVar will be overwirtten and contain whatever the value of someCol is for this particular predicate - unless the value of someCol happens to be NULL at which point it the host variable remains unchanged.

Even though you can do this, I would suggest to you that this is not a good practice because someHostVar may end up containing values for different columns of the same table - too easy to screw up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top