"SQL command not properly ended" 使用子查询时

"SQL command not properly ended" when using subquery

我有以下查询工作:

select 
    a.column_value as artigo 
from 
    encomenda e, table(e.artigos) a 
where 
    e.id = 2;

此查询 returns 以下输出(一行 menu_t 类型和另一行 bebida_menu_t 类型)。请注意,这不是简单的文本,而是我自己定义的类型的对象,因为这是一个对象关系数据库。

根据该结果,我只想提取 menu_t 行。所以,我尝试了以下查询:

select * 
from (select 
          a.column_value as artigo 
      from 
          encomenda e, table(e.artigos) a 
      where e.id = 2) as subquery 
where 
    subquery.artigo is of (menu_t); 

这给了我错误

  1. 00000 - "SQL command not properly ended"

我不明白为什么。

更新:

似乎问题出在 as 关键字上。所以,应该是:

select * 
from (select 
          a.column_value as artigo 
      from 
          encomenda e, table(e.artigos) a 
      where e.id = 2) subquery --removed the 'as' here
where 
    value(subquery.artigo) is of (menu_t); --added value() because they were inconsistent types

但是,现在我收到错误消息说 subquery.artigo 是一个无效的标识符。

  1. 00000 - "%s: invalid identifier"

您需要更改:

where subquery.artigo is of (menu_t);

where subquery.artigo LIKE '%MENU_T';

因此,要解决第一个问题,正如我在更新中所说,在 Oracle 中我们不应该在别名上使用 as 关键字。因此,查询变为:

select * 
from (select 
          a.column_value artigo 
      from 
          encomenda e, table(e.artigos) a 
      where e.id = 2) subquery 
where 
    subquery.artigo is of (menu_t); 

但在此之后,我又遇到了另一个错误,如更新中所述。发生的事情是我试图在 REF 中使用 is of,它警告我这是一个无效的标识符,但我花了一些时间,并且多次尝试实现正确的查询。所以,我需要在 art.column_value 列上使用 deref()

毕竟,我什至不需要嵌套子查询。最终查询为:

select value(e).id id, art.column_value artigo 
from encomenda e, table(e.artigos) art 
where e.id = 2 and 
deref(art.column_value) is of (menu_t);