意外的“无效字符” Oracle 10g 中的错误

发布于 2025-01-08 15:35:38 字数 636 浏览 5 评论 0原文

以下查询:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉鱼一梦 2025-01-15 15:35:38

我无法在 Oracle 10g 上重现您的测试用例:

SQL> create table table1 (id2 number, col2 number, col3 number, id1 number, lvl number);

Table created.

SQL> create table table2 (col1 number, col2 number, col3 number, col4 number, lvl number);

Table created.

SQL> create view view_name_here as
  2  SELECT DISTINCT table1_alias.id2 AS col1 ,
  3                  table1_alias.col2,
  4                  table1_alias.col3
  5  FROM table1
  6  INNER JOIN table1 table1_alias
  7     ON table1.id1 =table1_alias.id2
  8  WHERE  table1_alias.id2<>-55   AND table1_alias.LVL=1
  9  UNION
 10  SELECT col1 ,col2,col3
 11  FROM table2 WHERE col1> 0 AND col4 = 1
 12  AND LVL = 2;

View created.

SQL> select * from view_name_here;

no rows selected

I cannot reproduce your test case on Oracle 10g:

SQL> create table table1 (id2 number, col2 number, col3 number, id1 number, lvl number);

Table created.

SQL> create table table2 (col1 number, col2 number, col3 number, col4 number, lvl number);

Table created.

SQL> create view view_name_here as
  2  SELECT DISTINCT table1_alias.id2 AS col1 ,
  3                  table1_alias.col2,
  4                  table1_alias.col3
  5  FROM table1
  6  INNER JOIN table1 table1_alias
  7     ON table1.id1 =table1_alias.id2
  8  WHERE  table1_alias.id2<>-55   AND table1_alias.LVL=1
  9  UNION
 10  SELECT col1 ,col2,col3
 11  FROM table2 WHERE col1> 0 AND col4 = 1
 12  AND LVL = 2;

View created.

SQL> select * from view_name_here;

no rows selected
夏至、离别 2025-01-15 15:35:38

我怀疑您的视图名称包含无效字符,但在创建该名称时,该名称被用双引号引起来(根据文档,这是一个“带引号的标识符”),因此是允许的;并且在查询时省略双引号。类似于:

create view "MY~VIEW" as select * from dual;

View created.

select * from MY~VIEW;
                *
Error at line 1:
ORA-00911: invalid character

但这是有效的:

select * from "MY~VIEW";

D
-
X

当然,实际字符可能是其他字符,但错误(至少在 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:

create view "MY~VIEW" as select * from dual;

View created.

select * from MY~VIEW;
                *
Error at line 1:
ORA-00911: invalid character

But this works:

select * from "MY~VIEW";

D
-
X

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文