资讯

展开

sqlserver-openxml-函数在达梦中实现

作者:快盘下载 人气:

sqlserver实现;
DECLARE ;idoc int
DECLARE ;doc varchar(1000)
SET ;doc =;
<ROOT>
<Customer CustomerID=;VINET; ContactName=;Paul Henriot;>
   <Order CustomerID=;VINET; EmployeeID=;5; OrderDate=;1996-07-04T00:00:00;>
      <OrderDetail OrderID=;10248; ProductID=;11; Quantity=;12;/>
      <OrderDetail OrderID=;10248; ProductID=;42; Quantity=;10;/>
   </Order>
</Customer>
<Customer CustomerID=;LILAS; ContactName=;Carlos Gonzlez;>
   <Order CustomerID=;LILAS; EmployeeID=;3; OrderDate=;1996-08-16T00:00:00;>
      <OrderDetail OrderID=;10283; ProductID=;72; Quantity=;3;/>
   </Order>
</Customer>
</ROOT>;
--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument ;idoc OUTPUT, ;doc
-- Execute a SELECT statement that uses the OPENXML rowset provider.
SELECT    *
FROM       OPENXML (;idoc, ;/ROOT/Customer;,1)
            WITH (CustomerID  varchar(10),
                  ContactName varchar(20))
达梦实现;

--提前创建表

create  table xmldata_t(C1 VARCHAR2);

DECLARE ;idoc int;
 ;doc varchar(1000);
 begin
SET ;doc =;
<ROOT>
<Customer CustomerID=;VINET; ContactName=;Paul Henriot;>
   <Order CustomerID=;VINET; EmployeeID=;5; OrderDate=;1996-07-04T00:00:00;>
      <OrderDetail OrderID=;10248; ProductID=;11; Quantity=;12;/>
      <OrderDetail OrderID=;10248; ProductID=;42; Quantity=;10;/>
   </Order>
</Customer>
<Customer CustomerID=;LILAS; ContactName=;Carlos Gonzlez;>
   <Order CustomerID=;LILAS; EmployeeID=;3; OrderDate=;1996-08-16T00:00:00;>
      <OrderDetail OrderID=;10283; ProductID=;72; Quantity=;3;/>
   </Order>
</Customer>
</ROOT>;;
--Create an internal representation of the XML document.
--call sp_xml_preparedocument ;idoc OUTPUT, ;doc
-- Execute a SELECT statement that uses the OPENXML rowset provider.
SF_SET_SESSION_PARA_VALUE(;ENABLE_TABLE_EXP_REF_FLAG;, 1);开启同层列引用该参数
insert into xmldata_t select ;doc ;
SELECT   CustomerID,ContactName
FROM      xmldata_t    ,xmltable(;/ROOT/Customer; PASSING ;doc COLUMNS CustomerID
VARCHAR2 PATH ;;CustomerID;, ContactName VARCHAR2 PATH ;;ContactName;);
       --( select (XMLPARSE(document;doc)));
       --( select (XMLQUERY(;doc, ;/ROOT/Customer;)));
       --( select (sf_xmlquery(;doc, ;/ROOT/Customer;)));
         --WITH (CustomerID  varchar(10),ContactName varchar(20));
delete from  xmldata_t;
end 

加载全部内容

相关教程
猜你喜欢
用户评论
快盘暂不提供评论功能!