今天创建一个视图

create view v_myview{

  id,

  time

}

as

select t.id as id,

   (case

         when to_date(t.time,'hh24:mi:ss')<

              TO_DATE ('12:00:00', 'hh24:mi:ss')

         then

              'AM'

         else

              'PM'

    )  as time

from mytable t


发现生成的 v_myview 中 time 类型为char(2 byte)


在项目中查看(用hibernate 的 query.list) 得到time字段只有‘A’或‘P’(应该为‘AM’或‘PM’)


后将 创建 view 语句修改为

create view v_myview{

  id,

  time

}

as

select t.id as id,

   (case

         when to_date(t.time,'hh24:mi:ss')<

              TO_DATE ('12:00:00', 'hh24:mi:ss')

         then

             cast('AM' as varchar2(10))

         else

             cast('PM' as varchar2(10))

    )  as time

from mytable t


这下在v_myview 中    time字段类型 为varcha2(10)了


在项目中查看(用hibernate 的 query.list) 终于为‘AM’或‘PM’了!