• <legend id='T11gH'><style id='T11gH'><dir id='T11gH'><q id='T11gH'></q></dir></style></legend>

      • <bdo id='T11gH'></bdo><ul id='T11gH'></ul>
    1. <i id='T11gH'><tr id='T11gH'><dt id='T11gH'><q id='T11gH'><span id='T11gH'><b id='T11gH'><form id='T11gH'><ins id='T11gH'></ins><ul id='T11gH'></ul><sub id='T11gH'></sub></form><legend id='T11gH'></legend><bdo id='T11gH'><pre id='T11gH'><center id='T11gH'></center></pre></bdo></b><th id='T11gH'></th></span></q></dt></tr></i><div id='T11gH'><tfoot id='T11gH'></tfoot><dl id='T11gH'><fieldset id='T11gH'></fieldset></dl></div>

        <tfoot id='T11gH'></tfoot>

        <small id='T11gH'></small><noframes id='T11gH'>

        XML Oracle:多子节点提取

        XML Oracle : Multiple Child Node extract(XML Oracle:多子节点提取)
          <i id='RlGqb'><tr id='RlGqb'><dt id='RlGqb'><q id='RlGqb'><span id='RlGqb'><b id='RlGqb'><form id='RlGqb'><ins id='RlGqb'></ins><ul id='RlGqb'></ul><sub id='RlGqb'></sub></form><legend id='RlGqb'></legend><bdo id='RlGqb'><pre id='RlGqb'><center id='RlGqb'></center></pre></bdo></b><th id='RlGqb'></th></span></q></dt></tr></i><div id='RlGqb'><tfoot id='RlGqb'></tfoot><dl id='RlGqb'><fieldset id='RlGqb'></fieldset></dl></div>
          <tfoot id='RlGqb'></tfoot>
            <tbody id='RlGqb'></tbody>

              <legend id='RlGqb'><style id='RlGqb'><dir id='RlGqb'><q id='RlGqb'></q></dir></style></legend>
              • <bdo id='RlGqb'></bdo><ul id='RlGqb'></ul>
              • <small id='RlGqb'></small><noframes id='RlGqb'>

                  本文介绍了XML Oracle:多子节点提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 xml 代码:

                  I have an xml code :

                  <begin>
                      <entry>
                          <lastname>gordon</lastname>
                          <NumberList>
                              <number>100</number>
                              <codelist>
                                   <code>213</code>
                                   <code>214</code>
                              <codelist>
                              <login>
                                   <user>user1</user>
                                   <user>user2</user>
                              </login>
                          <NumberList>
                          <address>
                              <addresslist>Jl. jalan pelan-pelan ke Bekasi, Indonesia</addresslist>
                          </address>
                      </entry>
                      <entry>
                          <lastname>mark</lastname>
                          <address>
                              <addresslist>Jl. jalan cepet-cepet ke Jakarta, Indonesia</addresslist>
                          </address>
                      </entry>
                  </begin>
                  

                  我的代码:

                  FOR r IN (SELECT VALUE(p) col_val,
                                   EXTRACT(VALUE(P), '/entry/codelist') AS code,
                                   EXTRACT(VALUE(P), '/entry/login') AS login
                             FROM TABLE(XMLSequence(Extract(x,'/begin/entry'))) p)
                  LOOP
                     IF r.col_val.existsnode('/entry/lastname/text()') > 0 
                     THEN
                        vc_lastname := r.col_val.extract('/sdnEntry/lastname/text()').getstringval();
                     END IF;
                  
                     IF r.col_val.existsnode('/entry/address/addresslist/text()') > 0 
                     THEN
                      vc_address := r.col_val.extract('/sdnEntry/address/addresslist/text()').getstringval();
                     END IF;
                  
                     IF r.col_val.existsnode('/entry/codelist/id/code/text()') > 0 AND r.col_val.existsnode('/entry/login/user/text()') > 0 
                     THEN
                        FOR R1 IN (SELECT EXTRACTVALUE(VALUE(T1), '/codelist/code/text()') AS code
                                     FROM TABLE(XMLSEQUENCE(EXTRACT(R.code, '/codelist'))) T1)
                        LOOP
                           DBMS_OUTPUT.PUT_LINE(vc_uid||' - '||vc_firstName||' - '||R1.code||' - '||R2.address);
                        END LOOP;
                  
                        FOR R2 IN (SELECT
                                          EXTRACTVALUE(VALUE(T1), '/login/user/text()') AS user
                                     FROM TABLE(XMLSEQUENCE(EXTRACT(R.address, 'login/'))) T1)
                        LOOP
                           DBMS_OUTPUT.PUT_LINE(vc_uid||' - '||vc_firstName||' - '||R2.user||' - '||R2.address);
                        END LOOP;
                    ELSE
                          DBMS_OUTPUT.PUT_LINE(vc_uid||' - '||vc_firstName);
                    END IF;
                  

                  我的问题:如何循环子节点使数据变成这样:

                  My problem : How to loop child nodes so the data will become like this :

                  LastName | Number | code    | user  |   address
                  gordon   | 100    | 213     | user1 |Jl. jalan pelan-pelan ke Bekasi, Indonesia
                  gordon   | 100    | 213     | user2 |Jl. jalan pelan-pelan ke Bekasi, Indonesia
                  gordon   | 100    | 214     | user1 |Jl. jalan pelan-pelan ke Bekasi, Indonesia
                  gordon   | 100    | 214     | user2 |Jl. jalan pelan-pelan ke Bekasi, Indonesia
                  mark     | Null   | null    | null  |Jl. jalan cepet-cepet ke Jakarta, Indonesia
                  

                  任何帮助将不胜感激.

                  推荐答案

                  你可以使用 XMLTable() 函数来达到预期的效果:

                  You can achieve desired result by using XMLTable() function:

                  select q.Lastname
                       , q.Numberid
                       , s.codeid
                       , w.LoginId
                       , q.address
                    from t1 t
                    left join xmltable('/begin/entry'
                                        passing t.xml_col 
                                        columns LastName   varchar2(21)  path 'lastname',
                                                NumberId   number        path 'NumberList/number',
                                                Address    varchar2(201) path 'address/addresslist',
                                                CodeList   XmlType       Path 'NumberList/codelist/code',
                                                Logins     XmlType       Path 'NumberList/login/user'
                                        ) q
                      on (1=1) 
                    left join xmltable('/code'
                                        passing q.CodeList
                                        columns CodeId number path '.') s
                      on (1=1)
                    left join   xmltable('/user'
                                          passing q.Logins
                                          columns LoginId varchar2(11) path '.') w
                      on (1=1)
                  

                  结果:SQLFiddle 演示

                  Lastname Numberid Codeid Loginid Address 
                  ---------------------------------------------------------------------------
                  gordon   100      213    user1   Jl. jalan pelan-pelan ke Bekasi, Indonesia 
                  gordon   100      213    user2   Jl. jalan pelan-pelan ke Bekasi, Indonesia 
                  gordon   100      214    user1   Jl. jalan pelan-pelan ke Bekasi, Indonesia 
                  gordon   100      214    user2   Jl. jalan pelan-pelan ke Bekasi, Indonesia 
                  mark     null     null   null    Jl. jalan cepet-cepet ke Jakarta, Indonesia 
                  

                  了解更多关于XMLTable() 函数.

                  注意:使用 11.2.0.2 之前的 Oracle 版本,当 cursor_sharing 参数设置为 FORCESIMILAR(从 11.2 开始弃用).将cursor_sharing参数设置为EXACT(默认值),即可解决问题.

                  Note: Working with Oracle releases prior to 11.2.0.2, you can encounter ORA-1780 error(bug 8545377) on certain types of XML queries when cursor_sharing parameter is set to FORCE or SIMILAR(deprecated starting from 11.2). Setting cursor_sharing parameter to EXACT(default value), will solve the problem.

                  这篇关于XML Oracle:多子节点提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to redirect the output of DBMS_OUTPUT.PUT_LINE to a file?(如何将 DBMS_OUTPUT.PUT_LINE 的输出重定向到文件?)
                  How do I get column datatype in Oracle with PL-SQL with low privileges?(如何使用低权限的 PL-SQL 在 Oracle 中获取列数据类型?)
                  Get a list of all functions and procedures in an Oracle database(获取 Oracle 数据库中所有函数和过程的列表)
                  Why cannot I create triggers on objects owned by SYS?(为什么我不能在 SYS 拥有的对象上创建触发器?)
                  Returning result even for elements in IN list that don#39;t exist in table(即使对于表中不存在的 IN 列表中的元素也返回结果)
                  Reset Sequence in oracle 11g(oracle 11g 中的重置序列)

                    <tbody id='GSXrS'></tbody>
                1. <small id='GSXrS'></small><noframes id='GSXrS'>

                2. <tfoot id='GSXrS'></tfoot>
                  <legend id='GSXrS'><style id='GSXrS'><dir id='GSXrS'><q id='GSXrS'></q></dir></style></legend>
                    <i id='GSXrS'><tr id='GSXrS'><dt id='GSXrS'><q id='GSXrS'><span id='GSXrS'><b id='GSXrS'><form id='GSXrS'><ins id='GSXrS'></ins><ul id='GSXrS'></ul><sub id='GSXrS'></sub></form><legend id='GSXrS'></legend><bdo id='GSXrS'><pre id='GSXrS'><center id='GSXrS'></center></pre></bdo></b><th id='GSXrS'></th></span></q></dt></tr></i><div id='GSXrS'><tfoot id='GSXrS'></tfoot><dl id='GSXrS'><fieldset id='GSXrS'></fieldset></dl></div>
                      • <bdo id='GSXrS'></bdo><ul id='GSXrS'></ul>