使用 Oracle 表字段中的值更新 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 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
Tks 中的工作更新,非常需要任何帮助
I have an existing table in an Oracle 10gR2 that I added a XMLTYPE
column to it. Now, I need to fill this field with a XML that is composed with a mixture of values from the fields of each row, but I can't get the syntax down correctly. Below is the correctly working SELECT statement that generates the desired XML for each row:
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
The UPDATE I'm trying is something like this, but it's not working:
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
I'm trying to UPDATE each row with the XML content generated from it's fields. I keep getting the error below:
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:
Just as a reference, below is the working UPDATE in Transact Sql
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
Tks so much for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Oracle 不执行 UPDATE...FROM
以下操作有效吗?
如果没有,您可以发布表定义吗?
Oracle doesn't do UPDATE...FROM
Does the following work ?
If not, can you post the table definition.