朋友们,
我正在使用Oracle 10g,我需要使用以下xml格式的SQL从表中生成结果:
7839
KING
7369
SMITH
... Rest of the EMP table records
excluding KING
规则是显示在外部行中选择的记录,子行应包含除外部行中显示的记录之外的所有其他记录.记录没有层次结构.
在上面的示例中,在外部行中选择了King,因此子行应包含来自emp的所有记录,不包括King.
这个查询给了我需要的结果集:
select e.empno,
e.ename,
cursor(select empno,
ename
from emp where empno <> 7839)
from emp e
where empno = 7839
但是,当我尝试使用以下方法从此生成XML时:
select xmlelement("RESULTS",
xmlagg(xmlelement("ROW",
xmlelement("EMPNO", empno),
xmlelement("ENAME", ename),
cursor(SELECT xmlagg(xmlelement("SUBROWS", xmlelement("ROW",
xmlelement("EMPNO", empno),
xmlelement("ENAME", ename)
)
)
)
FROM emp
WHERE empno <> 7839
)
)
)
)
from emp
where empno = 7839
我收到以下错误:
ORA-22902: CURSOR expression not allowed
22902. 00000 - "CURSOR expression not allowed"
*Cause: CURSOR on a subquery is allowed only in the top-level
SELECT list of a query.
我尝试过使用DBMS_XMLGEN:
SELECT DBMS_XMLGEN.getXML('select empno,
ename,
cursor(select empno,
ename
from emp
where empno <> 7839) as SUBROWS
from emp
where empno = 7839')
FROM dual
Whist以预期的格式输出XML,但它没有显示正确的元素名称.
任何帮助解决这个问题将非常感激.
提前致谢