简体   繁体   English

Oracle SQL将时间戳转换为格式

[英]Oracle sql convert timestamp into format

I have a timestamp column 'ts'. 我有一个时间戳列“ ts”。 I need to convert it into the format: 我需要将其转换为以下格式:

'DD-MON-YYYY hh24:mi' . 'DD-MON-YYYY hh24:mi'

I used this to complete the requirement: 我用它来完成要求:

to_char(ts, 'DD-MON-YYYY hh24:mi').

The problem is this returns a String. 问题是这将返回一个字符串。 I am using Oracle Apex and outputting everything in a table. 我正在使用Oracle Apex并将所有内容输出到表中。 The table allows sorting. 该表允许排序。 Now when I sort it sorts the column as a string and not as a date, so the sorting is not accurate. 现在,当我对它进行排序时,它会将列作为字符串而不是日期进行排序,因此排序是不准确的。 How can I convert a timestamp into the format I need while still being a timestamp/date field (any type as long as it accurately will sort by real dates). 如何在仍为时间戳记/日期字段的同时将时间戳记转换为所需的格式(任何类型,只要它能准确地按实际日期排序即可)。

@sstan is right. @sstan是正确的。 There are four date formats that can be set at the workspace level, and at the application level: Application Date Format, Application Date Time Format, Application Timestamp Format, and Application Timestamp Time Zone Format. 可以在工作空间级别和应用程序级别设置四种日期格式:应用程序日期格式,应用程序日期时间格式,应用程序时间戳格式和应用程序时间戳时区格式。 That way your timestamp stays a timestamp and so it sorts correctly. 这样,您的时间戳记将保持时间戳记,因此可以正确排序。 Select the application, click on the Edit Application Properties button (top rightish), click on the Globalization button (top leftish), and there you can set the date formats. 选择应用程序,单击“ 编辑应用程序属性”按钮(右上角),单击“ 全球化”按钮(左上角),然后可以在其中设置日期格式。

Since you are already calling the table output the 由于您已经在调用表输出

select to_char(ts,...) as formatteddate, original_date

columns but then in the sort do the following: 列,然后在排序中执行以下操作:

ORDER BY original_date

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

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