get/set 使用 OCI 的时间戳值

get/set TIMESTAMP values using OCI

我正在使用 C 和 oci.h 来设置和获取 VARCHAR、NUMBER、... DATE 值,但我还需要 TIMESTAMP 类型。我可以从每列的 OCIAttrGet 中读取大小、比例和精度

得到

在我的 OCIDefineByPos 中,我如何知道要为 TIMESTAMP 类型分配多少 space? 当我使用 OCIStmtFetch2() 时,如何解释检索到的值?

设置

在 OCIBindByPos() 和 OCIStmtExecute() 中,如何将我的时间戳格式转换为 oracle 的格式? 我也需要知道 space 的要求。

帮助获取 TIMESTAMP(来自 https://docs.oracle.com/html/E49886_05/oci12oty.htm

示例 12-2 操作 OCIDateTime 类型的属性

...

/* allocate the program variable for storing the data */
OCIDateTime *tstmpltz = (OCIDateTime *)NULL;

/* Col1 is a time stamp with local time zone column */
OraText *sqlstmt = (OraText *)"SELECT col1 FROM foo";

/* Allocate the descriptor (storage) for the data type */
status = OCIDescriptorAlloc(envhp,(void  **)&tstmpltz, OCI_DTYPE_TIMESTAMP_LTZ,
         0, (void  **)0);
....

status = OCIStmtPrepare (stmthp, errhp, sqlstmt, (ub4)strlen ((char *)sqlstmt),
         (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT);

/* specify the define buffer for col1 */
status = OCIDefineByPos(stmthp, &defnp, errhp, 1, &tstmpltz, sizeof(tstmpltz),
         SQLT_TIMESTAMP_LTZ, 0, 0, 0, OCI_DEFAULT);

/* Execute and Fetch */
OCIStmtExecute(svchp, stmthp, errhp, 1, 0,(OCISnapshot *) NULL,
         (OCISnapshot *)NULL, OCI_DEFAULT)

At this point tstmpltz contains a valid time stamp with local time zone data. You
can get the time zone name of the datetime data using:

status = OCIDateTimeGetTimeZoneName(envhp, errhp, tstmpltz, (ub1 *)buf,
         (ub4 *)&buflen);
...