我在oracle中有一个表,并且在SQL Developer中工作,我试图获取xml字符串中的所有行,但是当我尝试使用XMLAGG在一行中进行处理时,出现异常 ORA-22275:指定的LOB定位器无效。
+------------------+
| empleados |
+------------------+
| nomina | empresa |
+--------+---------+
| 212121 | 31 |
+--------+---------+
| 212122 | 32 |
+--------+---------+
| 212123 | 33 |
+--------+---------+
这是针对Oracle 11 DB
尝试1 选择 XMLElement(“ employees”,XMLAgg (XMLElement(“ Employee”,e.nomina ||''|| e.empresa)ORDER BY nom )) AS“ Dept_list” 来自empleados e;
尝试2
SELECT XMLROOT(
XMLELEMENT("employees",
XMLAGG(
XMLELEMENT("employee",
XMLFOREST(
e.nomina AS "nomina",
e.empresa AS "empresa")
)
)
)
)
AS employees
FROM empleados e;
我希望像
这样的字符串<employees>
<employee>
<nomina>212121</nomina>
<empresa>21</empresa>
</employee>
<employee>
<nomina>212122</nomina>
<empresa>22</empresa>
</employee>
<employee>
<nomina>212123</nomina>
<empresa>23</empresa>
</employee>
</employees>
但我不断得到
ORA-22275: invalid LOB locator specified
答案 0 :(得分:0)
在尝试2中,您必须向xmlroot(xmltype,版本1)添加另一个参数。 可能的主要问题是在“ sql developer”中。缺少Java库或xmltype的疯狂转换。
尝试
xmlserialize(document
XMLELEMENT("employees",
XMLAGG(
XMLELEMENT("employee",
XMLFOREST(
e.object_id AS "nomina",
e.object_type AS "empresa")
)
)
)
as clob indent size = 2)
AS employees ...
或为varchar
xmlserialize(document
XMLELEMENT("employees",
XMLAGG(
XMLELEMENT("employee",
XMLFOREST(
e.object_id AS "nomina",
e.object_type AS "empresa")
)
)
)
as varchar2(4000) indent size = 2)
AS employees ...