INSERT, STRUCT, DATE
Peter Smith, March 04, 2004 - 9:59 am UTC
I have a program using array inserts of the old variety, i.e. an array for each column:
FOR :aNumRows EXECUTE S_YEAR USING
:mArrDate[0]:mArrDateInd, ...
I want to convert this to an array of structure inserts.
To do this you have to lie in the PREPARE and pass a single struct, but pass the array in
EXECUTE S_YEAR USING :mCdrStruct[0]:mCdrStructInd[0];
All this is fine, except that my table contains a date column. Usually I use to_date() to populate this but in the array version all you can pass is the array of structures and it's indicator array.
So my structure must contain a date not a char[].
Approaches:
typedef char MyDate[7];
EXEC SQL TYPE MyDate IS DATE;
typedef struct
{ ...
myDate date_start;
}
s.date_start[0] = 119;
s.date_start[1] = 204; /* 2004 */
s.date_start[2] = 3; /* march */
...
Doesn't work.
OCIDate: Cannot put OCIDate in array variables!
Default of to_date(), assume that ascii DD-MAR-04 works.
But it doesnt.
How can one do array of struct inserts if the table contains a date?
March 04, 2004 - 2:10 pm UTC
don't even consider using the 7 byte date format, it'll cause you no end of misery.
Just set your nls_date_format and use strings as always:
void process( void )
{
exec sql begin declare section;
struct test_data
{
char str[15];
char dt[25];
int num;
} test_d[10];
int n;
exec sql end declare section;
int i;
EXEC SQL WHENEVER SQLERROR DO sqlerror_hard();
for( i = 0; i < 10; i++ )
{
sprintf( test_d[i].str, "data%d", i );
sprintf( test_d[i].dt, "%d/03/2004", i+1 );
test_d[i].num = i;
}
n = 10;
exec sql alter session set nls_date_format = 'dd/mm/yyyy';
exec sql for :n insert into t (str,dt,num) values (:test_d );
exec sql commit;
}