连接中的Oracle表别名

时间:2014-05-12 10:26:00

标签: sql oracle oracle10g

是否可以在ON-Statement中使用表别名?

SQL语句:

SELECT XMLELEMENT("row", XMLATTRIBUTES(rownum as "order"),
    (
       SELECT
          XMLAGG(XMLELEMENT("attribute",XMLATTRIBUTES(z as "identifier") ) )
       FROM b
       LEFT JOIN c
          ON c.ID = b.cID 
          AND c.example = table_alias.example
    )
)
FROM
(
    SELECT example FROM x ORDER BY y
) table_alias

我收到table_alias.example是无效标识符的错误。 如果我将c.example = table_alias.example移动到WHERE语句中它可以工作,但当然我会得到错误的结果。

有人有想法吗?

TY frgtv10

1 个答案:

答案 0 :(得分:-1)

试试这个

   SELECT XMLELEMENT("row", XMLATTRIBUTES(rownum as "order"),
         ( SELECT XMLAGG(XMLELEMENT("attribute"),XMLATTRIBUTES(z as "identifier") ) ) 
            FROM b, c, x
            where c.ID = b.cID(+) AND c.example = x.example
         )
    ) from dual