问题描述
我有一个表,其中date列具有以下格式的数据:
2014年7月25日12:14:27 AM'。我需要通过放置where子句来获取此日期。
I have one table where date column is having data in below format:"7/25/2014 12:14:27 AM'. I need to fetch this date by putting in the where clause. can anyone suggest how can i do this?
推荐答案
日期(存储在表中)是-它们没有任何关联的格式。如果将它们格式化为字符串,则该客户端程序是您用来访问数据库的应用程序自己的日期格式(通常可以通过该程序中的首选项设置)。
Dates (stored in tables) are represented by 7 bytes - they do not have any format associated with them. If they are formatted as a string then that is the client program which you are using to access the database applying its own formatting to the date (which you can usually set via the preferences in that program).
如果日期以某种格式存储,则您不存储将其作为日期,但将其存储为字符串(即 VARCHAR2
)格式。
If the "date" is stored with a format then you are not storing it as a date but storing it as a string (i.e. VARCHAR2
) format.
查询-如果日期存储为日期:
SELECT *
FROM table_name
WHERE date_column = TO_DATE( '7/25/2014 12:14:27 AM', 'MM/DD/YYYY HH12:MI:SS AM' )
或使用ANSI / ISO文字:
or, using ANSI/ISO literals:
SELECT *
FROM table_name
WHERE date_column = TIMESTAMP '2014-07-25 00:14:27'
,或者,如果您想要的只是给定日期的值,则:
or, if you want values which are just for a given day then:
SELECT *
FROM table_name
WHERE date_column >= DATE '2016-05-12'
AND date_column < DATE '2016-05-13'
(这将允许您在 date_column
列。)
或,仅传递单日值(由绑定表示)变量:date_value
):
or, only passing a single day value (represented by the bind variable :date_value
):
SELECT *
FROM table_name
WHERE date_column >= :date_value
AND date_column < :date_value + INTERVAL '1' DAY
查询-如果日期存储为字符串:
SELECT *
FROM table_name
WHERE TO_DATE( date_as_a_string_column, 'MM/DD/YYYY HH12:MI:SS AM' )
= TIMESTAMP '2014-07-25 00:14:27'
,或者简单地:
SELECT *
FROM table_name
WHERE date_as_a_string_column = '7/25/2014 12:14:27 AM'
这篇关于where子句中的日期格式-Oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!