0

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;
bummi
  • 27,123
  • 14
  • 62
  • 101
XiaoChuan Yu
  • 3,951
  • 1
  • 32
  • 44

1 Answers1

0

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.

NealB
  • 16,670
  • 2
  • 39
  • 60