通过 Oracle 显示时间格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8134003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display time format through Oracle
提问by JLearner
I wish to view my column time as 'hh24:mi:ss' but even i insert it as to_date('13:00:00','hh24:mi:ss'). It still displays as date format. I have tried different methods to convert and i don't wish to alter the session.
我希望将我的列时间查看为 'hh24:mi:ss' 但即使我将其插入为 to_date('13:00:00','hh24:mi:ss')。它仍然显示为日期格式。我尝试了不同的转换方法,但我不想改变会话。
Here's my table created:
这是我创建的表:
CREATE TABLE Test
(
Name VARCHAR2(20),
Description Varchar2(20),
StudyTime Date,
SleepTime Date,
);
Insert:
插入:
INSERT INTO Test
VALUES('JUDY','STUDYING AT ABC', (To_Date('01:00:00', 'HH24:MI:SS')),
(TO_DATE('06:35:00', 'HH:MI:SS')));
Display results:
显示结果:
Judy,Studying at abc,11-Nov-2011,11-Nov-2011
Thanks for anyone help!
感谢任何人的帮助!
回答by Ollie
Your IDE or SQL*Plus settings are displaying the default date format of DD-Mon-YYYY
.
Even though you are entering just a time format, oracle will still see it as a full date and time, hence the 11-Nov-2011 date (you need to be aware of this!).
您的 IDE 或 SQL*Plus 设置显示的默认日期格式为DD-Mon-YYYY
. 即使您输入的只是时间格式,oracle 仍会将其视为完整的日期和时间,因此是 2011 年 11 月 11 日的日期(您需要注意这一点!)。
When you then select all columns whichever interface you are using to display the results will show you the character representation of the date columns, if you have not specified what that is it will use the default NLS format settings. See: http://www.adp-gmbh.ch/ora/admin/nls_levels.html
当您选择所有列时,无论您使用哪个界面来显示结果,都会向您显示日期列的字符表示,如果您没有指定它是什么,它将使用默认的 NLS 格式设置。见:http: //www.adp-gmbh.ch/ora/admin/nls_levels.html
Either change the NLS date format settings or specify using TO_CHAR
what format you want the results.
更改 NLS 日期格式设置或指定使用TO_CHAR
您想要结果的格式。
Try:
尝试:
SELECT name,
description,
TO_CHAR(studytime, 'HH24:MI:SS') as studytime,
TO_CHAR(sleeptime, 'HH:MI:SS') as sleeptime
FROM test;
N.B. I used HH24
for studytime
and HH
for sleeptime
as you have done in your example when entering your values.
注意,在输入值时,我使用了HH24
forstudytime
和HH
for ,sleeptime
就像您在示例中所做的那样。
This should disply it in the correct format.
这应该以正确的格式显示它。