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

时间:2020-03-05 18:41:20  来源:igfitidea点击:

例子:

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

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

返回不同的结果

解决方案

回答

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

本质上,第一个示例将假定81是2081,而RR则假定是1981. 因此,第一个示例不应返回任何行,因为我们很可能在2081年5月1日之后尚未雇用任何人:-)

回答

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

请参阅:http://www.oradev.com/oracle_date_format.jsp

编辑:该死!迈克尔" quickfingers" stum击败了我!

/ mp

回答

@迈克尔·斯托姆

My last Oracle experience is a bit long ago

嗯,是在2000年之前吗? :p

...

Will yy always assume 19xx?

根据消息来源,我们得到以下情况:

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

回答

RR代表1990年以后,yy假设90代表2090。