使用其字段中的值更新Oracle表中的XMLTYPE

时间:2011-03-03 01:09:55

标签: oracle ora-00933 xmltype

我在Oracle 10gR2中有一个现有表,我在其中添加了XMLTYPE列。现在,我需要用一个XML组成这个字段,该XML由每行字段中的值组合而成,但是我无法正确地理解语法。下面是正确工作的SELECT语句,它为每一行生成所需的XML:

SELECT XMLELEMENT("TBLOrigs",
  XMLELEMENT("TBLOrig", XMLATTRIBUTES(Field1 AS "Field1"),
  XMLFOREST(Field2 AS "Field2", Field3 AS "Field3", Field4 AS "Field4", Field5 AS "Field5"),
    XMLELEMENT("Dets",
    XMLFOREST(Field6, Field7 AS "Field7")))) AS XmlCol
  FROM TBLOrigin Orig1
WHERE Field1 <= 10

我正在尝试的更新是这样的,但它不起作用:

UPDATE TBLOrigin
SET AUXFIELD = (
  SELECT XMLELEMENT("TBLOrigs",
  XMLELEMENT("TBLOrig", XMLATTRIBUTES(Field1 AS "Field1"),
  XMLFOREST(Field2 AS "Field2", Field3 AS "Field3", Field4 AS "Field4", Field5 AS "Field5"),
    XMLELEMENT("Dets",
    XMLFOREST(Field6, Field7 AS "Field7")))) AS XmlCol
  FROM TBLOrigin Orig1
  WHERE Orig1.Field1 = Orig2.Field1
  AND Orig1.Field2 = Orig2.Field2
  AND Orig1.Field3 = Orig2.Field3
  AND Orig1.Field4 = Orig2.Field4
  AND Orig1.Field5 = Orig2.Field5)
FROM TBLOrigin Orig2
WHERE Field1 <= 10

我正在尝试使用从其字段生成的XML内容更新每一行。我一直收到以下错误:

Erro na Linha de Comando:13 Coluna:47
Relatório de Erro:
Erro de SQL: ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"
*Cause:    
*Action:

作为参考,下面是Transact Sql中正在运行的UPDATE

UPDATE dbo.TBLOrigin
SET AuxInfo = (SELECT 
  Field1 as "@Field1",
  Field2 as "Field2", 
  Field3 as "Field3", 
  Field4 as "Field4", 
  Field5 as "Field5", 
  Field6 as "Dets/Field6", 
  Field7 as "Dets/Field7"
FROM dbo.TBLOrigin AS Orig1
WHERE Orig1.Field1 = Orig2.Field1
AND Orig1.Field2 = Orig2.Field2
AND Orig1.Field3 = Orig2.Field3
AND Orig1.Field4 = Orig2.Field4
AND Orig1.Field5 = Orig2.Field5
  FOR XML PATH('TBLOrig'), TYPE, ROOT('TBLOrigs'))
FROM dbo.TBLOrigin Orig2

非常感谢任何帮助

1 个答案:

答案 0 :(得分:1)

Oracle不执行UPDATE ... FROM

以下是否有效?

UPDATE TBLOrigin
SET AUXFIELD = 
       XMLELEMENT("TBLOrigs",
         XMLELEMENT("TBLOrig", XMLATTRIBUTES(Field1 AS "Field1"),
         XMLFOREST(Field2 AS "Field2", Field3 AS "Field3", 
                   Field4 AS "Field4", Field5 AS "Field5"),
         XMLELEMENT("Dets",
            XMLFOREST(Field6, Field7 AS "Field7")))) AS XmlCol
WHERE Field1 <= 10

如果没有,您可以发布表格定义。