Data from table in XML data type

Hi friends,

I have data of type table, and I want that in XML to send through the web service.

could you please suggest any api available in Oracle 11 g (PLSQL) for this or any method to produce.

Help, please.

Kind regards

Tom

For example, if MY_FUNCTION() returns a MAJOR_LINE_TABLE_TYPE collection type, you can do something like this:

Select xmlserialize (document

XmlElement ("ROOT"

xmlagg (xmltype (t.object_value))

)

dash

) as a result

table (my_function ()) t;

It will generate a canonical XML document right out of the returned collection:


  
    1
    Item1
    Path1
    6
    
      
        1
        Item1
        4
        
          
            07/03/15
            08/03/15
            1
          
          
            06/03/15
            08/03/15
            2
          
        
      
      
        2
        Item2
        5
        
          
            07/03/15
            08/03/15
            1
          
          
            06/03/15
            08/03/15
            2
          
        
      
    
    
      
        1
        Item1
        Path1
        2
        
          
            1
            Item1
            4
            
              
                07/03/15
                08/03/15
                1
              
              
                06/03/15
                08/03/15
                2
              
            
          
          
            2
            Item2
            5
            
              
                07/03/15
                08/03/15
                1
              
              
                06/03/15
                08/03/15
                2
              
            
          
        
        
          
            1
            Item1
            Path1
            5
          
          
            2
            Item2
            Path2
            6
          
          
            3
            Item3
            Path3
            7
          
        
      
      
        2
        Item2
        Path2
        3
        
          
            1
            Item1
            4
            
              
                07/03/15
                08/03/15
                1
              
              
                06/03/15
                08/03/15
                2
              
            
          
          
            2
            Item2
            5
            
              
                07/03/15
                08/03/15
                1
              
              
                06/03/15
                08/03/15
                2
              
            
          
        
        
          
            1
            Item1
            Path1
            5
          
          
            2
            Item2
            Path2
            6
          
          
            3
            Item3
            Path3
            7
          
        
      
    
  
  
    2
    Item2
    Path2
    3
    
      
        1
        Item1
        4
        
          
            07/03/15
            08/03/15
            1
          
          
            06/03/15
            08/03/15
            2
          
        
      
      
        2
        Item2
        5
        
          
            07/03/15
            08/03/15
            1
          
          
            06/03/15
            08/03/15
            2
          
        
      
    
    
      
        1
        Item1
        Path1
        2
        
          
            1
            Item1
            4
            
              
                07/03/15
                08/03/15
                1
              
              
                06/03/15
                08/03/15
                2
              
            
          
          
            2
            Item2
            5
            
              
                07/03/15
                08/03/15
                1
              
              
                06/03/15
                08/03/15
                2
              
            
          
        
        
          
            1
            Item1
            Path1
            5
          
          
            2
            Item2
            Path2
            6
          
          
            3
            Item3
            Path3
            7
          
        
      
      
        2
        Item2
        Path2
        3
        
          
            1
            Item1
            4
            
              
                07/03/15
                08/03/15
                1
              
              
                06/03/15
                08/03/15
                2
              
            
          
          
            2
            Item2
            5
            
              
                07/03/15
                08/03/15
                1
              
              
                06/03/15
                08/03/15
                2
              
            
          
        
        
          
            1
            Item1
            Path1
            5
          
          
            2
            Item2
            Path2
            6
          
          
            3
            Item3
            Path3
            7
          
        
      
    
  

If this requires a minimum of effort, the drawback is that you don't have much control over the generated structure.

Optionally, apply an XSLT stylesheet to transform into the required shape.

The other option is to turn back the hierarchy of objects to relational data and use the SQL/XML functions to generate the XML content.

If you use these objects only in order to generate the XML, then you can also bypass it entirely and build the XML directly in the base tables, it will be much more effective.

Tags: Database

Similar Questions

  • to retrieve data from xml data type

    Hello...
    I have a doubt in the oracle database... Here's how to retrieve data from xml data type?

    Like this...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select xmltype('
      2  
    3 4 toMonth5 5 ctTestPan1 6 costType2 7 toYear2012 8 fromMonth12 9 fromYear2011 10 11
    ') as xml from dual) 12 -- 13 -- end of sample XMLDATA, use below query on your own table etc. as required 14 -- 15 select x.* 16 from t 17 ,xmltable('/DETAILS/FIELDS_VALUES/FIELD' 18 passing t.xml 19 columns name varchar2(30) path './NAME' 20 ,val varchar2(10) path './VALUE' 21* ) x SQL> / NAME VAL ------------------------------ ---------- toMonth 5 ctTestPan 1 costType 2 toYear 2012 fromMonth 12 fromYear 2011 6 rows selected.
  • export data from the table in xml files

    Hello

    This thread to get your opinion on how export data tables in a file xml containing the data and another (xsd) that contains a structure of the table.
    For example, I have a datamart with 3 dimensions and a fact table. The idea is to have an xml file with data from the fact table, a file xsd with the structure of the fact table, an xml file that contains the data of the 3 dimensions and an xsd file that contains the definition of all the 3 dimensions. So a xml file fact table, a single file xml combining all of the dimension, the fact table in the file a xsd and an xsd file combining all of the dimension.

    I never have an idea on how to do it, but I would like to have for your advise on how you would.

    Thank you in advance.

    You are more or less in the same situation as me, I guess, about the "ORA-01426 digital infinity. I tried to export through UTL_FILE, content of the relational table with 998 columns. You get very quickly in this case in these ORA-errors, even if you work with solutions CLOB, while trying to concatinate the column into a CSV string data. Oracle has the nasty habbit in some of its packages / code to "assume" intelligent solutions and converts data types implicitly temporarily while trying to concatinate these data in the column to 1 string.

    The second part in the Kingdom of PL/SQL, it is he's trying to put everything in a buffer, which has a maximum of 65 k or 32 k, so break things up. In the end I just solved it via see all as a BLOB and writing to file as such. I'm guessing that the ORA-error is related to these problems of conversion/datatype buffer / implicit in the official packages of Oracle DBMS.

    Fun here is that this table 998 column came from XML source (aka "how SOA can make things very complicated and non-performing"). I have now 2 different solutions 'write data to CSV' in my packages, I use this situation to 998 column (but no idea if ever I get this performance, for example, using table collections in this scenario will explode the PGA in this case). The only solution that would work in my case is a better physical design of the environment, but currently I wonder not, engaged, as an architect so do not have a position to impose it.

    -- ---------------------------------------------------------------------------
    -- PROCEDURE CREATE_LARGE_CSV
    -- ---------------------------------------------------------------------------
    PROCEDURE create_large_csv(
        p_sql         IN VARCHAR2 ,
        p_dir         IN VARCHAR2 ,
        p_header_file IN VARCHAR2 ,
        p_gen_header  IN BOOLEAN := FALSE,
        p_prefix      IN VARCHAR2 := NULL,
        p_delimiter   IN VARCHAR2 DEFAULT '|',
        p_dateformat  IN VARCHAR2 DEFAULT 'YYYYMMDD',
        p_data_file   IN VARCHAR2 := NULL,
        p_utl_wra     IN VARCHAR2 := 'wb')
    IS
      v_finaltxt CLOB;
      v_v_val VARCHAR2(4000);
      v_n_val NUMBER;
      v_d_val DATE;
      v_ret   NUMBER;
      c       NUMBER;
      d       NUMBER;
      col_cnt INTEGER;
      f       BOOLEAN;
      rec_tab DBMS_SQL.DESC_TAB;
      col_num NUMBER;
      v_filehandle UTL_FILE.FILE_TYPE;
      v_samefile BOOLEAN      := (NVL(p_data_file,p_header_file) = p_header_file);
      v_CRLF raw(2)           := HEXTORAW('0D0A');
      v_chunksize pls_integer := 8191 - UTL_RAW.LENGTH( v_CRLF );
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      --
      FOR j IN 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
        WHEN 1 THEN
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,4000);
        WHEN 2 THEN
          DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
        WHEN 12 THEN
          DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,4000);
        END CASE;
      END LOOP;
      -- --------------------------------------
      -- This part outputs the HEADER if needed
      -- --------------------------------------
      v_filehandle := UTL_FILE.FOPEN(upper(p_dir),p_header_file,p_utl_wra,32767);
      --
      IF p_gen_header = TRUE THEN
        FOR j        IN 1..col_cnt
        LOOP
          v_finaltxt := ltrim(v_finaltxt||p_delimiter||lower(rec_tab(j).col_name),p_delimiter);
        END LOOP;
        --
        -- Adding prefix if needed
        IF p_prefix IS NULL THEN
          UTL_FILE.PUT_LINE(v_filehandle, v_finaltxt);
        ELSE
          v_finaltxt := 'p_prefix'||p_delimiter||v_finaltxt;
          UTL_FILE.PUT_LINE(v_filehandle, v_finaltxt);
        END IF;
        --
        -- Creating creating seperate header file if requested
        IF NOT v_samefile THEN
          UTL_FILE.FCLOSE(v_filehandle);
        END IF;
      END IF;
      -- --------------------------------------
      -- This part outputs the DATA to file
      -- --------------------------------------
      IF NOT v_samefile THEN
        v_filehandle := UTL_FILE.FOPEN(upper(p_dir),p_data_file,p_utl_wra,32767);
      END IF;
      --
      d := DBMS_SQL.EXECUTE(c);
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT
      WHEN v_ret    = 0;
        v_finaltxt := NULL;
        FOR j      IN 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
          WHEN 1 THEN
            -- VARCHAR2
            DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
            v_finaltxt := v_finaltxt || p_delimiter || v_v_val;
          WHEN 2 THEN
            -- NUMBER
            DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
            v_finaltxt := v_finaltxt || p_delimiter || TO_CHAR(v_n_val);
          WHEN 12 THEN
            -- DATE
            DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
            v_finaltxt := v_finaltxt || p_delimiter || TO_CHAR(v_d_val,p_dateformat);
          ELSE
            v_finaltxt := v_finaltxt || p_delimiter || v_v_val;
          END CASE;
        END LOOP;
        --
        v_finaltxt               := p_prefix || v_finaltxt;
        IF SUBSTR(v_finaltxt,1,1) = p_delimiter THEN
          v_finaltxt             := SUBSTR(v_finaltxt,2);
        END IF;
        --
        FOR i IN 1 .. ceil( LENGTH( v_finaltxt ) / v_chunksize )
        LOOP
          UTL_FILE.PUT_RAW( v_filehandle, utl_raw.cast_to_raw( SUBSTR( v_finaltxt, ( i - 1 ) * v_chunksize + 1, v_chunksize ) ), TRUE );
        END LOOP;
        UTL_FILE.PUT_RAW( v_filehandle, v_CRLF );
        --
      END LOOP;
      UTL_FILE.FCLOSE(v_filehandle);
      DBMS_SQL.CLOSE_CURSOR(c);
    END create_large_csv;
    
  • selection column of the table xml data type

    Hello.
    I tried the following example with xml as column name data type
    create table emp_detail( empno number,ename varchar2(32),empdetails sys.xmltype)
    
    Insert into EMP_DETAIL
       (EMPNO, ENAME, EMPDETAILS)
     Values
       (1, 'satya', XMLTYPE('<NAME>
      <FIRSTNAME>SATYA</FIRSTNAME>
      <LASTNAME>SREE</LASTNAME>
      <LOC>SECBAD</LOC>
    </NAME>
    '));
    Insert into EMP_DETAIL
       (EMPNO, ENAME, EMPDETAILS)
     Values
       (2, 'jo', XMLTYPE('<NAME>
      <FIRSTNAME>JO</FIRSTNAME>
      <LASTNAME>REDDY</LASTNAME>
      <LOC>MYPR</LOC>
    </NAME>
    '));
    So, after that I tried this query to retrieve the State of an attribute data.
    SELECT a.empdetails.extract('//NAME/text()').getStringVal() AS "Table Name"
    FROM   emp_detail a
    WHERE  a.empdetails.existsNode('/NAME')  = 1;
    But those who above indicates no record...
    Why?


    Thank you
    SQL>  SELECT a.empdetails.extract('//NAME/FIRSTNAME/text()').getStringVal() AS "first_name",
      2     a.empdetails.extract('//NAME/LASTNAME/text()').getStringVal() AS "last_name",
      3     a.empdetails.extract('//NAME/LOC/text()').getStringVal() AS "loc"
      4     FROM emp_detail a
      5    WHERE a.empdetails.existsNode('/NAME')  = 1;
    
    first_name           last_name            loc
    -------------------- -------------------- --------------------
    SATYA                SREE                 SECBAD
    JO                   REDDY                MYPR
    
  • Table design for the newspaper error due to a xml data type

    Hello

    I am trying to create a table of error log, but I get the below error

    ORA-20069: unsupported column or the types found:

    Table on which I am trying to create a column with the xml data type.

    Is there a way to create the error table for tables with the XML data type.

    Thank you

    PAL

    http://docs.Oracle.com/CD/E11882_01/server.112/e41084/statements_9014.htm#SQLRF55101

    Concerning

    Etbin

    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e40758/d_errlog.htm#ARPLS680

    Look at the skip_unsupported setting

  • From a function table: invalid data type error

    Hello

    I'm a ORA-00902: invalid data type error when I try to call the function from a select statement below. Here, I am leaving an array from a function.
    create or replace package pkg10
    as
    
    type tabletype1 is table of table1%rowtype
    index by binary_integer;
    
    function func1 return tabletype1;
    
    end pkg10;
    create or replace package body pkg10
    as
    
    function func1 return tabletype1 
    is
        v_tab1 tabletype1;
        idx integer;
    begin 
    
        idx := 1;
        
        for i in (select * from table1)
        loop
            v_tab1(idx).name1 := i.name1;
            v_tab1(idx).key := i.key;
            idx := idx+1;
            
        end loop;
    
    return v_tab1; 
    
    end func1; 
    
    end pkg10;
    select * from table(pkg10.func1);
    Please point out to me where I'm wrong.

    Thank you

    Sathya Vamsi says:
    Hello

    I'm a ORA-00902: invalid data type error when I try to call the function from a select statement below. Here, I am leaving an array from a function.

    create or replace package pkg10
    as
    
    type tabletype1 is table of table1%rowtype
    index by binary_integer;
    
    function func1 return tabletype1;
    
    end pkg10;
    
    create or replace package body pkg10
    as
    
    function func1 return tabletype1
    is
    v_tab1 tabletype1;
    idx integer;
    begin 
    
    idx := 1;
    
    for i in (select * from table1)
    loop
    v_tab1(idx).name1 := i.name1;
    v_tab1(idx).key := i.key;
    idx := idx+1;
    
    end loop;
    
    return v_tab1; 
    
    end func1; 
    
    end pkg10;
    
    select * from table(pkg10.func1);
    

    Please point out to me where I'm wrong.

    Thank you

    you try to use a data type of PL/SQL as part of an SQL statement. is NOT authorized.

  • table col name get the details of the table column and inserting of values depending on the data type of the column

    Hello

    I am train to write a procedure where I would spend the table as a parameter name and then the code would determine it is column names, and then he would insert records in each column depending on the data type. could someone help me with this.

    Thank you

    SM

    Hello

    Perhaps you need to dummy data just for the table.

    Here is my exercise

    create or replace
    procedure generate_rows(p_table_name varchar2, p_count number)
    is
      --
      function insert_statement(p_table_name varchar2) return clob
      is
        l_columns clob;
        l_expressions clob;
        l_sql clob default
          'insert into p_table_name (l_columns) select l_expressions from dual connect by level <= :p_count';
      begin
        select
          -- l_columns
          listagg(lower(column_name), ',') within group (order by column_id),
          -- l_expressions
          listagg(
            case
            when data_type = 'DATE'
              then  'sysdate'
            when data_type like 'TIMESTAMP%'
              then  'systimestamp'
            when data_type = 'NUMBER'
              then  replace('dbms_random.value(1,max)',
                      'max', nvl(data_precision - data_scale, data_length)
                    )
            when data_type = 'VARCHAR2'
              then  replace(q'|dbms_random.string('a',data_length)|',
                      'data_length', data_length
                    )
            else
                    'NULL'
            end, ',') within group (order by column_id)
        into
          l_columns,
          l_expressions
        from user_tab_columns
        where table_name = upper(p_table_name);
        --
        l_sql := replace(replace(replace(l_sql,
          'p_table_name', p_table_name),
          'l_columns', l_columns),
          'l_expressions', l_expressions);
        -- debug
        dbms_output.put_line(l_sql);
        --
        return l_sql;
      end;
    begin
      execute immediate insert_statement(p_table_name) using p_count;
    end;
    /
    
    -- test
    create table mytable(
      id number(4,0),
      txt varchar2(10),
      tstz timestamp with time zone,
      dt date,
      xml clob
    )
    ;
    set serveroutput on
    exec generate_rows('mytable', 10);
    select id, txt from mytable
    ;
    drop procedure generate_rows
    ;
    drop table mytable purge
    ;
    
    Procedure GENERATE_ROWS compiled
    Table MYTABLE created.
    PL/SQL procedure successfully completed.
    
    insert into mytable (id,txt,tstz,dt,xml) select dbms_random.value(1,4),dbms_random.string('a',10),systimestamp,sysdate,NULL from dual connect by level <= :p_count
            ID TXT
    ---------- ----------
             3 WnSbyiZRkC
             2 UddzkhktLf
             1 zwfWigHxUp
             2 VlUMPHHotN
             3 adGCKDeokj
             3 CKAHGfuHAY
             2 pqsHrVeHwF
             3 FypZMVshxs
             3 WtbsJPHMDC
             3 TlxYoKbuWp
    
    10 rows selected
    
    Procedure GENERATE_ROWS dropped.
    Table MYTABLE dropped.
    

    and here is the vision of Tom Kyte for the same https://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:2151576678914

    Edit: to improve my code, it must use p_count as bind as Tom.

  • XMLTable: definition of the columns data type of table

    Hello world

    I am using ORACLE 11 g and you want to shred XML into a table called test used. I was hoping I'd be able to get the types of data to the employees table existing instead of specify them in the clause of columns. Is this possible?

    Here is an example of what I'm trying to do. But I get an error: PL/SQL: ORA-00907: lack the right parenthesis on the line starting with columns.
        insert into EMPLOYEES
         select *
           from xmltable(
           '/employees/employee'
            passing EMP_XML
    
            columns FIRST_NAME EMPLOYEES.FIRST_NAME%TYPE path 'first_name',
                    LAST_NAME  EMPLOYEES.LAST_NAME%TYPE  path 'last_name',
                    GENDER     EMPLOYEES.GENDER%TYPE     path 'gender',
                    AGE        EMPLOYEES.AGE%TYPE        path 'age'
            );
    Error details
            columns FIRST_NAME EMPLOYEES.FIRST_NAME%TYPE path 'first_name',
                                *          
    
    ERROR at line 16:
    ORA-06550: line 16, column 42:
    PL/SQL: ORA-00907: missing right parenthesis
    ORA-06550: line 11, column 5:
    PL/SQL: SQL Statement ignored
    Thank you.

    Specification of column names is required, but you can omit the declaration of data types.

    See: the function XMLTABLE SQL/XML in Oracle XML DB

    XMLTable is used with storage XML based on a schema of XMLType data type is optional. If absent, the data type is inferred from the XML schema. If Oracle > XML DB is unable to determine the right type of a node, a default type VARCHAR2 (4000) is used.

    It is an Oracle extension; in the SQL/XML standard, the data type is always required.

    Note:
    The alleged data type might change as a result of the application of a patch or upgrade of Oracle XML DB. In particular, a new set of release or patch might be able to > determine the data type when the previous version was unable to do so (and therefore not reimbursed to VARCHAR2 (4000)). To protect against such an eventuality, specify an explicit data type with the data type.

  • The table in XML data

    Dear Sir

    The current ver is 10gXe

    I trf suite data through two table the Pl/sql procedure in table sales, filed (col) narr varchar2 (200)

    How can I select all in xml?

    is it possible to convert given below even even in Formate of xml

    > < 1 INVOICE NUMBER < / INVOICE NUMBER >
    < DATE 14/09/2011 invoice - > < / DATE of INVOICE >
    < BILLING - >
    Pipe of the first < DESCRIPTION OF PRODUCTS > carbon steel seamless < / PRODUCT >
    CETSH < NUMBER > 73049000 < / CETSH-NUMBER >
    QUANTITY < CODE > KG < / QUANTITY-CODE >
    < QUANTITY > 40 < / QUANTITY >
    < AMOUNT-OF-DUTY-set GAME > 3699 < / QUANTITY-OF-DUTY-INCURRED >
    < / BILLING >
    < / INVOICE-INSTRUCTIONS >

    You must use the getClobVal() method to convert the XMLType to a character data type:

    ...
    ).extract('/*').getclobval() as yourXML
    from demo_orders o;
    
  • Add a new node to an existing XML (CLOB) data type

    Hi guys,.

    I have a table with one of his field as a CLOB data type that stores a XML here, now I need to add an additional node to the XML.

    <?xml version="1.0" encoding="UTF-8"?><alert>
     
         <tab0 comment="section in XSL component" name="Initial Information">
              <details>     
                   <Priority>0001</Priority>
                   <DateVRUClaimInitiated>2010-06-29</DateVRUClaimInitiated>
              
              </details>
              <contacts comment="grid in XSL component">
                   many child nodes here
              </contacts>               
         </tab0>
     
         <tab1 comment="section in XSL component" name="Additional Information">
              <details comment="list collection in XSL component">
                   <Channel1>123</Channel1>
              </details>
              <IPAddresses>
                   Many child nodes here
              </IPAddresses>          
              <ANIPhones>
                   Many child nodes here
              </ANIPhones>
         </tab1>
    </alert>
    Here, in this xml file, I need to add this node < / canal2 >... so my xml should look like
    <?xml version="1.0" encoding="UTF-8"?><alert>
     
         <tab0 comment="section in XSL component" name="Initial Information">
              <details>     
                   <Priority>0001</Priority>
                   <DateVRUClaimInitiated>2010-06-29</DateVRUClaimInitiated>
              
              </details>
              <contacts comment="grid in XSL component">
                   many child nodes here
              </contacts>               
         </tab0>
     
         <tab1 comment="section in XSL component" name="Additional Information">
              <details comment="list collection in XSL component">
                   <Channel1>123</Channel1></Channel2>
              </details>
              <IPAddresses>
                   Many child nodes here
              </IPAddresses>          
              <ANIPhones>
                   Many child nodes here
              </ANIPhones>
         </tab1>
    </alert>
    I can do using an update or something?

    but it converts my CLOB to ORAXML.

    then use getclobval():

    select insertchildxml(xml, '/alert/tab1/details', 'Channel2' ,xmltype('')).getclobval() xml from t
    
  • the value of the xml column type tag data BLOB

    Hello

    I'm on Oracle 10 g.
    I have a table that has a column as BLOB data type and contains XML data. I need to select specific table records according to a unique tag value of the xml data in the BLOB column. For example:
    The table say Test has two columns: id (integer) and MESG (BLOB)
    The xml in the MESG column message is assumed:
    < message >
    < > 123456 contactphone < / contactphone >
    < contactname > ABCD < / contactname >
    < amount > 9999 < / amount >
    < / message >

    I need to extract only the records where the amount is = 9999

    Help, please. Thanks in advance.

    user12850338 wrote:
    Hi BluShadow,
    Thanks for your reply.
    I confess that if we would have used type xml in the first place, things would have been easier.
    For example, I mentioned three tags in the xml file, but my real data contains some hundreds of tags... :( So it will always be a good idea with this approach.

    Yes, it's a good approach. Oracle has provided built-in XML functionality to manage XML, then of course it's the best thing to use. :)

    For example, you can easily deal with namespaces and repeating nested groups and flatten the data in a table structure. for example

    SQL> ed
    Wrote file afiedt.buf
    
      1  WITH t as (select XMLTYPE('
      2  
      3    
      4      1
      5      1800
      6      
      7        1
      8        28
      9        6
     10        12
     11      
     12      
     13        5
     14        19
     15        1
     16        90
     17      
     18    
     19    
     20      2
     21      2400
     22      
     23        3
     24        14
     25        7
     26        5
     27      
     28    
     29  ') as xml from dual)
     30  -- END OF TEST DATA
     31  select x.country, x.point, y.user_id, y.target, y.state, y.task
     32  from t
     33      ,XMLTABLE(XMLNAMESPACES('http://www.w3.org' as "aa"),
     34                '/RECSET/aa:REC'
     35                PASSING t.xml
     36                COLUMNS country NUMBER PATH '/aa:REC/aa:COUNTRY'
     37                       ,point   NUMBER PATH '/aa:REC/aa:POINT'
     38                       ,user_info XMLTYPE PATH '/aa:REC/*'
     39               ) x
     40      ,XMLTABLE(XMLNAMESPACES('http://www.w3.org' as "aa"),
     41                '/aa:USER_INFO'
     42                PASSING x.user_info
     43                COLUMNS user_id NUMBER PATH '/aa:USER_INFO/aa:USER_ID'
     44                       ,target  NUMBER PATH '/aa:USER_INFO/aa:TARGET'
     45                       ,state   NUMBER PATH '/aa:USER_INFO/aa:STATE'
     46                       ,task    NUMBER PATH '/aa:USER_INFO/aa:TASK'
     47*              ) y
    SQL> /
    
       COUNTRY      POINT    USER_ID     TARGET      STATE       TASK
    ---------- ---------- ---------- ---------- ---------- ----------
             1       1800          1         28          6         12
             1       1800          5         19          1         90
             2       2400          3         14          7          5
    
    SQL>
    
  • How to extract data using the xml data type

    Hello
    I tried the following example using the xml data type, but not the desired output.
    could you please correct the query in order to obtain the necessary
    CREATE TABLE TEST.EMP_DETAIL
    (
      EMPNO       NUMBER,
      ENAME       VARCHAR2(32 BYTE),
      EMPDETAILS  SYS.XMLTYPE
    )
    Insert into EMP_DETAIL
       (EMPNO, ENAME, EMPDETAILS)
     Values
       (7, 'Martin', XMLTYPE('<Dept>
      <Emp Empid="1">
        <EmpName>Kevin</EmpName>
        <Empno>50</Empno>
        <DOJ>20092008</DOJ>
        <Grade>E3</Grade>
        <Sal>3000</Sal>
      </Emp>
      <Emp Empid="2">
        <EmpName>Coster</EmpName>
        <Empno>60</Empno>
        <DOJ>01092008</DOJ>
        <Grade>E1</Grade>
        <Sal>1000</Sal>
      </Emp>
      <Emp Empid="3">
        <EmpName>Samuel</EmpName>
        <Empno>70</Empno>
        <DOJ>10052008</DOJ>
        <Grade>E2</Grade>
        <Sal>2530</Sal>
      </Emp>
      <Emp Empid="4">
        <EmpName>Dev</EmpName>
        <Empno>80</Empno>
        <DOJ>10032007</DOJ>
        <Grade>E2</Grade>
        <Sal>1200</Sal>
      </Emp>
    </Dept>
    '));
    I need to get the record for Empid = '2'
    Then tried the following query with no expected o/p
    SELECT a.empno,a.ename,a.empdetails.extract('//Dept/Emp/EmpName/text()').getStringVal() AS "EmpNAME",
         a.empdetails.extract('//Dept/Emp/Empno/text()').getStringVal() AS "EMPNumber",
          a.empdetails.extract('//Dept/Emp/DOJ/text()').getStringVal() AS "DOJ",
          a.empdetails.extract('//Dept/Emp/Grade/text()').getStringVal() AS "Grade",
          a.empdetails.extract('//Dept/Emp/Sal/text()').getStringVal() AS "Salary",
          a.empdetails.extract('//Dept/Emp[@Empid="2"]').getStringVal() AS "ID",
          a.empdetails.extract('//Dept/Emp[EmpName="Coster"]').getStringVal() AS "CHK"
         FROM emp_detail a 
         where empno=7  
               AND a.empdetails.existsNode('//Dept/Emp[@Empid="2"]') =1
    Thank you...

    Karthick_Arp wrote:
    I'm not very good at that... But if your XML code should not be more like this

    SQL> Insert into EMP_DETAIL
    2     (EMPNO, ENAME, EMPDETAILS)
    3   Values
    4     (7, 'Martin', XMLTYPE('
    5    
    6      1
    7      Kevin
    8      50
    9      20092008
    10      E3
    11      3000
    12    
    .. cut ..
    

    Why? It is perfectly valid to data as attributes rather than elements and also quite common for key values.

  • Problem of XML data type

    I am trying to unflatten data from an xml file but my entry type for the type on the unflatten my guess isn't valid, and I get error 1106.

    Is attached, the file xml and VI

    XML file is in text loading constraints

    Your cluster of data type does not match your XML file. Fixed VI (LV version 2013) is attached. However, the file you posted seems to be a single element, not the entire file, so I can't verify that it works.

    If you have a previous version of LabVIEW, the cluster lacked a time stamp and had a cluster at the end which should be a string.

    Double post here.

  • Syntex to create the table with the long data type

    I'm looking to create a table based on another table that having the column long data type. Throw the error ORA-00997: illegal use of the LONG data type


    I tired it

    create table abc_long (ag bgd long number);

    create table abc_long_dummy as ( ) Select *of abc_long); - ORA-00997 error: illegal use of the LONG data type

    How to get there?

    I'm looking to create a table based on another table that having the column long data type.

    You really don't want to do that.

    LONG data type has been deprecated for some time now, use CLOB.

    The TO_LOB() function will do the conversion on the fly:

    create table abc_long_dummy
    as
    select ag
         , to_lob(bgd) as bgd
    from abc_long ;
    
  • Change the Data Type of column on large partitioned Table Tablet

    Hello

    I was tasked to change a certain NUMBER of collar to a colonel VARCHAR2

    It is usually an easy task, but I ran into several challenges due to the size of the table, the second major problem is the compression of the table.

    To begin with, the Table and index are 4.4 to and hold around 11 lines billion. That the Table is compressed, not the index.

    The first option was to add a new collar of VCHAR, update from the Col de NUM, file and then drop the colonel NUM


    We ran this test in the Test environment and because discovered Compression Table that you can only mark the column is not used, and it can only be moved permanently from the Table if you unzip the whole Table and run «...» REMOVE the UNUSED COLUMNS'.

    The second way is to create a separate Table copy with the values of the source of neck, then write to null to the source of neck, change data Type when its empty and then update the source again with the copy Table values.

    The second option, that's what I'm testing, but I work with nearly 30 million lines by daily score, inserts take very long to fill.

    How can I make faster inserts between the Source and the copy Table?

    What other channels follow to accomplish the task above?

    Concerning

    Stephan

    Nowhere in your proposed solution was necessary for you to understand why the data source changes, its as simple that to take what is ons the table (all the facts in the original post) and offering the best way on the basis of previous experience or oracle skills acquired over time.

    If you spent so much time and thought to help with a solution that you did on WHY complain, you could have provided some feasible solutions already.

    No thanks to your information irrelevant and unnecessary, I've implemented a solution already.

    1 export the Source Table

    2. create a 'replica Table' using the DDL source using a temporary table name

    3. import all Partitions in the Table new

    4. before the Cut-Over, synchronize the changes from the Source to the replica Table

    5 rename the Source

    5 rename the Table of replica for the Original Source Table name

    6. slide the original Source Table

Maybe you are looking for

  • HP Pavilion 500 series: repair disk error

    Hello.I have a problem when I turned on my PC and it said "prepairing auto repair' followed"diagnostic PC"and finally"repair disk error, it may take more than an hour"It had been like this for 10 hours and I know something is wrong. Any help would be

  • Satellite L350 - error while restoring the Vista using the recovery disk

    Hello I had a problem with my L350.Windows Vista won't start. So I ordered recovery Toshiba dvd because I not create my own recovery dvd.But during the get back to Vista, I got error restore image. I don't know what to do now. Thanks for any help.

  • Get the EXIT and the RETURN of a stored procedure parameters

    I have a stored procedure (SQL Server 2008 R2 MS) as in the following example. Thanks to the connectivity of database I get OUTPUT parameters, but I can't get the game DATA RECORDS and RETURN value. Someone knows how to do this? CREATE PROCEDURE [dbo

  • My computer won't print on my printer

    My hp said the printer status bar is ready, but when I try to print the message printer is offline is displayed which gives? That's all nothing more to say here

  • DV7 - 1253ca: a caddy for SSD work?

    I have a dv7 - 1253ca and have tried to put an SSD in the second drive Bay without a shopping cart, but Win7 does not even recognize the drive is there. Do I need a cart for laptop to recognize the second disk?