oracle日期类型字段

来源:互联网 发布:上海行知中学 编辑:程序博客网 时间:2024/04/26 20:52

我的开发框架是webwork+ibatis+oracle

大家有没有碰到这样的问题:

      假如我的表字段的类型是date,java po类里此字段对应的类型是String,我们需要从数据库里把此po的信息查询出来,

然后保存到另外一个表里,另外一张表里字段的类型是date,java po类里此字段对应的类型是String。

      如果我们直接从数据库里查询出来,然后不加处理就直接插入,或是更新到另一个表里,那么就会报错,导致insert or

update 失败.原因date类型的字段从数据库里查出来是 21-1月 -09 12.00.00.000000 这样的格式,然后我们用to_date('','yyyy-mm-dd'),或  to_date('','yyyy-mm-dd hh-mi-ss.sss')都会报错。

      我的解决方法是:(1)查询此po的信息时把它转换成字符串,并规定好格式

                               (2)插入时用to_date('','yyyy-mm-dd')就行了

 

      代码:

     <select id="getContentInfoCopyByID" resultClass="contentPO" parameterClass="long">
          select  t.content_id,t.content_name,t.indicate,t.content_type,t.item_id,
          t.order_command,t.type_id,t.imguri,t.order_success_message,
         t.content_order_message,t.service_approve_state,t.opinion,
         to_char(t.apply_time,'yyyy-mm-dd') as apply_time,to_char(t.approve_time,'yyyy-mm-dd') as            approve_time,
         t.delete_flag,t.cp_id,t.inner_service_code_id,t.author,t.copyright_deadline
          from t_content_info_copy t where content_id = #content_id#
 </select>