Extract a specific node of XMLTYPE value

I have a piece of code that puts an answer Google geocoding in an XMLTYPe variable.  I then use lines similar to the following to retrieve values such as address and location:

px_xml.EXTRACT('/GeocodeResponse[1]/result['||pn_result_number||']/formatted_address[1]/text()').getstringval();

It's a pretty lazy way of just looping through my results and picking a specific value.

Now, I need to extract just the addresses zip_code of XML component and can't do in the same way.  Someone at - it ideas?

A call to the example is:

https://maps.googleapis.com/maps/API/geocode/XML?address=London+Eye & Bounds = 49.90878, - 7.69042. 60.88770,-0.83496 & key =

but you need to add your own key to operate.  There are several components of the address and I just want to identify who has the type "zip_code".

Thank you!

It's a pretty lazy way of just looping through my results and picking a specific value.

And what about using a more friendly approach, XMLTABLE namely:

Extract data from complex XML of XMLType with nodes parents containing several internal nodes

Use an XPath predicate to target only the required component, for example:

select x.long_name
from xmltable('/GeocodeResponse/result'
       passing px_xml
       columns
         long_name   varchar2(200) path 'address_component[type="postal_code"]/long_name'
     ) x
;

Tags: Database

Similar Questions

  • Extraction of a node in an XMLtype table - selection of the previous query

    Hey all,.

    I work with a server Oracle 11 g r2 and basically need to be able to analyse and select nodes from it. I spent hours scouring the net and reading the manual oracle xml db trying to find an appropriate solution to my problem, but I can't seem to identify the correct way to do it. I have some experience in programming, but none with databases oracle, sql or xml in general so forgive me if this is a trivial question.

    OK, so the question:

    I have a very simple XML file saved under catalog.xml and it is as follows:

    <>Catalog
    < cd >
    < title > hide your heart < /title >
    < artist > Bonnie Tyler < / artist >
    < Country > UK < / country >
    < company > CBS Records < / company >
    < price > 9.90 < / price >
    < year > 1988 < / year >
    < CD >
    < cd >
    Empire Burlesque < title > < /title >
    < artist > Bob Dylan < / artist >
    < country > USA < / country >
    < company > Columbia < / company >
    < price > 10.90 < / price >
    < year > 1985 < / year >
    < CD >
    < / catalogue >

    Now, I want to be able to extract the title of the given cd a certain artist. So, for example, if the artist is "bob dylan", the title should be "empire burlesque".

    Now I created an XMLType table in Oracle as follows:

    CREATE BINARY XMLTYPE STORE AS XML BINARY XMLType TABLE.

    I then load my xml file into oracle by:

    Insert the BINARY values (XMLTYPE (BFILENAME ('XML_DIR', 'catalog.xml'), nls_charset_id ('AL32UTF8')));

    So far so good.

    Now for the part of the excerpt:

    First of all I've tried:

    SELECT extract (b.object_value, ' / catalogue/cd/title ')
    Binary b
    WHERE existsNode (b.object_value,'/catalog/cd [artist = "Bob Dylan"]') = 1;

    EXTRACT(B.OBJECT_VALUE,'/CATALOG/CD/TITLE')
    --------------------------------------------------------------------------------

    < title > hide your heart < /title >
    Burlesque Empire < title > < /title >

    1 selected line.



    It did not work because the xml file was all in 1 row then I realized that I had to split my xml in separate rows. Doing that, I had to convert the nodes < title > a virtual table using the functions XMLSequence() and table(). These functions convert nodes two title returned by the extract() function in a virtual table composed of two XMLType objects, each of which contains a single title element.

    Second test:

    SELECT value (d)
    Binary B,
    Table (xmlsequence(extract(b.object_value,'/catalog/cd'))) d
    WHERE existsNode (b.object_value,'/catalog/cd [artist = "Bob Dylan"]') = 1;

    VALUE (D)
    --------------------------------------------------------------------------------

    < cd >
    < title > hide your heart < /title >
    < artist > Bonnie Tyler < / artist >
    < Country > UK < / country >
    < company > CBS Records < / company >
    < price > 9.90 < / price >
    < year > 1988 < / year >
    < CD >

    < cd >
    Empire Burlesque < title > < /title >
    < artist > Bob Dylan < / artist >
    < country > USA < / country >
    < company > Columbia < / company >
    < price > 10.90 < / price >
    < year > 1985 < / year >
    < CD >

    2 selected lines.


    It's better because it is now divided into 2 different lines so I should be able to make a selection - where, and then select the title from the artist.

    However, this is where I have questions, I tried to literally hours but I can't understand how to use the results of the query above in my next. So I tried to use a suquery in this way:

    Select extract (sub1, ' cd/title')
    Of
    (
    SELECT value (d)
    Binary B,
    Table (xmlsequence(extract(b.object_value,'/catalog/cd'))) d
    ) sub1
    WHERE existsNode (sub1,'/ cd [artist = "Bob Dylan"]') = 1;

    However, sql * plus displays an error:

    ORA-00904: "SUB1": invalid identifier.

    I've tried dozens of variations to try to use subqueries but I simly can't do things.

    I heard you can do also do this using variables or pl/sql, but I don't know where to start.

    Any help would be greatly appreciated I tried everything at my disposal.

    This should help you get started!

    select banner as "Oracle version" from v$version where banner like 'Oracle%';
    
    create table otn5test(
      id number,
      data xmltype
    );
    
    insert into otn5test values (1, xmltype('
    
    Hide your heart
    Bonnie Tyler
    UK
    CBS Records
    9.90
    1988
    
    
    Empire Burlesque
    Bob Dylan
    USA
    Columbia
    10.90
    1985
    
    
    '));
    
    select otn5test.id, x.*
    from otn5test,
         xmltable('/catalog/cd[artist/text()="Bob Dylan"]' passing otn5test.data
         columns title varchar2(20) path 'title') x;
    
    select otn5test.id,
           xmlcast(xmlquery('/catalog/cd[artist/text()="Bob Dylan"]/title'
                   passing otn5test.data returning content)
           as varchar2(20)) from otn5test;
    
    drop table otn5test;
    
    sqlplus> @otn-5.sql
    
    Oracle version
    ------------------------------------------------------------------------------
    Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
    
    Table created.
    
    1 row created.
    
         ID TITLE
    ---------- --------------------
          1 Empire Burlesque
    
         ID XMLCAST(XMLQUERY('/C
    ---------- --------------------
          1 Empire Burlesque
    
    Table dropped.
    
  • Questions about the management of specific nodes in different hierarchies

    Hi all

    I have a question about the specific management of some particular set nodes, which are located in different hierarchies within a same version.

    I want to know if there is any editing made to certain properties of these specific nodes or if the nodes are deleted/moved/edited approval to be triggered for the data manager.

    or should not allow users to edit (adding/moving/deleting/changing property values) or those specific members.


    According to my understanding of the nodes of domain prevents the removal of nodes, but I don't want my Member prefix/suffix, domain is the only way to prevent the change.




    Thanks and greetings

    Madhu

    We have an obligation to not allow a node to remove or deleted without the approval of the admin, so I created a Boolean property AllowDelete is false, which is substitutable, default and is available only in a category of property Admin, for which most of the users do not have access.  Then, I created a validation of PropRemove with an error message that tells the user to contact a user admin to remove or delete the node.  The admin can change the AllowDelete to true, then can either remove himself or to allow the user to do.

  • WORK on a specific node

    Is it possible to run a scheduled task to run on a specific node.
    BEGIN
      SYS.DBMS_SCHEDULER.CREATE_JOB_CLASS
        (
          job_class_name          => 'TEST'
         ,resource_consumer_group => 'DEFAULT_CONSUMER_GROUP'
         ,service                 => 'ORCL'
         ,log_history             => 30
         ,comments                => NULL
        );
    END;
    / 
    

    ORCL must exist:

    SELECT NAME FROM DBA_SERVICES:
    NAME
    ----------------
    SYS$BACKGROUND
    SYS$USERS
    ORCLXDB
    ORCL                                                            
    
    BEGIN
      SYS.DBMS_SCHEDULER.CREATE_JOB
        (
           job_name        => 'SYS.TEST_JOB'
          ,start_date      => TO_TIMESTAMP_TZ('sysdate','yyyy/mm/dd hh24:mi:ss.ff tzr')
          ,repeat_interval => NULL
          ,end_date        => NULL
          ,job_class       => 'TEST'
          ,job_type        => 'PLSQL_BLOCK'
          ,job_action      => 'begin null; end;'
          ,comments        => NULL
        );
    /
    
  • How to call the specific node of the navigation model?

    Hello

    I have a portal application webcenter containing a custom navigation template. HIES model is used by the menu tree and bread crumbs.
    Users request a link in the template to navigate to the home page. I could make a case of navigation in my ADFC-config file to navigate to the home page, but I would rather use the navigation model. Is there a way to select a specific node in the navigation model and navigate using a button or a link?
    I've been looking for this much time, but could not find an example. It's has enough of the menu etc, but not cela.
    Thank you...

    You can use the same navigation model just like using the template of menu xml
    http://www.orastudy.com/oradoc/selfstu/Fusion/Web.1111/b31973/af_navigate.htm#CACDBFEI
    For more information on the el here chk
    http://docs.Oracle.com/CD/E21764_01/WebCenter.1111/e10148/jpsdg_app_els.htm#CHDCBJGJ

  • PIN dbms_cube.build jobs parallel to a specific node on the CARS

    Is it possible to Pin dbms_cube.build jobs parallel to a specific node on CARS. Currently, work with say parallelism of 10 bays on all nodes of the RAC.

    Is it possible to control for the jobs of the child works on the subset of nodes. Unable to see how we can link to categories of jobs and services with dbms_cube.build.

    Any suggestions will be much appreciated.

    JOB_CLASS was added in 11.2.0.2 precisely for this purpose. It is undocumented, because he missed the 11.2.0.1. Deadline for documentation, but it has exactly the same meaning as the job_class parameter in DBMS_SCHEDULER. CREATE_JOB.

  • Check the value of the attribute of a child node to xmltype data type.

    Hello

    I have a xml stored in the column with the data type as "XMLTYPE.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <Settings>
      <Setting Name="A1" Value="N"/>
      <Setting Name="A2" Value="N"/>
      <Setting Name="A3" Value="SOMEVALUE"/>
      <Setting Name="A4" Value="N"/>
      <Setting Name="A5" Value="Y"/>
      <Setting Name="A6" Value="N"/>
    </Settings>
    I don't want to loop in each child node. But want to know if the value of the A5 parameter is Y or N? Is there a way I can find it without making the child node extract "Setting" and then a loop of each node to find the value?

    Kind regards

    You specify your Oracle version then here are two options. If 10.2 or higher, use XMLTable, otherwise use the option of ExtractValue.

    -- The WITH simply simulates your existing table that I do not have.
    WITH fake_tab AS
    (SELECT XMLTYPE('
    
      
      
      
      
      
      
    
    ') tab_col
      FROM dual)
    -- For 10.2 and higher use this SELECT
    SELECT a5
      FROM fake_tab,
           XMLTABLE('/Settings'
                    PASSING fake_tab.tab_col
                    COLUMNS
                    a5   VARCHAR2(10)  PATH 'Setting[@Name="A5"]/@Value');
    
    -- For 10.1 and before
    SELECT ExtractValue(tab_col, '/Settings/Setting[@Name="A5"]/@Value')
      FROM fake_tab;
    
  • How to extract the node where the value of the node is the max in all of the XML document?

    Hello

    I have a transaction that refers to an xmltype in iRecruitment, containing multiple versions of the same node as follows:

    (only for the example data)



    {noformat} & lt; Transaction & gt;


    & lt; data & gt;


    & lt; ObjectVersionNumber & gt; 1 & lt; / object_version_number & gt;


    & lt; EO & gt;


    & lt; Attribute1 & gt; A & lt; / Attribute1 & gt;


    & lt; Attribut2 & gt; B & lt; / attribut2 & gt;


    & lt; /EO & gt;


    & lt; / data & gt;


    & lt; data & gt;


    & lt; ObjectVersionNumber & gt; 2 & lt; / object_version_number & gt;


    & lt; EO & gt;


    & lt; Attribute1 & gt; A & lt; / Attribute1 & gt;


    & lt; Attribut2 & gt; C & lt; / attribut2 & gt;


    & lt; /EO & gt;


    & lt; / data & gt;


    & lt; data & gt;


    & lt; ObjectVersionNumber & gt; X & lt; / object_version_number & gt;


    & lt; EO & gt;


    & lt; Attribute1 & gt;? & lt; / Attribute1 & gt;


    & lt; Attribut2 & gt;? & lt; / attribut2 & gt;


    & lt; /EO & gt;


    & lt; / data & gt;


    & lt; / Transaction & gt; {noformat}

    I can extract a value for FULL-TIME 1 or 2, is not a problem.
    However, how can I go on the selection of a value of an attribute below FULL-TIME X, where X is the maximum value of FULL-TIME in any node in the XML document?

    I tried to the last node corresponding to my way, but it is not always the case that the FULL-TIME max will correspond to this scenario.

    Any help would be greatly appreciated!

    Thank you very much, Pete

    Published by: Pete Mahon on February 24, 2009 12:11

    Here's a way

    SQL> set long 100000
    SQL> with XML as (
      2  select XMLTYPE(
      3  '
      4  
      5     
      6             1
      7             
      8                     A
      9                     B
     10             
     11     
     12     
     13             2
     14             
     15                     A
     16                     C
     17             
     18     
     19     
     20             3
     21             
     22                     ?
     23                     ?
     24             
     25     
     26  ') OBJECT_VALUE
     27    from dual
     28  )
     29  select DATA, OVN
     30    from XML,
     31         XMLTable
     32         (
     33           '/Transaction/data'
     34           passing OBJECT_VALUE
     35           columns
     36           DATA XMLType path '.',
     37           OVN  number  path 'ObjectVersionNumber'
     38         )
     39   where OVN = ( select MAX(OVN)
     40                   from XML,
     41                        XMLTable
     42                        (
     43                          '/Transaction/data'
     44                          passing OBJECT_VALUE
     45                          columns
     46                          OVN  number  path 'ObjectVersionNumber'
     47                        )
     48               )
     49
    SQL> /
    
    DATA
    --------------------------------------------------------------------------------
           OVN
    ----------
    3?
    ?
             3
    
    SQL>
    
  • Remove the specific node of an XML stored as XMLType

    Hello

    I have a XML stored as XMLType,

    < ocaStatus xmlns = "http://xmlbeans.apache.org/ocastatus" >
    < status >
    < > 700 statusCode < / statusCode >
    < statusDate > 2010 - 03 - 31 12:39:41.580 GMT + 05:30 < / statusDate >
    < username > 1234 < / userId >
    < comment > Document is deleted from the OCA. < / comment >
    < / status >
    < status >
    < > 934 statusCode < / statusCode >
    < statusDate > 2010 - 03 - 31 12:39:41.580 GMT + 05:30 < / statusDate >
    < username > 1234 < / userId >
    < comment > Document is deleted from the OCA. < / comment >
    < / status >
    < status >
    < > 934 statusCode < / statusCode >
    < statusDate > 2010 - 03 - 31 12:39:41.580 GMT + 05:30 < / statusDate >
    < username > 1234 < / userId >
    < comment > Document is deleted from the OCA. < / comment >
    < / status >
    < / ocaStatus >

    I have a requirement where the first occurrence of statusCode 934 should be removed from the XML.
    I can do through a java program. But that is costly.
    Is there a way that this can be done by a SQL XMLQuery/XPath statement?

    Help, please.
    Thanks in advance.

    You can use DELETEXML:

    SQL> select xml from myxml;
    
    XML
    --------------------------------------------------------------------------------
    
    
    700
    2010-03-31 12:39:41.580 GMT+05:30
    1234
    Document is deleted from OCA.
    
    
    934
    2010-03-31 12:39:41.580 GMT+05:30
    1234
    Document is deleted from OCA.
    
    
    934
    2010-03-31 12:39:41.580 GMT+05:30
    1234
    Document is deleted from OCA.
    
    
    
    SQL> update myxml
      2  set xml = deletexml(xml,'//status[statusCode="934"][1]',
      3                          'xmlns="http://xmlbeans.apache.org/ocastatus"');
    
    1 row updated.
    
    SQL> select xml from myxml;
    
    XML
    --------------------------------------------------------------------------------
    
    
    700
    2010-03-31 12:39:41.580 GMT+05:30
    1234
    Document is deleted from OCA.
    
    
    934
    2010-03-31 12:39:41.580 GMT+05:30
    1234
    Document is deleted from OCA.
    
    
    

    Max
    http://oracleitalia.WordPress.com

  • Retrieve / search a specific node of the XML file

    Hello

    I have a question about reading the XML (search) in PL SQL file:

    There is an XML file with the following structure:
    <root>
      <Hnode1 attr1="value1" />
      <Hnode2 attr1="value1" /> 
         <node1_of_Hnode2 id="10" personname="Steven"/>
         <node2_of_Hnode2 id="20" personname="Christian"/>
         <node3_of_Hnode2 id="30" personname="Arnold"/>
         .
         .
      <Hnode2/>
    <root/>
    How it is possible to filter a node by one of its attribute value. For example:
    The id of a person - I guess that id = 20. In this case I would like to get the whole node (in this case node2_of_Hnode2) to get the personname = > 'Christian '.
    Just like a SELECT statement (WHERE ID = 20)

    Is it possible to get it in a single order or should it be buckled on all the lines in the Document. Can you please provide an example for me.

    Thank you for advice!

    The basic version is 10.

    Sorry, this is not a version.
    For example:

    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    PL/SQL Release 10.2.0.5.0 - Production
    CORE     10.2.0.5.0     Production
    TNS for 64-bit Windows: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
     
    

    The use of the extraction of the values?
    1. better in a Select statement. assignment directli in a variable, or by using the xmlquery function?

    PL/SQL or SQL calls to the XMLType methods such as getStringVal() or extract() function should be equivalent (save the change of context).
    However, none of them are the right way to retrieve a scalar value of a given node.
    You must use the rather extractValue() function (SQL only) for immediate release< 11.2="" and="" xmlcast/xmlquery="" starting="" with="">

    Another Question:

    I've seen a lot of options for dealing with XML files.

    In my case only query data in XML files is relevant.

    I've seen to many API called XMLDOM, DMBS_XMLDOM, XMLTYPE...

    When to use these APIs. Can you give me feedback on this please?

    It is a broad topic.
    An appropriate response will depend on your condition.

    -You have to deal with large files and if so what size?
    -Performance/memory management is a concern for you?
    -You want to extract unique values or process the XML content in the form of relational data?

    If you have any specific test cases to show us, please post in the {forum: id = 34} forum and make sure to include all the necessary details (see the FAQ).

    Published by: odie_63 on 23 Feb. 2012 11:35

  • XMLTABLE - necessary help extract a single node

    (Oracle 10.2.0.4)

    Hello

    Due to front questionable stuff, my database ends by past xml which is more or less the following format:
    CREATE TABLE xml_test
    (id integer,NOTEBOOK XMLTYPE);
     
    insert into xml_test values (1, '<?xml version="1.0" encoding="UTF-8"?>
    <Product Type=''Laptop''>
    <Notebook Brand="HP" Model="Pavilion dv6-3132TX Notebook">
    <Harddisk>640 GB</Harddisk>
    <Processor>Intel Core i7</Processor>
    <RAM>4 GB</RAM>
    <Example>
      <Example_sub>a</Example_sub>
      <Example_sub>b</Example_sub>
      <Example_sub>c</Example_sub>
      <Example_sub>d</Example_sub>
    </Example>
    </Notebook>
    <Notebook Brand="HP" Model="HP Pavilion dv6-3032TX Notebook">
    <Harddisk>640 GB</Harddisk>
    <Processor>Intel Core i7</Processor>
    <RAM>6 GB</RAM>
    <Example>
      <Example_sub>a</Example_sub>
      <Example_sub>b</Example_sub>
      <Example_sub>c</Example_sub>
      <Example_sub>d</Example_sub>
    </Example>
    </Notebook>
    <Notebook Brand="Toshiba" Model="Satellite A660/07R 3D Notebook">
    <Harddisk>640 GB</Harddisk>
    <Processor>Intel Core i7</Processor>
    <RAM>4 GB</RAM>
    <Example>
      <Example_sub>a</Example_sub>
      <Example_sub>b</Example_sub>
      <Example_sub>c</Example_sub>
      <Example_sub>d</Example_sub>
    </Example>
    </Notebook>
    <Notebook Brand="Toshiba" Model="Satellite A660/15J Notebook">
    <Harddisk>640 GB</Harddisk>
    <Processor>Intel Core i5</Processor>
    <RAM>6 GB</RAM>
    <Example>
      <Example_sub>a</Example_sub>
      <Example_sub>b</Example_sub>
      <Example_sub>c</Example_sub>
      <Example_sub>d</Example_sub>
    </Example>
    </Notebook>
    </Product>');
     
    insert into xml_test values (2, '<?xml version="1.0" encoding="UTF-8"?>
    <Product Type=''Laptop''>
    <Notebook Brand="HP" Model="Pavilion dv6-3132TX Notebook">
    <Harddisk>640 GB</Harddisk>
    <Processor>Intel Core i7</Processor>
    <RAM>4 GB</RAM>
    <Example>
      <Example_sub>a</Example_sub>
      <Example_sub>b</Example_sub>
      <Example_sub>c</Example_sub>
      <Example_sub>d</Example_sub>
    </Example>
    </Notebook>
    <Notebook Brand="HP" Model="HP Pavilion dv6-3032TX Notebook">
    <Harddisk>640 GB</Harddisk>
    <Processor>Intel Core i7</Processor>
    <RAM>6 GB</RAM>
    <Example>
      <Example_sub>b</Example_sub>
    </Example>
    </Notebook>
    <Notebook Brand="Toshiba" Model="Satellite A660/07R 3D Notebook">
    <Harddisk>640 GB</Harddisk>
    <Processor>Intel Core i7</Processor>
    <RAM>4 GB</RAM>
    <Example>
      <Example_sub>c</Example_sub>
    </Example>
    </Notebook>
    <Notebook Brand="Toshiba" Model="Satellite A660/15J Notebook">
    <Harddisk>640 GB</Harddisk>
    <Processor>Intel Core i5</Processor>
    <RAM>6 GB</RAM>
    <Example>
      <Example_sub>c</Example_sub>
      <Example_sub>d</Example_sub>
    </Example>
    </Notebook>
    </Product>');
    
    insert into xml_test values (3, '<?xml version="1.0" encoding="UTF-8"?>
    <Product Type=''Laptop''>
    <Notebook Brand="HP" Model="Pavilion dv6-3132TX Notebook">
    <Harddisk>640 GB</Harddisk>
    <Processor>Intel Core i7</Processor>
    <RAM>4 GB</RAM>
    <Example>
      <Example_sub>a</Example_sub>
    </Example>
    </Notebook>
    <Notebook Brand="HP" Model="HP Pavilion dv6-3032TX Notebook">
    <Harddisk>640 GB</Harddisk>
    <Processor>Intel Core i7</Processor>
    <RAM>6 GB</RAM>
    <Example>
      <Example_sub>b</Example_sub>
    </Example>
    </Notebook>
    <Notebook Brand="Toshiba" Model="Satellite A660/07R 3D Notebook">
    <Harddisk>640 GB</Harddisk>
    <Processor>Intel Core i7</Processor>
    <RAM>4 GB</RAM>
    <Example>
      <Example_sub>c</Example_sub>
    </Example>
    </Notebook>
    <Notebook Brand="Toshiba" Model="Satellite A660/15J Notebook">
    <Harddisk>640 GB</Harddisk>
    <Processor>Intel Core i5</Processor>
    <RAM>6 GB</RAM>
    <Example>
      <Example_sub>d</Example_sub>
    </Example>
    </Notebook>
    </Product>');
    
    commit;
    
    SELECT NOTEBOOKS2.*
      FROM xml_test PO,
           XMLTable('//Notebook' PASSING PO.NOTEBOOK
           COLUMNS  row_num for ordinality,
                    "BrandType"    CHAR(10) PATH '@Brand',
                    "ProductModel" CHAR(50) PATH '@Model',
                    "Harddisk" CHAR(10) PATH 'Harddisk',
                    "Processor" CHAR(20) PATH 'Processor',
                    "RAM" CHAR(10) PATH 'RAM') AS NOTEBOOKS2;
    
            ID    ROW_NUM BrandType  ProductModel                                       Harddisk   Processor            RAM       
    ---------- ---------- ---------- -------------------------------------------------- ---------- -------------------- ----------
             1          1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB      
             1          2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB      
             1          3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB      
             1          4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB      
             2          1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB      
             2          2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB      
             2          3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB      
             2          4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB      
             3          1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB      
             3          2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB      
             3          3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB      
             3          4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB      
    However, I need to extract the values of Example_sub - but only when there is a single Example_sub node in each / / Notebook/example, otherwise I should return null - for example:
            ID    ROW_NUM BrandType  ProductModel                                       Harddisk   Processor            RAM        Example
    ---------- ---------- ---------- -------------------------------------------------- ---------- -------------------- ---------- --------
             1          1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB       
             1          2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB       
             1          3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB       
             1          4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB       
             2          1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB       
             2          2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB       b
             2          3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB       c
             2          4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB       
             3          1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB       a
             3          2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB       b
             3          3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB       c
             3          4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB       d
    I tried the following:
    SELECT NOTEBOOKS2.*
      FROM xml_test PO,
           XMLTable('//Notebook' PASSING PO.NOTEBOOK
           COLUMNS  row_num for ordinality,
                    "BrandType"    CHAR(10) PATH '@Brand',
                    "ProductModel" CHAR(50) PATH '@Model',
                    "Harddisk" CHAR(10) PATH 'Harddisk',
                    "Processor" CHAR(20) PATH 'Processor',
                    "RAM" CHAR(10) PATH 'RAM',
                    "Example" VARCHAR2(3) PATH 'Example/Example_sub') AS NOTEBOOKS2;
    but that just ends up with the following error (of course): ORA-19279: dynamic XQuery type mismatch: expected - singleton sequence got several sequence element

    Any ideas on how I can do to get this snippet? I would like to make in a single call XMLTABLE if I can, but it is probably not possible - otherwise, I'm happy to go with another call to XMLTABLE if necessary.

    Thank you.

    PS. I'm on Oracle 10.2.0.4

    Published by: Boneist on March 12, 2012 18:34

    Published as the modified requirements.

    Hello

    I don' t have your trial version but this one should work:

    SQL> SELECT t.id, x.*
      2  FROM xml_test t
      3     , XMLTable(
      4         '/Product/Notebook'
      5         PASSING t.NOTEBOOK
      6         COLUMNS row_num for ordinality
      7               , "BrandType"    VARCHAR2(10) PATH '@Brand'
      8               , "ProductModel" VARCHAR2(50) PATH '@Model'
      9               , "Harddisk"     VARCHAR2(10) PATH 'Harddisk'
     10               , "Processor"    VARCHAR2(20) PATH 'Processor'
     11               , "RAM"          VARCHAR2(10) PATH 'RAM'
     12               , "Example"      VARCHAR2(3)  PATH 'Example[count(Example_sub)=1]/Example_sub'
     13       ) x
     14  ;
    
           ID    ROW_NUM BrandType  ProductModel                                       Harddisk   Processor            RAM        Example
    --------- ---------- ---------- -------------------------------------------------- ---------- -------------------- ---------- -------
            1          1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB
            1          2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB
            1          3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB
            1          4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB
            2          1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB
            2          2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB       b
            2          3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB       c
            2          4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB
            3          1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB       a
            3          2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB       b
            3          3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB       c
            3          4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB       d
    
    12 rows selected
     
    

    If this is not the case, try this solution:

    SELECT t.id, x.*
    FROM xml_test t
       , XMLTable(
           'for $i in /Product/Notebook
            return element p {
              $i/@Brand
            , $i/@Model
            , $i/Harddisk
            , $i/Processor
            , $i/RAM
            , $i/Example[count(Example_sub)=1]/Example_sub
            }'
           PASSING t.NOTEBOOK
           COLUMNS row_num for ordinality
                 , "BrandType"    VARCHAR2(10) PATH '@Brand'
                 , "ProductModel" VARCHAR2(50) PATH '@Model'
                 , "Harddisk"     VARCHAR2(10) PATH 'Harddisk'
                 , "Processor"    VARCHAR2(20) PATH 'Processor'
                 , "RAM"          VARCHAR2(10) PATH 'RAM'
                 , "Example"      VARCHAR2(3)  PATH 'Example_sub'
         ) x
    ;
    

    Published by: odie_63 on March 12, 2012 20:38 - added alternative

  • Extraction of data to xml by value

    How can I retrieve from an xml value by value?

    In this example, I need to extract one by a pair of LABEL / VALUE:
    pLABEL = pVALUE 101 = A
    pLABEL = 102 pVALUE = B
    pLABEL = 102 pVALUE = C
    pLABEL = 102 pVALUE = D

    If I run the query in this example, I get all the data at once:

    ABCD
    101102103104

    PL/SQL procedure successfully completed

    The labels are not always the same.



    DECLARE
    t varchar2 (1000): =' < tip t = "1" > '
    ||     ' < info > < label > 101 < / label > < value > < / value > < / info > '
    ||     ' < info > < label > 102 < / label > < value > B < / value > < / info > '
    ||     ' < info > < label > 103 < / label > C < value > < / value > < / info > '
    ||     ' < info > < label > 104 < / label > D < value > < / value > < / info > '
    ||     "< / Tip >."
    v_xml XMLType: = XMLType (t);
    r varchar2 (1000);
    pLABEL number (10);
    VARCHAR2 (10) pVALUE;

    BEGIN

    Select extract(v_xml,'//tip/info/value/text()').getStringVal () in double r
    where existsNode (v_xml, '//tip/info [label = "101"]') = 1;
    dbms_output.put_line (substr (r, 1, 255));

    Select extract(v_xml,'//tip/info/label/text()').getStringVal () in double r
    where existsNode (v_xml, '//tip/info [label = "101"]') = 1;
    dbms_output.put_line (substr (r, 1, 255));

    END;
    /

    You will need to use a function to return the nodes of a collection as a set of lines. In 10g, it is table (xmlsequence ()). 11 g, you can use XMLTABLE().

    Here is a sample of 10g:

    Select
    ExtractValue (value (p), "/ info/label") label.
    ExtractValue (value (p), "/ info / value ') value
    Of
    table)
    xmlsequence)
    extract)
    XmlType)
    ' < Tip t = "1" >
    < info > < label > 101 < / label > < value > < / value > < / info >
    < info > < label > 102 < / label > < value > B < / value > < / info >
    < info > < label > 103 < / label > C < value > < / value > < / info >
    < info > < label > 104 < / label > D < value > < / value > < / info >
    < / tip > '
    )
    ,'/ / info'
    )
    )
    ) p ;

    HTH,
    Keith

  • Prevent the change of name of specific nodes

    Hi all

    DRM can we prevent the renaming of the names of nodes for certain specific levels in the hierarchy and not the whole hierarchy.

    Preference of the system RenameLimb/Renameleaf can be prevented, but it is a property of the system and changing this property applies to any application and all versions.

    I want my restriction to only specific hierarchy and levels.

    Can any validations or it's training of security privileges will in this scenario.

    Thank you

    Madhu

    Hi Madhu,

    Have you tried to use access to the node groups and granted read only access to the relevant level?

    https://docs.Oracle.com/cloud/latest/financialscs_gs/FADRA/CH03.html

    Concerning

    Craig

  • Transfer values of ROWTYPE in ROWTYPE with different COLUMN specifications. keeping the Default_Data values

    Hello

    I have a problem on dynamically the transfer values of different columns in two variables given rowtype type.

    My intention is to transfer values from table1 into table2.

    Basically, I stated to vars of v_table1 and v_table2% rowtype, each of them contains columns with the same, and also the individual column names.

    v_table2% rowtype must be initialized with default values.

    I would like to insert v_table2 values in table2 later by practice 'INSERT INTO TABLE2 VALUES v_table2'.

    Before inserting, I need to change several values of column by different rules, but these rules are not relevant for my actual demand.

    The point is, how can I transfer the values of v_table1 in v_table2 for the hanving of columns with the same column name, without hard-coding the names of columns, because these two tables contain many columns.

    In addition values initialized with v_table2 default_data values should not be overwritten by data does not exist in the same named column of v_table1.

    Example: If v_table1. D is NULL, it should not replace the default value initialized former "Monday".

    Conditions:

    Table 1 contains the following values:

    Column name Value
    A'1'
    B'2'
    CNULL VALUE
    D'somedata '.
    ENULL VALUE
    F« 3 »

    After the transfer of the values of v_table1 in v_table2, I guess that the following data:

    Column name Value Source
    CNULL VALUETable1.C
    D'somedata '.Table1.D
    E"Tuesday".DATA_DEFAULT from Table2
    F« 3 »Table1.F
    GNULL VALUE
    HNULL VALUE

    Right now I am already able to fill the v_table2 with the default values:

    declare
      lv_query varchar2(1000);
      
      type cur_typ is ref cursor;
      rcur_typ cur_typ;
      
      v_table2 table2%rowtype;
    
    begin
        for rec in (select *
                    from user_tab_columns
                    where table_name = 'TABLE2'
                    order by column_id
                    )
        loop
          if rec.data_default is null then
              lv_query := lv_query||', null';
            elsif rec.data_type = 'NUMBER' then
              lv_query := lv_query||', '||rec.data_default;
            elsif rec.data_type = 'DATE' then
              lv_query := lv_query||', '||rec.data_default;
            else
              lv_query := lv_query||', '||rec.data_default||'';
          end if;
        end loop;
        
        lv_query := 'SELECT'||substr(lv_query, 2)||' FROM DUAL';
        dbms_output.put_line(lv_query);
        
        open rcur_typ for lv_query;
        fetch rcur_typ into v_table2;
        close rcur_typ;
    end;
    

    I have no idea how to achieve the transfer of v_table1 to v_table2 without substitute default values of table2.


    As far as I know I can find these columns with column names by querying:

    select column_name from user_tab_cols where table_name='TABLE1' intersect select column_name from user_tab_cols where table_name='TABLE2'
    

    Maybe you can give me some advice.

    Thank you very much.

    Sample data:

    CREATE TABLE "TABLE1" 
       (    "A" VARCHAR2(20 BYTE), 
        "B" VARCHAR2(20 BYTE), 
        "C" VARCHAR2(20 BYTE), 
        "D" VARCHAR2(20 BYTE), 
        "E" VARCHAR2(20 BYTE), 
        "F" VARCHAR2(20 BYTE)
       );
    
      CREATE TABLE "TABLE2" 
       (    "C" VARCHAR2(20 BYTE), 
        "D" VARCHAR2(20 BYTE) DEFAULT 'Monday', 
        "E" VARCHAR2(20 BYTE) DEFAULT 'Tuesday', 
        "F" VARCHAR2(20 BYTE) DEFAULT 'Wednesday', 
        "G" VARCHAR2(20 BYTE) DEFAULT 'Thursday', 
        "H" VARCHAR2(20 BYTE)
       );
    
    INSERT INTO "TABLE1" (A, B, D, F) VALUES ('1', '2', 'somedata', '3');
    
    INSERT INTO "TABLE1" (A, B, D, F) VALUES ('1', '2', 'somedata', '3');
    

    Banner:

    Oracle Database 11 g Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    CORE Production 11.2.0.3.0

    AMT for Linux: Version 11.2.0.3.0 - Production

    NLSRTL Version 11.2.0.3.0 - Production

    You can build a dynamic query that checks the values of all columns in the table 1,

    and if a column contains null, then retrieves the default value of the column in table2,

    or null if this column doesn't have a default vallue.

    Something like this pseudocode

    SELECT
       if column A is not null then take A from table1, else take default for column A from table2
       .....
       if column X is not null then take A from table1, else take default for column X from table2
    FROM table1
    

    The default budget can be extracted from USER_TAB_COLUMNS

    select column_name, data_default from user_tab_columns
    where table_name = 'TABLE2'
    order by column_id
    ;
    
  • Hierarchy of the building under a specific node in the outline

    Hello

    We have an obligation to create a hierarchy under a specific dimension member in the sketch. We have the dimension of time in which there are two nodes 'Time_Hierarchy379' and 'Time_Hierarchy383', now we need generate a rule file that generates a hierarchy, 4 levels deep, under the node 'Time_Hierarchy379 '. The construction of a hierarchy, to use the reference level or generation method, but how do you ensure that the hierarchy is built under the node "Time_Hierarchy379" specifically? Members 'Time_Hierarchy379' and 'Time_Hierarchy383' have been created manually, and they are not a part of the data in the source dimension tables. Help, please.

    Thank you
    Krishna

    It is not necessary that these two members is a part of the data in the source table.

    During the creation of the rule file, you can insert a column with 'create text using... "and specify the Member under which you want the hierarchy must be created. Label with appropriate generation and level and you should be able to build the desired hierarchy.

    Kind regards
    Sunil

Maybe you are looking for