简体   繁体   English

将oracle列作为时间戳返回

[英]Return an oracle column as timestamp

I'm in coldfusion working with data from an sql table, and using a query of queries to join the sql data to some data from an oracle database. 我正在使用SQL表中的数据进行Coldfusion,并使用查询查询将sql数据连接到oracle数据库中的某些数据。 Unfortunately, I need to order them by date, and the oracle table has two columns - DRWR_DATE which is of type DATE and TIME which is of type VARCHAR2. 不幸的是,我需要按日期对它们进行排序,并且oracle表有两列-DRWR_DATE类型为DATE,而TIME类型为VARCHAR2。 The two columns put into a string read 17-JUN-03 16:35:18 or something similar. 两列放入一个字符串读取17-JUN-03 16:35:18或类似的东西。 I need to return these two columns as a TIMESTAMP so I can use query of queries to sort them. 我需要将这两列作为TIMESTAMP返回,以便我可以使用查询查询来对它们进行排序。

Also, I think I read that a date column holds the time in Oracle anyway? 另外,我想我读过一个日期专栏,无论如何都要在Oracle中占用时间? I don't have much experience with Oracle so I am unsure how best to do this. 我对Oracle没有太多经验,所以我不确定如何做到最好。

Try this: 尝试这个:

SELECT  to_timestamp(
              to_char( drwr_date,'dd-mon-yy') ||' '|| time
              , 'dd-mon-yy hh24:mi:ss'
        ) 
FROM   your_table

Try using TO_TIMESTAMP function: 尝试使用TO_TIMESTAMP函数:

SELECT TO_TIMESTAMP('17-JUN-03 16:35:18', 'DD-MON-RR HH24:MI:SS') 
  FROM DUAL;

you can try converting the column to date as the following: 您可以尝试将列转换为日期,如下所示:

TO_DATE(column,'DD-MON-YY HH24:MI:SS')

The first parameter takes your column and the second parameter specifies the date format that is used 第一个参数占用您的列,第二个参数指定使用的日期格式

If all you have to do is order by date, all you need is an order by clause. 如果你所要做的就是按日期订购,你只需要一个order by子句。

order by drwr_date, time

You don't have to cast these to anything, unless you need to do so for another reason. 您不必将这些内容转换为任何内容,除非您出于其他原因需要这样做。 Remember that a date datatype is essentially a floating point number. 请记住,date数据类型本质上是一个浮点数。 This, "17-JUN-03" is simply how your client is displaying it. 这个“17-JUN-03”就是您的客户端显示它的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM