1

我正在尝试使用 join 但面临这个问题。我已经粘贴了我的查询

select count(*) from table_a inner 
                join table_b on table_a.number = table_b.number 
                left outer join table_c on table_a.id = table_c.id 
                     and table_a.number = table_c.number 
          order by number;

请让我知道查询中有什么问题...

-维诺德

4

4 回答 4

1

Are you executing this query as part of an INSERT or DELETE? If so, remove the ORDER BY. It's not needed anyway.

Error: ORA-00933: SQL command not properly ended

Cause: You tried to execute an SQL statement with an inappropriate clause.

Action: The options to resolve this Oracle error are:

You may have executed an INSERT statement with an ORDER BY Clause. To resolve this, remove the ORDER BY clause and re-execute the INSERT statement. For example, you tried to execute the following INSERT statement:

INSERT INTO supplier (supplier_id, supplier_name) VALUES (24553, 'IBM') ORDER BY supplier_id;

You can correct the INSERT statement by removing the ORDER BY clause as follows:

INSERT INTO supplier (supplier_id, supplier_name) VALUES (24553, 'IBM');

You may have tried to execute a DELETE statement with an ORDER BY Clause. To resolve this, remove the ORDER BY clause and re-execute the DELETE statement. For example, you tried to execute the following DELETE statement:

DELETE FROM supplier WHERE supplier_name = 'IBM' ORDER BY supplier_id;

You can correct the DELETE statement by removing the ORDER BY clause as follows:

DELETE FROM supplier WHERE supplier_name = 'IBM';

于 2009-12-14T05:52:50.643 回答
1

When you transcribed your query to the anodyne test case you present here you inadvertently corrected it. Well, you introduced an ORA-00918 bug but once that is fixed the code runs fine...

SQL> create table table_a (col_1 number, id number)
  2  /

Table created.

SQL> create table table_b (col_1 number)
  2  /

Table created.

SQL> create table table_c (col_1 number, id number)
  2  /

Table created.

SQL>
SQL>
SQL> select count(*) from
  2  table_a inner join table_b on table_a.col_1 = table_b.col_1
  3  left outer join table_c on table_a.id = table_c.id
  4                         and table_a.col_1 = table_c.col_1
  5  order by col_1
  6  /
order by col_1
         *
ERROR at line 5:
ORA-00918: column ambiguously defined


SQL> select count(*) from
  2  table_a inner join table_b on table_a.col_1 = table_b.col_1
  3  left outer join table_c on table_a.id = table_c.id
  4                         and table_a.col_1 = table_c.col_1
  5  order by table_a.col_1
  6  /

  COUNT(*)
----------
         0

SQL>

Note: I have subsituted COL_1 for NUMBER as a column name. I don't think that's your problem, because using NUMBER unescaped in the query would hurl ORA-1747 not ORA-00933.

So, let's rule out the obvious: are you running on an ancient version of Oracle which doesn't support the ANSI join syntax, that is 8i or older?

于 2009-12-14T11:09:01.123 回答
1

你是如何执行这个查询的?

在 Oracle SQL 中,没有像“;”这样的语句分隔符。该语句仅用于 PL/SQL 中,并且某些工具允许您在文件/编辑器中放置多个语句,当您将它们用“;”分隔时。只是为了让他们可以单独执行它们。

长话短说:删除“;” 然后再试一次。哦,下一次,告诉我们你是如何运行查询的。我们必须检查我们的水晶球来猜测您的问题是什么。

于 2009-12-14T06:08:12.360 回答
1

您不能按无法包含在结果集中的值进行排序。您的结果集将多行聚合成一行,每行都有自己的 NUMBER 值。因此 order by 没有逻辑意义。在这种情况下,您的查询仅返回一行,因此 ORDER BY 无关紧要。

于 2009-12-14T11:12:22.617 回答