SQL oracle的'yy'和'rr'日期掩码有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19058/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 23:08:02  来源:igfitidea点击:

What is the difference between oracle's 'yy' and 'rr' date mask?

sqloracle

提问by juan

Example:

例子:

select ename from emp where hiredate = todate('01/05/81','dd/mm/yy')

and

select ename from emp where hiredate = todate('01/05/81','dd/mm/rr')

return different results

返回不同的结果

回答by Michael Stum

http://oracle.ittoolbox.com/groups/technical-functional/oracle-dev-l/difference-between-yyyy-and-rrrr-format-519525

http://oracle.ittoolbox.com/groups/technical-functional/oracle-dev-l/difference-between-yyyy-and-rrrr-format-519525

YY allows you to retrieve just two digits of a year, for example, the 99 in 1999. The other digits (19) are automatically assigned to the current century. RR converts two-digit years into four-digit years by rounding.

50-99 are stored as 1950-1999, and dates ending in 00-49 are stored as 2000-2049. RRRR accepts a four-digit input (although not required), and converts two-digit dates as RR does. YYYY accepts 4-digit inputs butdoesn't do any date converting

YY 允许您仅检索年份的两位数字,例如,1999 年的 99。其他数字 (19) 将自动分配给当前世纪。RR 通过四舍五入将两位数的年份转换为四位数的年份。

50-99 存储为 1950-1999,以 00-49 结尾的日期存储为 2000-2049。RRRR 接受四位数的输入(尽管不是必需的),并像 RR 一样转换两位数的日期。YYYY 接受 4 位输入但不进行任何日期转换

Essentially, your first example will assume that 81 is 2081 whereas the RR one assumes 1981. So the first example should not return any rows as you most likely did not hire any guys after May 1 2081 yet :-)

本质上,您的第一个示例将假设 81 是 2081,而 RR 假设是 1981。因此,第一个示例不应返回任何行,因为您很可能在 2081 年 5 月 1 日之后还没有雇用任何人:-)

回答by mauriciopastrana

@Michael Stum

@迈克尔·斯图姆

My last Oracle experience is a bit long ago

我上一次 Oracle 体验是很久以前的事了

uhm, was it, before 2000? :p

呃,是2000年之前吗?:p

...

...

Will yy always assume 19xx?

yy 总是假设 19xx 吗?

according to your source, we get the following scenarios:

根据您的消息来源,我们得到以下场景:

USING
ENTERED
STORED
SELECT of date column


YY
22-FEB-01
22-FEB-1901
22-FEB-01


YYYY
22-FEB-01
22-FEB-0001
22-FEB-0001


RR
22-FEB-01
22-FEB-2001
22-FEB-01


RRRR
22-FEB-01
22-FEB-2001
22-FEB-2001 

/mp

/mp

回答by mauriciopastrana

y2k compatibility. rr assumes 01 to be 2001, yy assumes 01 to be 1901

y2k 兼容性。rr 假设 01 为 2001,yy 假设 01 为 1901

see: http://www.oradev.com/oracle_date_format.jsp

见:http: //www.oradev.com/oracle_date_format.jsp

edit: damn! michael "quickfingers" stumbeat me to it!

编辑:该死!michael "quickfinger" stum击败了我

/mp

/mp

回答by hariharan

RR displays four digits as 1999 or 2015(if it is <49 then it will consider 20th century)

RR 显示四位数字为 1999 或 2015(如果小于 49 则考虑 20 世纪)

回答by Pritam Bhansali

About RR or RRRR

关于RR或RRRR

When we are inserting the dates with 2 digits years (i.e. 09/oct/15) then Oracle may changes the centuries automatically hence the solution is 4 digit dates. But 4 digit version is introduced in some recent versions, therefore the solutions for this problem in earlier versions was RRor RRRR. But note that it only works with the TO_DATE()function but not with the TO_CHAR()function.

当我们插入带有 2 位数年份的日期(即 09/oct/15)时,Oracle 可能会自动更改世纪,因此解决方案是 4 位数日期。但是最近的一些版本引入了4位版本,因此早期版本解决这个问题的方法是RRRRRR。但请注意,它仅适用于该TO_DATE()函数,而不适用于该TO_CHAR()函数。

Whenever inserts/updates are conducted upon dates we should always clarify current date running in the clock in association with the date translation since Oracle conducts every date translation by contacting the server.

每当在日期上执行插入/更新时,我们应该始终澄清与日期转换相关的时钟中运行的当前日期,因为 Oracle 通过联系服务器来执行每个日期转换。

In order to keep the consistencies among the centuries, it is always better to execute the date translation with 4 digit years.

为了保持世纪之间的一致性,最好使用 4 位年份执行日期转换。

About YY or YYYY

关于 YY 或 YYYY

It accepts the dates but doesn't has functionality to automatically change it.

它接受日期,但没有自动更改它的功能。

This Image shows behaviour when inserting date with two digit (i.e. 09/oct/15)

此图像显示插入两位数日期时的行为(即 09/oct/15)

回答by vivek

RR stands for after 1990 and yy assumes 90 as 2090....as we are in the current yr,...

RR 代表 1990 年之后,yy 假设 90 为 2090 年......因为我们在今年,......