首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用OCI获取/设置时间戳值

使用OCI获取/设置时间戳值
EN

Stack Overflow用户
提问于 2018-07-14 17:57:35
回答 1查看 600关注 0票数 0

我使用C和oci.h来设置和获取VARCHAR,NUMBER,...日期值,但我还需要时间戳类型。我可以从每列的OCIAttrGet中读取大小、小数位数和精度

到达

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

设置

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

EN

回答 1

Stack Overflow用户

发布于 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);
...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51337345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档