0

Say, I have the following query to execute to read bulk set of records:

SELECT  c1, c2, c3 , ........, c10
FROM TBL1 
WHERE C5 = 5 
ORDER BY c7, c8

Then, I have:

EXEC SQL WHENEVER SQLERROR DO ...;
EXEC SQL DECLARE xx CURSOR FOR xxx;     
EXEC SQL OPEN xxx;
EXEC SQL WHENEVER NOT FOUND goto notfound;
EXEC SQL FETCH xxx INTO :a1:a1_ind;

where a1 is array of structures and a1_ind is array of indicator variables.

Can I use variable number of bind variables? For example:

EXEC SQL FETCH xxx INTO :v1:v1_ind, :v2:v2_ind, .... :v6:v6_ind;

Can I use EXEC SQL DESCRIBE BIND VARIABLES ? How? Please guide.

Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
  • What do your variable number of bind variables represent? Individual columns from your query - because you only expect one row back? Why a variable number? It isn't really clear what you are really trying to do, or what problem you are trying to solve. – Alex Poole Aug 12 '16 at 11:50
  • @AlexPoole I have multiple rows to retrieve, and number of columns may vary, for example, in one scenario, I may have 6 cols, in other scenario, I may have 4 cols, and I will have a character string for the query with 6 or 4 placeholders for bind variables as :v. Problem is how to variable number of bind variables, considering all are character strings? – Dr. Debasish Jana Aug 12 '16 at 11:56
  • So the query you're executing changes? I think you'll need a variety of fetches and pick one based on the number or columns in the result set; you'll need to know that to process the data from the arrays anyway, surely. Are you asking how to find out how many columns there are in the result set, from metadata about the parsed cursor query? (I have no idea how to get that unfortunately, but it may be possible!) – Alex Poole Aug 12 '16 at 12:08
  • @AlexPoole Yes my query changes with basic skeleton remaining same, varying part is number of columns to fetch and keeping that variable, I need to have fetch into variable structure? Can I have pointer to pointer to dynamically allocate the fetch into part or anything better? – Dr. Debasish Jana Aug 12 '16 at 12:10

0 Answers0