我正在使用主机阵列插入和更新数据,如Oracle 手册中所示。这是一段代码:
in my_func(void* ctx, int run_id, DB_DATA** db_data)
{
int i = 0;
EXEC SQL BEGIN DECLARE SECTION;
int ora_id_run[BULK_SIZE];
int ora_term_id[BULK_SIZE];
int ora_seq_num[BULK_SIZE];
int ora_resp[BULK_SIZE];
char ora_timestamp[BULK_SIZE][27];
EXEC SQL END DECLARE SECTION;
for (i = 0; i < BULK_SIZE; i++)
{
ora_id_run[i] = run_id;
ora_term_id[i] = db_data[i]->term_id;
ora_seq_num[i] = db_data[i]->seq_num;
ora_resp[i] = db_data[i]->resp;
memset(ora_timestamp[i], '\0', sizeof(ora_timestamp[i]));
strncpy(ora_timestamp[i], db_data[i]->timestamp, strlen(db_data[i]->timestamp));
}
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CONTEXT USE :ctx;
EXEC SQL UPDATE T_TABLE
SET RESP = :ora_resp,
ELAPSED = TO_TIMESTAMP(:ora_timestamp, 'DD-MM-RR HH24:MI:SS.FF') - DT
WHERE ID_RUN = :ora_id_run
AND ID_TERM = :ora_term_id
AND SEQ_NUM = :ora_seq_num;
if (sqlca.sqlcode != 0)
{
ORA_ERROR;
}
EXEC SQL COMMIT WORK;
return sqlca.sqlcode;
}
BULK_SIZE 大约是 200、300、500。有时更新的行数小于 BULK_SIZE(我用 sqlerrd[2] 检查过)。
为什么?