You can use indicator arrays for FETCH INTO statements that are non-dynamic, when you set the precompiler option COMPATIBILITY_MODE to ORA.
An indicator variable array is a short data type variable that is associated with a specific host variable array or a structure array. Each indicator variable element in the indicator variable array can contain 0 or -1 value that indicates whether an associated host variable or structure contains a null value. If an indicator variable value is less than zero, it identifies the corresponding array value as NULL.
In FETCH INTO statements, you can use indicator variable arrays to determine whether any elements of array variables are null.
You can use the keyword INDICATOR to identify an indicator variable, as shown in the example.
EXEC SQL BEGIN DECLARE SECTION;
char empno[100][8];
char lastname[100][15];
short edlevel[100];
double bonus[100];
short bonus_ind[100];
EXEC SQL END DECLARE SECTION;
EXEC SQL DECLARE empcr CURSOR FOR
SELECT empno, lastname, edlevel, bonus
FROM employee
WHERE workdept = 'D21';
EXEC SQL OPEN empcr;
EXEC SQL WHENEVER NOT FOUND GOTO end_fetch;
while (1) {
EXEC SQL FETCH empcr INTO :empno :lastname :edlevel,
:bonus INDICATOR :bonus_ind
...
...
}
end_fetch:
EXEC SQL CLOSE empcr;
EXEC SQL FETCH empcr INTO :empno :lastname :edlevel, :bonus:bonus_ind
If the cardinality of indicator variable array does not match the cardinality of the corresponding host variable array, an error is returned.
// declaring indicator structure array of size 3
EXEC SQL BEGIN DECLARE SECTION;
...
struct MyStructInd
{
short c1_ind;
short c2_ind;
} MyStructVarInd[3];
EXEC SQL END DECLARE SECTION;
...
// using structure array host variables & indicators structure type
// array while executing FETCH statement
// ‘MyStructVar’ is structure array for host variables
// ‘MyStructVarInd’ is structure array for indicators
EXEC SQL FETCH cur INTO :MyStructVar :MyStructVarInd;
Applications
can check the sqlca.sqlerrd[2] field to get the number
of rows that are successfully fetched.