日期:2014-05-16  浏览次数:20517 次

PI插入数据库时关于日期与时间戳特殊用法
   由于PI传输数据是通过XML传输的,所以数据理论上都是STRING类型的,所以在插入数据库DATE与TIMESTAMP类型时需要做一下特殊处理。

   首先说说日期类型的。由于PI操作数据库会根据自定义的结构转换成SQL语句,所以我们就可以利用SQL里的TO_DATE方法把String类型转换成日期。

首先结构定义如下:



注意字段要添加属性:hasQuot. 赋值:No

hasQuot= YES|NO During construction of the WHERE condition of the SQL statement, the table column type determines whether the default is to set the values in quotation marks (text column types) or not (numerical column types). In a few cases (for example, when using functions), it may be necessary to override this. This attribute enables you to do this. If YES, quotation marks are always set round the values for which this attribute is set in the SQL syntax. If NO, quotation marks are never set. Only use this attribute in individual cases.

字段的MAPPING如图:



第一个文体: TO_DATE('
第二个文体:  ','YYYY-MM-DD')
mapping的逻辑就是判断日期是否为空,如果不为空就把值转换成:
TO_DATE('2011-12-30','YYYY-MM-DD')

TIMESTAMP就是把TO_DATE换成to_timestamp
转换的格式为:
to_timestamp('20111228 091931','yyyyMMdd HHmiss')


Java严格区分大小写,而Oracle对大小写不敏感,所以上面的 MM-年中的月份 和 mm-小时的分钟 就发生了冲突,即出现了两次。

将 mm 修改为 mi 即可,to_date('05092011093536','ddMMyyyyHHmiss')


相关连接:http://help.sap.com/saphelp_nw70/helpdata/en/2e/96fd3f2d14e869e10000000a155106/frameset.htm