Query using date datatype in Oracle 11g

时间:2015-06-30 13:26:53

标签: sql oracle date

I'm trying to do simple select and Update in Oracle 11g using a date where clause and I can't produce the result I expect.

The date field is datemodified and currently has values like 12-JUL-14 and of data type date.

I'm doing the following and don't get result:

  select *
  from table
  where datemodified = to_date(datemodified, '12-JUL-14')

I tried the following and still did not produce result:

  select * from table
  where to_date(datemodified, 'DD-MON-YY') = to_date('12-JUL-15',   
  'DD-MON-YY')

or

  Update table
  set column = 'some value'
  where datemodified = to_date('12-JUL-15', 'DD-MON-YY')

What am I doing wrong?

2 个答案:

答案 0 :(得分:0)

You can try this query

select * from table
  where to_char(datemodified, 'dd-MON-yy') = '12-JUL-15'

答案 1 :(得分:0)

Oracle日期字段包括一天中的时间。此外,过滤功能结果(如to_char())会降低生产速度。这种方法有效:

where dateModified >= the date you want
and dateModified < the day after the date you want.

可以使用函数作为值,例如

where dateModified >= trunc(sysdate)

where dateModified >= to_date('12-JUL-15','DD-MON-YY')

但不在球场本身

相关问题