oracle ORA-00904: "FORMAT": 无效标识符

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

ORA-00904: "FORMAT": invalid identifier

sqloracleora-00904

提问by gary A.K.A. G4

I am trying to format a date:

我正在尝试格式化日期:

FORMAT(table.TCKT.TCKT_ISS_DATE, 'YYYY') AS TICKETYEAR

but I am getting the following error:

但我收到以下错误:

ORA-00904: "FORMAT": invalid identifier

ORA-00904: "FORMAT": 无效标识符

Right now the date show the complete timestamp. Any suggestions on how to fix this problem, or any other way to format the date to just show the four digit year?

现在日期显示完整的时间戳。关于如何解决此问题的任何建议,或任何其他方式来格式化日期以仅显示四位数年份?

回答by RedFilter

Use this function:

使用这个功能:

TO_CHAR(table.TCKT.TCKT_ISS_DATE, 'YYYY') AS TICKETYEAR 

回答by Nick Craver

You want to use TO_CHARinstead of FORMAThere, like this:

你想使用TO_CHAR而不是在FORMAT这里,像这样:

TO_CHAR(table.TCKT.TCKT_ISS_DATE, 'YYYY') AS TICKETYEAR

Oracle uses TO_CHARfor string casting, you can see here for additional format options.

OracleTO_CHAR用于字符串转换,您可以在此处查看其他格式选项

回答by David Faber

There's also the option of using EXTRACT()which is ANSI-standard and portable:

还可以选择使用EXTRACT()哪个是 ANSI 标准且可移植的:

EXTRACT(YEAR FROM table.TCKT.TCKT_ISS_DATE) AS ticketyear