【发布时间】:2020-07-14 11:45:41
【问题描述】:
我正在用 C 编写一个向 Oracle DB 发送查询的客户端,当我尝试对受它影响的行数进行采样时,我总是得到 1 的值。 这是查询:
char * query = "BEGIN "\
"INSERT INTO table_name ( field_1, field_2, id, field_3 ) VALUES ( :1, :2, :3, 1 );"\
"EXCEPTION "\
"when dup_val_on_index then "\
"UPDATE table_name SET field_1 =:4, field_2 =:5, field_3 = 1 where id = :6 and field_4 <= :7;"\
"END; ";
我使用 OCI 的 OCIStmtExecute 函数和 OCI_COMMIT_ON_SUCCESS 执行它,并且为了对受影响的行进行采样:
ub4 update_count;
OCIAttrGet(stmthp, OCI_HTYPE_STMT, &update_count, 0, OCI_ATTR_ROW_COUNT, ctx->hp);
出于某种奇怪的原因,update_count 始终为 1。 这很奇怪,因为如果我以完全相同的方式发送简单的更新或插入查询,我会在 update_count 中得到正确的结果。
以这种形式执行查询时,有什么不同应该做的吗?
【问题讨论】:
标签: sql c oracle oracle-call-interface