我使用C和oci.h来设置和获取VARCHAR,NUMBER,...日期值,但我还需要时间戳类型。我可以从每列的OCIAttrGet中读取大小、小数位数和精度
到达
在我的OCIDefineByPos中,如何知道为TIMESTAMP类型分配多少空间?当我使用OCIStmtFetch2()时,如何解释检索到的值?
设置
在OCIBindByPos()和OCIStmtExecute()中,如何将时间戳格式转换为oracle的时间戳格式?我也需要知道所需的空间。
发布于 2018-07-15 08:27:24
帮助获取时间戳(来自https://docs.oracle.com/html/E49886_05/oci12oty.htm)
Example 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);
...
https://stackoverflow.com/questions/51337345
复制相似问题