English 中文(简体)
页: 1
原标题:Oracle: How to filter by date and time in a where clause
  • 时间:2012-01-12 16:58:14
  •  标签:
  • sql
  • oracle

How can I do this:

select *
from tableName
where SESSION_START_DATE_TIME > To_Date ( 12-Jan-2012 16:00 ,  DD-MON-YYYY hh24:mi  )

届会:START_DATE_TIM 格式12/01/2012 13:16:32.000

I Trial where To_Date (SESSION_START_DATE_TIME, DD-MON-YYYh24:mi ) > To_Date (12-Jan-2012 16:00, DD-MON-YYh24:mi

but no matter what I try I get the error: SQL command not properly formed

问题回答

举例来说,你提供的任何东西都不会放弃<条码>。 结构指挥没有适当形成错误。 你如何执行这一询问? 你们没有告诉我们什么?

举例来说,这本书行的罚款是:

create table tableName
(session_start_date_time DATE);

insert into tableName (session_start_date_time) 
values (sysdate+1);

select * from tableName
where session_start_date_time > to_date( 12-Jan-2012 16:00 ,  DD-MON-YYYY hh24:mi );

如上所示:

create table tableName2
(session_start_date_time TIMESTAMP);

insert into tableName2 (session_start_date_time) 
values (to_timestamp( 01/12/2012 16:01:02.345678 , mm/dd/yyyy hh24:mi:ss.ff ));

select * from tableName2
where session_start_date_time > to_date( 12-Jan-2012 16:00 ,  DD-MON-YYYY hh24:mi );

select * from tableName2
where session_start_date_time > to_timestamp( 01/12/2012 14:01:02.345678 , mm/dd/yyyy hh24:mi:ss.ff );

因此,还必须有其他错误。

这样做

where ("R"."TIME_STAMP">=TO_DATE ( 03-02-2013 00:00:00 ,  DD-MM-YYYY HH24:MI:SS )
   AND "R"."TIME_STAMP"<=TO_DATE ( 09-02-2013 23:59:59 ,  DD-MM-YYYY HH24:MI:SS )) 

Where R is table name.
TIME_STAMP is FieldName in Table R.

3. 如果会议召开,《START》 您可能希望利用“TIMESTAMP”这一功能。 例如:

     SQL> CREATE TABLE t (ts TIMESTAMP);

     Table created.

     SQL> INSERT INTO t
       2       VALUES (
       3                 TO_TIMESTAMP (
       4                     1/12/2012 5:03:27.221008 PM 
       5                   , mm/dd/yyyy HH:MI:SS.FF AM 
       6                 )
       7              );

     1 row created.

     SQL> SELECT *
       2    FROM t
       3   WHERE ts =
       4            TO_TIMESTAMP (
       5                1/12/2012 5:03:27.221008 PM 
       6              , mm/dd/yyyy HH:MI:SS.FF AM 
       7            );
     TS
     -------------------------------------------------
     12-JAN-12 05.03.27.221008 PM

Try:

To_Date (SESSION_START_DATE_TIME,  MM/DD/YYYY hh24:mi ) > 
To_Date ( 12-Jan-2012 16:00 ,  DD-MON-YYYY hh24:mi  )

显然,12/01/2012 13:16:32.000 吨与DD-MON-YYY h24:mi Format。

Update:

你们需要MMM/DD/YYYh24:mi:s.ff Format and to use_TIMESTAMP,而不是为了_DATE,日期不会在矿石中持有mill。





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

热门标签