これらの例は、<xsl:copy-of select="">および<xsl:value-of select="">の両方のマッピング定義を使用する方法を示しています。
この例を実行する前に、必要な権限を持つテスト ユーザーが作成され、必要なテーブルが作成されていることを確認します。参照整合性ルールについては、XSLT_SHRED_BATCHとXSLT_SHREDの例の設定を参照してください。
XMLソース文書を格納するために使用するステージング テーブルにデータを挿入します。
DELETE Offer; DELETE Input_Docs; INSERT INTO Input_Docs VALUES(1, CREATEXML('<?xml version="1.0"?> <Root> <predictixOfferMessage> <Offer><offerid>1000001</offerid></Offer> <mediaBlock><mediaBlockid>90000000010001</mediaBlockid></mediaBlock> </predictixOfferMessage> <predictixOfferMessage> <Offer><offerid>1000003</offerid></Offer> <mediaBlock><mediaBlockid>90000000010003</mediaBlockid></mediaBlock> </predictixOfferMessage> </Root>'));
スタイルシート マッピングによってXSLT_SHRED_BATCHストアド プロシージャを呼び出し、ステージング入力テーブルに格納されるXMLデータをシュレッドします。次の引数を呼び出しに使用します。
- queryStringは、次のようになります: sel * from xsltuser.Input_Docs
- xsltMapping引数は、スタイルシートを入力とするCREATEXML関数を呼び出すことで指定します。このスタイルシートは、XML文書に適用されます。
- この例では、externalContextはNULLです。
- resultCodeは:res.で返されます。操作が成功すると0が返されます。
CALL TD_SYSXML.XSLT_SHRED_BATCH('sel * from xsltuser.Input_Docs', CREATEXML('<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/Root"> <Transaction> <Insert> <Table> <xsltuser.Offer> <xsl:for-each select="predictixOfferMessage"> <Row> <xsl:copy-of select="Offer/offerid"/> <mediaBlockid><xsl:value-of select="mediaBlock/mediaBlockid"/></mediaBlockid> </Row> </xsl:for-each> </xsltuser.Offer> </Table> </Insert> </Transaction> </xsl:template> </xsl:stylesheet>'), NULL, :res);
結果: ターゲット テーブルで更新されたデータを表示するには次を実行します。SELECT offerid, mediaBlockid FROM Offer;
offerid mediaBlockid ---------- ---------------------------- 1000003 90000000010003 1000001 90000000010001
これは、<xsl:copy-of select="">および<xsl:value-of select="">の両方のマッピング定義を使用する方法を示すもう1つの例です。
この例を実行する前に、必要な権限を持つテスト ユーザーが作成され、必要なテーブルが作成されていることを確認します。参照整合性ルールについては、XSLT_SHRED_BATCHとXSLT_SHREDの例の設定を参照してください。
XMLソース文書を格納するために使用するステージング テーブルにデータを挿入します。
DELETE Customer; DELETE Input_Docs; INSERT INTO Input_Docs VALUES(1, CREATEXML('<?xml version="1.0" encoding="UTF-8"?> <customers> <customer> <c_custkey>1805</c_custkey> <c_name>Customer#000001805</c_name> <c_address>ZERs4Cu5lQTYD</c_address> <c_nationkey>9</c_nationkey> <c_phone>19-679-706-1096</c_phone> <c_acctbal>-274.75</c_acctbal> <c_mktsegment>AUTOMOBILE</c_mktsegment> <c_comment>quickly unusual courts alongside of the requests</c_comment> </customer> <customer> <c_custkey>1806</c_custkey> <c_name>Customer#000001806</c_name> <c_address>BB6Vr7W rSIpWKp</c_address> <c_nationkey>9</c_nationkey> <c_phone>19-872-322-3433</c_phone> <c_acctbal>254.17</c_acctbal> <c_mktsegment>MACHINERY</c_mktsegment> <c_comment>ideas are blithely. ironic instructions wake quickly.</c_comment> </customer> </customers>'));
スタイルシート マッピングによってXSLT_SHRED_BATCHストアド プロシージャを呼び出し、ステージング入力テーブルに格納されるXMLデータをシュレッドします。次の引数を呼び出しに使用します。
- queryStringは、次のようになります: sel id, xmldoc from xsltuser.Input_Docs
- xsltMapping引数は、スタイルシートを入力とするCREATEXML関数を呼び出すことで指定します。このスタイルシートは、XML文書に適用されます。
- この例では、externalContextはNULLです。
- resultCodeは:res.で返されます。操作が成功すると0が返されます。
CALL TD_SYSXML.XSLT_SHRED_BATCH('SEL id, xmldoc FROM xsltuser.Input_Docs', CREATEXML('<?xml version="1.0" encoding="ISO-8859-1" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/customers"> <Transaction> <Insert> <Table> <xsltuser.customer> <xsl:for-each select="customer"> <Row> <c_custkey genexp="cast(? as integer)"> <xsl:value-of select="c_custkey"/> </c_custkey> <xsl:copy-of select="c_name"/> <xsl:copy-of select="c_address"/> <c_nationkey genexp="cast(? as integer)"> <xsl:value-of select="c_nationkey"/> </c_nationkey> <xsl:copy-of select="c_phone"/> <c_acctbal genexp="cast(? as numeric(15,2))"> <xsl:value-of select="c_acctbal"/> </c_acctbal> <xsl:copy-of select="c_mktsegment"/> <xsl:copy-of select="c_comment"/> </Row> </xsl:for-each> </xsltuser.customer> </Table> </Insert> </Transaction> </xsl:template> </xsl:stylesheet>'), NULL,:res);
結果: ターゲット テーブルで更新されたデータを表示するには次を実行します。SELECT * FROM customer;
c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment --------- ------------------- --------------- ----------- --------------- ------------ ------------ ---------------------- 1805 Customer#000001805 ZERs4Cu5lQTYD 9 19-679-706-1096 -274.75 AUTOMOBILE quickly unusual courts 1806 Customer#000001806 BB6Vr7W rSIpWKp 9 19-872-322-3433 254.17 MACHINERY ideas are blithely