导入日期格式 mmddyyyy

发布于 2024-07-19 05:44:52 字数 146 浏览 11 评论 0 原文

我必须使用这种类型的格式

03JUN2008

将日期导入到 oracle 中,这是我之前见过的唯一一个例子,其中有破折号,而这个没有。

我应该将其作为 varchar 引入并进行操作还是还有其他方法?

谢谢

I have to import dates into oracle with this type of format

03JUN2008

The only example I've seen this done before has dashes and this does not.

Should I just bring it in as varchar and manipulate or is there another way?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

亣腦蒛氧 2024-07-26 05:44:52

如果是日期,则将其存储为日期,不要将其存储为 varchar 或任何类似的废话。

您到底打算如何“导入”数据?

如果您只是使用 sql 语句,则使用 TO_DATE

MWATSON@:> create table date_test ( x date );

Table created.

MWATSON@:> insert into date_test values ( to_date('03JUN2008','DDMONYYYY') );

1 row created.

MWATSON@:> select * from date_test;

X
-----------
03-Jun-2008

1 row selected.

MWATSON@DEV2:>

如果您通过 SQL*Loader 导入,您可以在控制文件中指定日期格式

> cat date_test.ldr 
LOAD DATA
INFILE *
APPEND
INTO TABLE date_test
FIELDS TERMINATED BY '|'
(x DATE 'DDMONYYYY')
BEGINDATA
01JAN1999
> sqlldr mwatson control=date_test.ldr
....
Commit point reached - logical record count 1
> sqlplus 
....
MWATSON:> select * from date_test;

X
-----------
03-Jun-2008
01-Jan-1999

2 rows selected.

MWATSON@:> 

If its a date, then store it as a date, don't mess about with storing it as a varchar or any nonsense like that.

How exactly are you planning to "import" the data?

If you are just using sql statements, then use TO_DATE

MWATSON@:> create table date_test ( x date );

Table created.

MWATSON@:> insert into date_test values ( to_date('03JUN2008','DDMONYYYY') );

1 row created.

MWATSON@:> select * from date_test;

X
-----------
03-Jun-2008

1 row selected.

MWATSON@DEV2:>

If you are importing via SQL*Loader you can specify the date format in the control file

> cat date_test.ldr 
LOAD DATA
INFILE *
APPEND
INTO TABLE date_test
FIELDS TERMINATED BY '|'
(x DATE 'DDMONYYYY')
BEGINDATA
01JAN1999
> sqlldr mwatson control=date_test.ldr
....
Commit point reached - logical record count 1
> sqlplus 
....
MWATSON:> select * from date_test;

X
-----------
03-Jun-2008
01-Jan-1999

2 rows selected.

MWATSON@:> 
可是我不能没有你 2024-07-26 05:44:52

我不知道我是否完全明白你的意思,但我认为你可以简单地使用 TO_DATE 来做到这一点,这里有示例和详细信息

http://www.techonthenet.com/oracle/functions/to_date.php

I don't know if i quite catch what you mean but i think that you can do this simply with TO_DATE, examples and details here

http://www.techonthenet.com/oracle/functions/to_date.php

温柔戏命师 2024-07-26 05:44:52

为了得到一个好的答案,您必须提前考虑在 Oracle 如何内部存储日期的背景下您将如何处理这些日期。

例如,如果你

to_date('03JUN2008','DDMONYYYY')

按照马修的建议去做,你真正会得到的是:

03-JUN-2008 00:00:00

为什么这会成为一个问题? 假设您使用该日期来测试当天结束的情况,例如计算截至 2008 年 6 月 3 日(含该日期)提交的所有用户评论。 如果您与上面的日期进行比较,您最终将排除该日期发表的所有评论,因为它们都是在 00:00 多小时发表的。

因此,在这种情况下,您需要添加时间以使其真正结束一天,例如:

to_date('03JUN2008','DDMONYYYY')+0.999988425925926

这将为您提供:

03-JUN-2008 23:59:59

In order to get a good answer, you have to think ahead of time what you are going to do with those dates in the context of how Oracle stores dates internally.

For example if you do

to_date('03JUN2008','DDMONYYYY')

as Matthew suggested, what you will really get is:

03-JUN-2008 00:00:00

Why would this be a problem? Let's say you use that date to test against end-of-day, such as counting all user comments submitted up to, and including, 06/03/2008. If you compare against the date above, you will end up excluding all comments made on that date since they will all be made at 00:00 plus hours.

So in that case you will need to add the time to make it truly end of day, for example:

to_date('03JUN2008','DDMONYYYY')+0.999988425925926

which will give you:

03-JUN-2008 23:59:59
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文