简体   繁体   English

如何修复Oracle中SQL中的“ ORA-01801:日期格式对于内部缓冲区而言太长”错误

[英]How to fix “ORA-01801: date format is too long for internal buffer” error in SQL in Oracle

I am working on an assignment where I need to display the system date in a very specific way in SQL. 我正在做一个作业,需要在SQL中以非常特定的方式显示系统日期。 The form is supposed to be as follows: 该表格应如下所示:

Day of the week with just the first letter capitalized, the month number in Roman Numerals (capitalized), the day of the month, the year spelled out in capital letters with anno domini, the day of the year from the Julian calendar with the phrase "Day of the year", number of seconds past midnight with the phrase "Seconds past midnight" 星期几,首字母大写,罗马数字(大写)中的月号,月日,大写字母中用anno domini拼写的年份,朱利安历法中的每年的日期用短语“一年中的某天”,午夜之后的秒数,短语“午夜之后的秒数”

I reached up to the actual number of seconds past midnight, but I can't seem to add "Seconds past midnight" to it. 我已达到午夜之后的实际秒数,但似乎无法在其中添加“午夜之后的秒数”。

I have looked for syntax online and didn't find exactly what I needed. 我已经在网上寻找语法,但没有找到我真正需要的语法。 It's possible my search queries weren't worded correctly or that I didn't look far enough. 我的搜索查询的措词可能不正确,或者看起来不够好。 My textbook isn't very clear to me on this, either. 我的课本对此也不是很清楚。 The only thing I've seen in there is an explanation of the difference between CURRENTDATE and SYSDATE . 我唯一看到的是对CURRENTDATESYSDATE之间的区别的解释。

This is what I have so far. 到目前为止,这就是我所拥有的。 I realize it may be entirely wrong. 我意识到这可能是完全错误的。 I have attempted it without the + and also without the quotes around the phrase. 我尝试过不带+ ,也没有带引号的短语。

SELECT TO_CHAR
    (SYSDATE, 'Dy, RM, D, YEAR AD, DDD "Day of the year", SSSSS "Seconds past midnight") "NOW"
     FROM DUAL;

I expected the output to say Fri, IV, 19, TWENTY NINETEEN AD, 109 Day of the year, 73829 Seconds past midnight but it's giving me the following error: ORA-01801: date format is too long for internal buffer 我希望输出显示Fri, IV, 19, TWENTY NINETEEN AD, 109 Day of the year, 73829 Seconds past midnight但它给了我以下错误: ORA-01801: date format is too long for internal buffer

You could cheat - concatenate the last hardcoded text to the result of TO_CHAR, instead of including it in the format model. 您可以作弊-将最后一个硬编码的文本连接到TO_CHAR的结果,而不是将其包括在格式模型中。

SELECT TO_CHAR(SYSDATE, 'Dy, RM, DD, YEAR AD, DDD "Day of the year ", SSSSS')
       || ' Seconds past midnight' "NOW"
FROM DUAL;



NOW
----------------------------------------------------------------------------------
Fri, IV  , 19, TWENTY NINETEEN AD, 109 Day of the year , 54236 Seconds past midnight

Note also that the third format element must be DD (you have D, which will not give you the two-digit day of the month, in this case 19). 另请注意,第三个格式元素必须为DD(您有D,它将不会为您提供月份的两位数字,在这种情况下为19)。

Further clarification on the error you got: This is written in the Oracle documentation 有关错误的进一步说明:这写在Oracle文档中

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/Format-Models.html#GUID-49B32A81-0904-433E-B7FE-51606672183A https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/Format-Models.html#GUID-49B32A81-0904-433E-B7FE-51606672183A

The total length of a datetime format model cannot exceed 22 characters. 日期时间格式模型的总长度不能超过22个字符。

However, a quick count shows that the length of the format model in my solution is in fact more than 22 characters. 但是,快速计数表明,我的解决方案中格式模型的长度实际上超过22个字符。 It is not uncommon for Oracle documentation to be plain wrong. Oracle文档经常会犯错误。 In this case, there seems to be a limit to the length of a format model, even though it is not the one in the documentation... 在这种情况下,格式模型的长度似乎受到限制,即使不是文档中的格式模型也是如此。

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

相关问题 ORA-06502:PL / SQL:数字或值错误:Oracle SQL查询中的字符串缓冲区太小 - ORA-06502: PL/SQL: numeric or value error: character string buffer too small in Oracle sql query sql 中的 oracle 'ora-01843' 日期格式错误 - oracle 'ora-01843' date format error in the sql Oracle数据库错误:ORA-06502:PL / SQL:数字或值错误:字符串缓冲区太小 - Oracle Database Error: ORA-06502: PL/SQL: numeric or value error: character string buffer too small Oracle SQL 错误代码 ORA-06502: PL/SQL: numeric or value error: string buffer too small at line 18 - Oracle SQL Error Code ORA-06502: PL/SQL: numeric or value error: character string buffer too small at line 18 ORA-01840: 输入值对于日期格式不够长 SQL Oracle - ORA-01840: input value not long enough for date format SQL Oracle 奇怪的Oracle错误:标识符太长ORA-00972 - Strange Oracle error: Identifier too long ORA-00972 SQL错误:ORA-01489:字符串连接的结果太长 - SQL Error: ORA-01489: result of string concatenation is too long Oracle SQL:日期字段上的 ORA-01858 错误 - Oracle SQL: ORA-01858 error on date fields 将日期传递给 Oracle SQL 中的存储过程错误:ORA-01858 - Passing date to Stored Procedure in Oracle SQL error : ORA-01858 Oracle-创建xmlindex时出现“ ORA-01704:字符串文字太长”错误 - Oracle - “ORA-01704: string literal too long” error while creating xmlindex
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM