我正在使用C和oci.h来设置和获取VARCHAR,NUMBER,... DATE值,但我还需要TIMESTAMP类型。我可以从OCIAttrGet的每一列上读取大小,比例和精度
在我的OCIDefineByPos中,我如何知道要为TIMESTAMP类型分配多少空间? 当我OCIStmtFetch2()时,如何解释检索到的值?
在OCIBindByPos()和OCIStmtExecute()中,如何将时间戳格式转换为oracle的格式? 我也需要知道所需的空间。
答案 0 :(得分:1)
帮助获取时间戳(来自https://docs.oracle.com/html/E49886_05/oci12oty.htm)
...
/* 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);
...