意外的“无效字符” Oracle 10g 中的错误
以下查询:
SELECT * FROM VIEW_NAME_HERE
导致ORA-00911:无效字符
错误。我尝试使用 SQL Developer、Oracle SQL Developer、Toad 以及 java 应用程序来执行它。
VIEW_NAME_HERE
是一个视图。用于创建视图的 SQL 查询如下:
SELECT DISTINCT table1_alias.id2 AS col1 ,
table1_alias.col2,
table1_alias.col3
FROM table1
INNER JOIN table1 table1_alias
ON table1.id1 =table1_alias.id2
WHERE table1_alias.id2<>-55 AND table1_alias.LVL=1
UNION
SELECT col1 ,col2,col3
FROM table2 WHERE col1> 0 AND col4 = 1
AND LVL = 2
从其他视图和表中选择 * 可以正常工作。
欢迎任何提示。
The following query:
SELECT * FROM VIEW_NAME_HERE
causes ORA-00911: invalid character
error. I tried to execute it using SQL Developer, Oracle SQL Developer, Toad, and from a java application.
VIEW_NAME_HERE
is a view. The SQL query used to create the view follows:
SELECT DISTINCT table1_alias.id2 AS col1 ,
table1_alias.col2,
table1_alias.col3
FROM table1
INNER JOIN table1 table1_alias
ON table1.id1 =table1_alias.id2
WHERE table1_alias.id2<>-55 AND table1_alias.LVL=1
UNION
SELECT col1 ,col2,col3
FROM table2 WHERE col1> 0 AND col4 = 1
AND LVL = 2
SELECT *
from other views and tables works normally.
Any hints are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法在 Oracle 10g 上重现您的测试用例:
I cannot reproduce your test case on Oracle 10g:
我怀疑您的视图名称包含无效字符,但在创建该名称时,该名称被用双引号引起来(根据文档,这是一个“带引号的标识符”),因此是允许的;并且在查询时省略双引号。类似于:
但这是有效的:
当然,实际字符可能是其他字符,但错误(至少在 SQL*Plus 中)有助于使用
*
突出显示它。 SQL 参考中有一个有关命名对象的部分;我猜你违反了规则 7。将对象名称括在双引号中不被认为是好的做法(尽管我确信意见有所不同),通常是因为它会导致大小写差异的问题,但可能会产生其他像这样的微妙影响。去掉引号,让 Oracle 用大写名称创建所有对象,并在对象创建时发现任何问题,要容易得多。
I suspect your view name contains an invalid character, but that when it was created the name was enclosed in double-quotes (a 'quoted identifier' according to the docs) so it was allowed; and when querying you're omitting the double-quotes. Something like:
But this works:
The actual character could be something else, of course, but the error (at least in SQL*Plus) helpfully highlights it with the
*
. The SQL reference has a section on naming objects; I'm guessing you're breaking rule 7.Enclosing object names in double quotes is not considered good practice (though I'm sure opinions vary), usually because it causes problems with case differences, but can have other subtle effects like this. It's much easier to leaves the quotes off, let Oracle create all your objects with upper-case names, and spot any problems at object creation time.