Table to XML via SQL ?

Hi everybody,
I'm stucked on this problem since 2 days...
I want to generate pseudo-XML data from a single table which (simplified) definition is:
Tag         Key     Parent    Data
Root        1       NULL      ABC
Node        2       1         DEF
Node        3       1         GHI
SubNode1    4       3         KLM
SubNode11   5       4         NOP
SubNode11   6       4         QRS
SubNode12   7       4         TUV
SubNode12   8       4         WXY
SubNode1    9       3         Z01
SubNode12   10      9         234What I want to generate something like:
<Root>ABC
<Node>DEF</Node>
<Node>GHI
  <SubNode1>KLM
   <SubNode11>Nop</SubNode11>
   <SubNode11>QRS</SubNode11>
   <SubNode12>TUV</SubNode12>
   <SubNode12>WXY</SubNode12>
  </SubNode1>
  <SubNode1>Z01
   <SubNode12>234</SubNode12>
  </SubNode1>
</Node>
</Root>(The result could be a single row, or one row per line)
I'm trying to use a single SQL query to do this job (maybe I'm crazy, OK! :)). I tryed several ones. For example, this one :
SELECT LPAD(' ',2*(LEVEL-1)) || '<' || Tag || '>' || Data || '</' || Tag || '>'
FROM XML_TBL
START WITH Parent IS NULL
CONNECT BY PRIOR Key = ParentThis query gives me (one row per line):
<Root>ABC
<Node>DEF
<Node>GHI
  <SubNode1>KLM
   <SubNode11>NOP
   <SubNode11>QRS
   <SubNode12>TUV
   <SubNode12>WXY
  <SubNode1>Z01
   <SubNode12>234I currently can cope with this format, but I'm still tring to obtain the result I wanted. I also tried several queries including GROUPING and GROUP BY ROLLUP keywords, in order to insert end separators (</...>) after group breaks, but I never successed.
Is anybody has a clue ?
I'm aware that SQL is not really intented to that, but if a single query can greatly ease development on end-user software side, I would really appreciate :)
Thanks in advance for any hint!
And please excuse my really bad english, as this is not my mother-tongue :D
Mike

have you tried the new XML functionality of Oracle SQL?
take a look at this article from the otn page.
http://otn.oracle.com/oramag/oracle/03-may/o33xml.html
Hope it helps,
Chris S.

Similar Messages

  • How to load XML file to table (non-XML) with SQL*Loader -- issue with nulls

    I have been attempting to use SQL*Loader to load an XML file into a "regular" Oracle table. All fields work fine, unless a null is encountered. The way that nulls are represented is shown below:
    <PAYLOAD>
    <FIELD1>ABCDEF</FIELD1>
    <FIELD2/>
    <FIELD3>123456</FIELD3>
    </PAYLOAD>
    In the above example, FIELD2 is a null field and that is the way it is presented. I have searched everywhere and have not found how I could code for this. The issue is that if FIELD2 is present, it is coded like: <FIELD2>SOMEDATA</FIELD2>, but the null is represented as <FIELD2/>. Here is a sample of the control file I am using to attempt the load -- very simplistic, but works fine when fields are present:
    load data
    infile 'testdata.xml' "str '<PAYLOAD>'"
    TRUNCATE
    into table DATA_FROM_XML
    FIELD1 ENCLOSED BY '<FIELD1>' AND '</FIELD1>',
    FIELD2 ENCLOSED BY '<FIELD2>' AND '</FIELD2>',
    FIELD3 ENCLOSED BY '<FIELD3>' AND '</FIELD3>')
    What do I need to do to account for the way that nulls are presented? I have tried everything I could glean from the web and the documentation and nothing has worked. Any help would be really appreciated.

    I hadn't even got that far. can you direct me to where the docs are to import data that is stored within xml but that you don't need any xml functionality, that just happens to be the format the data is stored in? thx

  • Updating UserID field on enduser table on CUCM via sql

    Hi,
    I have a cucm cluster with local users (something around 1500 users) where the cucm users and the active directory users are complitelly different.
    I have an excel file whitch have the active directory users and the cucm users respectively and I want to run an sql update command to update the users on the cucm to be the same as the active directory users and then make a LDAP sync on the cucm.
    Someone can help me with the set sql update commant for this issue ?
    Thanks,
    Liran.

    You could do this using AXL.
    There is an updateUser Element
    (https://developer.cisco.com/site/tech/communication-collaboration/management/axl/develop-and-test/documentation/latest-version/axl-soap.gsp)
    You could program an application that reads the information from the excel sheet or a csv and sends a request for every user to CUCM.
    Unfortunately I don't have a working example for this available.
    Also have a look at the developer site:
    https://developer.cisco.com/site/tech/communication-collaboration/management/axl/axl/
    The XML-Request should look like this:
    http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/8.5">
             enduser1
             newenduser1

  • Selecting xml-messages from ORABPEL-schema via SQL

    Hi,
    i want to select xml documents via SQL from the ORABPEL schema.
    Can anybody help, how to do this?
    There is the table xml_document, which has the columns:
    DOCKEY
    DOMAIN_REF
    BIN_CSIZE
    BIN_USIZE
    BIN
    MODIFY_DATE
    BIN_FORMAT
    Bin is of type blob....

    "Installation Monkey", did you ever find a solution or sample code to access and decipher the Audit_trail.LOG contents through a query or using SQL lob calls?
    I have looked all over, tried decoding the hex code (into a second layer of gibberish), and found nothing other than pointers to the API bpels.
    Thank you for any information.

  • Creating XML file via sql in 10g database

    Hi
    I am using an Oracle 10g database and via a procedure that is called from Forms 10g, I want to output data in XML format so that this file can be fed into an accounting system that uses XML.
    How do I go about doing this?

    How do I go about doing this?The most flexible way is via SQL/XML publishing functions.
    And use DBMS_XSLPROCESSOR.CLOB2FILE to write the result to a file in a single call :
    DECLARE
      xmlresult      clob;
    BEGIN
      select xmlelement("Departments",
               xmlagg(
                 xmlelement("Department",
                   xmlattributes(
                     d.deptno as "id"
                   , d.dname as "name"
                 , xmlelement("Employees",
                     xmlagg(
                       xmlelement("Employee",
                         xmlattributes(e.empno as "id")
                       , xmlforest(
                           e.ename as "Name"
                         , e.job as "Job"
                         , e.mgr as "ManagerId"
                       ) order by e.empno
                 ) order by d.deptno
             ).getclobval()
      into xmlresult    
      from scott.dept d
           join scott.emp e on e.deptno = d.deptno
      group by d.deptno, d.dname
      dbms_xslprocessor.clob2file(xmlresult, 'TEST_DIR', 'departments.xml');
    END;
    /Output : departments.xml in Oracle directory TEST_DIR :
    <Departments>
      <Department id="10" name="ACCOUNTING">
        <Employees>
          <Employee id="7782">
            <Name>CLARK</Name>
            <Job>MANAGER</Job>
            <ManagerId>7839</ManagerId>
          </Employee>
          <Employee id="7839">
            <Name>KING</Name>
            <Job>PRESIDENT</Job>
          </Employee>
          <Employee id="7934">
            <Name>MILLER</Name>
            <Job>CLERK</Job>
            <ManagerId>7782</ManagerId>
          </Employee>
        </Employees>
      </Department>
      <Department id="20" name="RESEARCH">
        <Employees>
          <Employee id="7369">
            <Name>SMITH</Name>
            <Job>CLERK</Job>
            <ManagerId>7902</ManagerId>
          </Employee>
          <Employee id="7566">
            <Name>JONES</Name>
            <Job>MANAGER</Job>
            <ManagerId>7839</ManagerId>
          </Employee>
          <Employee id="7902">
            <Name>FORD</Name>
            <Job>ANALYST</Job>
            <ManagerId>7566</ManagerId>
          </Employee>
        </Employees>
      </Department>
      <Department id="30" name="SALES">
        <Employees>
          <Employee id="7499">
            <Name>ALLEN</Name>
            <Job>SALESMAN</Job>
            <ManagerId>7698</ManagerId>
          </Employee>
          <Employee id="7521">
            <Name>WARD</Name>
            <Job>SALESMAN</Job>
            <ManagerId>7698</ManagerId>
          </Employee>
          <Employee id="7654">
            <Name>MARTIN</Name>
            <Job>SALESMAN</Job>
            <ManagerId>7698</ManagerId>
          </Employee>
          <Employee id="7698">
            <Name>BLAKE</Name>
            <Job>MANAGER</Job>
            <ManagerId>7839</ManagerId>
          </Employee>
          <Employee id="7844">
            <Name>TURNER</Name>
            <Job>SALESMAN</Job>
            <ManagerId>7698</ManagerId>
          </Employee>
          <Employee id="7900">
            <Name>JAMES</Name>
            <Job>CLERK</Job>
            <ManagerId>7698</ManagerId>
          </Employee>
        </Employees>
      </Department>
    </Departments>(formatted for display purpose)

  • Internal PLSQL Tables Access via SQL. But how ?

    Hello,
    I want to write the result of a database query in an internal PLSQL Table. After that i would like work with this internal PLSQL Table
    in a Package/Procedure/Function.
    Important for me is to access the internal Table via SQL because i have to refactor a package wich is working with 46 Database Tables an plain SQL. I
    would like to change these DB Tables into internal PLSQL Tables.
    I have written a short example wich will explain my approach to solving this problem.
    The syntax will be accepted by the Database but my 'dbms_output.put_line' statement at the end is empty or blank.
    What do i wrong ? Would be nice if anyone can help me out.
    With best regards
    Jens
    pre work :
    create table PERSON_DB_TABLE
    (SURNAME  VARCHAR2(50),
    LASTNAME VARCHAR2(50));
    insert into PERSON_DB_TABLE values
    ('JENS','FOERSTER');
    insert into PERSON_DB_TABLE values
    ('MAX','MEIER');
    insert into PERSON_DB_TABLE values
    ('MARTHA','MUSTERMANN');
    create type PERSON_OBJECT as object (
        SURNAME  VARCHAR2(50),
        LASTNAME VARCHAR2(50));
    create type PERSON_NESTED_TABLE as table of PERSON_OBJECT;
    now my anonymous block
    declare
       v_PERSON_OBJECT        PERSON_OBJECT;
       v_PERSON_NESTED_TABLE  PERSON_NESTED_TABLE;
       v_PERSON_OBJECT_2      PERSON_OBJECT;
    begin
       for v_counter in (select SURNAME, LASTNAME into v_PERSON_OBJECT.SURNAME,
                                                                                            v_PERSON_OBJECT.LASTNAME
                                  from PERSON_DB_TABLE)
         loop
            v_PERSON_NESTED_TABLE := PERSON_NESTED_TABLE(v_PERSON_OBJECT);
         end loop;
       for v_counter in (select SURNAME, LASTNAME into v_PERSON_OBJECT_2.SURNAME,
                                                                                            v_PERSON_OBJECT_2.LASTNAME
                                  from TABLE (v_PERSON_NESTED_TABLE))
         loop
            dbms_output.put_line(v_PERSON_OBJECT_2.LASTNAME);
         end loop; 
    end;

    1386a7b8-e834-43bf-a0d4-922b548bb70b wrote:
    I need this, because my customer didn't like the idea to use Database Tables instead of Variables in the RAM. So he wants this procedure redesigned.
    As Mike says, keep this person away from your database.
    Customers should not be dictating how to implement technical solutions, they should be providing business and logical requirements.
    PL/SQL arrays/collections use expensive PGA memory, taking up valuable server resources.
    Copying data from the database to PGA memory to try and process it using PL/SQL is bad design.  SQL is designed specifically for data manipulation using database tables, so it's the ideal way to do process data... directly on database tables.

  • Can a SQL SERVER table be accessed via Oracle Forms

    My boss asked me this question today. I am pretty sure the answer is "no", but thought it better to throw it out to the crowd:
    "Can a SQL SERVER table be accessed via Oracle Forms?"

    Yes, this is possible using Oracle's Transparent Gateway. Check out the My Oracle Support (formerly Metalink) document "How To Create A Form Based on SQL Server Table" (Doc ID: 564915.1) for all of the details. This document is based on Forms 10g (10.1.2.0.2) so you may need to upgrade your Forms version if you are not already at this version at a minimum.
    Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • Tables created via SQL...

    There is a way to show information stored in a table creadted via SQL in the SBO Print Forms ?

    Hello!
    yes, this will work as such, but might not give you the
    correct values as there is no link between the table and the layout! Usually, it pulls simply the first value in the table.
    Or, you might be lucky that it works now, but not after an upgrade.
    Be careful when adding field with "ALT", if you encounter problems at any stage, you will not receive any support!
    When adding fields via "ALT", check if you can create manual links between the table and the layout via "next segment" and "link to".
    Kind regards

  • Loading XML files in Oracle via SQL*Loader

    Hello,
    I need to load the data in an XML file provided by a thrird party into my Oracle DB. This file is not formatted as per the requirements of XSU, so I need to find an alternative. In the online documentation for Oracle8i it is stated that one way to load XML files into Oacle is via SQL*Loader. On the SQL*Loader documentation this is not mentioned. Also as far as I know, SQL*Loader can be used with delimited fields or fixed length fields and thus I do not see how this can be done (but it would be very cool).
    Can you give me any advice on this?
    Thanks
    Ciao
    Ferruccio

    No, SQL*Loader cannot process DBF files directly
    Tom Kyte provides a package to read in DBF files thorugh utl_file
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:711825134415

  • Creating APEX pages via SQL scripts..

    Hi Guys,
    I want to create APEX pages via SQL Script. The main reason to have this option that I have couple of applications which has XML files for screen definition where I can read all screen properties (field types, sizes, caption, etc...)
    Is there any documentation or help stuff where I can find the APEX page definition tables? I found something like WWV tables but I couldnt figure it out properly...
    Any help ?
    Thanks,
    Osman...

    We have built our entire apex app in a similar way. We create the shell apex pages using apex (eg, Item Detail, Insert Item, etc.). Then we create a PL/SQL region on the page. The PL/SQL region simply calls a stored procedure to render the controls on the page. For example, our regions looks similar to this:
    begin
    apex_pkg.sp_render_page('ITEM_DETAIL',Param1,Param2,Param3);
    end;
    The sp_render_page procedure in the database generates the appropriate HTML for the page. This procedure reads meta data in the database (eg, field label, field size, field type, field position, etc.) and renders the same HTML that apex would render if the apex page was manually created. For example, in the procedure we use lines similar to these:
    HTP.p(apex_item.text(...))
    HTP.p(apex_item.select_list_from_query(...))
    Because the procedure is reading meta data, the apex page is dynamic and can be different for different users or clients.
    Darrin

  • How to write a procedure to load the data into a table using xml file as input to the procedure?

    Hi,
    Iam new to the xml,
    can u please anyone help me how to write procedure to load the data into a table using xml as input parameter to a procedure and xml file is as shown below which is input to me.
    <?xml version="1.0"?>
    <DiseaseCodes>
    <Entity><dcode>0</dcode><ddesc>(I87)Other disorders of veins - postphlebitic syndrome</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    <Entity><dcode>0</dcode><ddesc>(J04)Acute laryngitis and tracheitis</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    <Entity><dcode>0</dcode><ddesc>(J17*)Pneumonia in other diseases - whooping cough</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    </DiseaseCodes>.
    Regards,
    vikram.

    here is the your XML parse in 11g :
    select *
      from xmltable('//Entity' passing xmltype
    '<?xml version="1.0"?>
    <DiseaseCodes>
    <Entity><dcode>0</dcode><ddesc>(I87)Other disorders of veins - postphlebitic syndrome</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    <Entity><dcode>0</dcode><ddesc>(J04)Acute laryngitis and tracheitis</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    <Entity><dcode>0</dcode><ddesc>(J17*)Pneumonia in other diseases - whooping cough</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    </DiseaseCodes>
    ') columns
      "dcode" varchar2(4000) path '/Entity/dcode',
      "ddesc" varchar2(4000) path '/Entity/ddesc',
      "reauthflag" varchar2(4000) path '/Entity/reauthflag'
    dcode                                                                            ddesc                                                                            reauthflag
    0                                                                                (I87)Other disorders of veins - postphlebitic syndrome                           0
    0                                                                                (J04)Acute laryngitis and tracheitis                                             0
    0                                                                                (J17*)Pneumonia in other diseases - whooping cough                               0
    SQL>
    Using this parser you can create procedure as
    SQL> create or replace procedure myXMLParse(x clob) as
      2  begin
      3    insert into MyXmlTable
      4      select *
      5        from xmltable('//Entity' passing xmltype(x) columns "dcode"
      6                      varchar2(4000) path '/Entity/dcode',
      7                      "ddesc" varchar2(4000) path '/Entity/ddesc',
      8                      "reauthflag" varchar2(4000) path '/Entity/reauthflag');
      9    commit;
    10  end;
    11 
    12  /
    Procedure created
    SQL>
    SQL>
    SQL> exec myXMLParse('<?xml version="1.0"?><DiseaseCodes><Entity><dcode>0</dcode><ddesc>(I87)Other disorders of veins - postphlebitic syndrome</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity><Entity><dcode>0</dcode><ddesc>(J04)Acute laryngitis and tracheitis</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity><Entity><dcode>0</dcode><ddesc>(J17*)Pneumonia in other diseases - whooping cough</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity></DiseaseCodes>');
    PL/SQL procedure successfully completed
    SQL> select * from MYXMLTABLE;
    dcode                                                                            ddesc                                                                            reauthflag
    0                                                                                (I87)Other disorders of veins - postphlebitic syndrome                           0
    0                                                                                (J04)Acute laryngitis and tracheitis                                             0
    0                                                                                (J17*)Pneumonia in other diseases - whooping cough                               0
    SQL>
    SQL>
    Ramin Hashimzade

  • Can connect via ODBC but not via SQL Developer?

    Hi, all.
    My setup:
    Windows XP Pro
    JDK 1.6
    SQL Developer 2.1.1.64.45
    I'm attempting to connect to an Oracle DB using OS authentication and trying hand-entry of the host and SID; and also trying my TNS file. When I attempt to connect via SQL Developer, I get the following error:
    "Status : Failure -Test failed: ORA-01017: invalid username/password; logon denied."
    When I attempt this same connection, however, using ODBC and Access, I can get right in and see the tables.
    What can I try in order to get SQL Developer working correctly?
    Thanks,
    IVR Avenger

    I'm not really familiar with connections Using OS authentication, but if OCI+TNS based connections work you could try to activate OCI connections by selecting
    Preferences -> Database -> Advanced -> Use OCI/Thick Driverand then use the TNS connection type when creating your connection.
    It should work well even with the thin driver but i cannot help you in this case because i've never had to use this kind of authentication.

  • How to determine via SQL who created the sales order

    Hello I am trying to determine via SQL who created the Sales Order.  I'm looking at the ADOC table but having a hard time determining which record points to the sales order creation.

    Hi Jimmy,
    Try this:
    select
         T0.[DocNum], T2.[DocDate], T2.[CardCode], T2.[CardName],
         T1.U_NAME as [User Name], T2.UpdateDate as [Cancelled Date]
    from
         ORDR T0
         inner join OUSR T1 on T0.UserSign = T1.UserID
         inner join ADOC T2 on T0.DocNum = T2.DocNum
    where
         T2.LogInstanc = (select min(LogInstanc) from ADOC T3 where T3.ObjType = 17 and T3.DocNum = T0.DocNum and T3.CANCELED = 'Y')
         and T2.CANCELED = 'Y'
         and T2.ObjType = 17
    group by
         T0.DocNum, T2.DocDate, T2.CardCode, T2.CardName, T1.U_NAME, T2.UpdateDate
    Kind Regards,
    Owen

  • Export Internal Table to XML in Background

    Hi
    I need to export a internal table into xml file in background using open dataset. The file is getting created but i am not able to open the file using IE/XML editor . When i open the file uisng wordpad i can see some charcters at the end of file which prevents it from opening in xml editor. if i delete the characters(box like) and save the file. i am able to open the file
    When i downalod the same internal table via frontend using ws_downlod it works pefectly. no junk charcters are appended in the end. and hence files opens perfectly
    below is the extract of program
    START-OF-SELECTION.
       PERFORM get_data.
       PERFORM create_xml.
    FORM get_data.
       REFRESH accesos.
       CLEAR accesos.
       MOVE: '45050' TO accesos-socio-numero,
                     'MOISES MORENO' TO accesos-socio-nombre,
                     '0' TO accesos-socio-reposicion.
       APPEND accesos.
    ENDFORM.
    i am using the following function modules
    CALL FUNCTION 'SDIXML_DATA_TO_DOM'
            EXPORTING
                 name         = 'ACCESOS'
                 dataobject   = accesos[]
            IMPORTING
                 data_as_dom  = l_dom
    CHANGING
                 document     = m_document
            EXCEPTIONS
                 illegal_name = 1
                 OTHERS       = 2.
           CHECK NOT l_dom IS INITIAL.
    w_rc = m_document->append_child( new_child = l_dom ).
    CALL FUNCTION 'SDIXML_DOM_TO_XML'
    EXPORTING
    document      = m_document
    IMPORTING
    xml_as_string = w_string
    size          = w_size
    TABLES
    xml_as_table  = it_xml
    EXCEPTIONS
    no_document   = 1
    OTHERS        = 2.
    LOOP AT it_xml INTO xml_tab-d.
         APPEND xml_tab.
       ENDLOOP.
    The following syntax for open datset which does not work
      lv_physcial_file = '
    hdat03\test.xml'.
    OPEN DATASET lv_physcial_file IN BINARY MODE   FOR OUTPUT MESSAGE l_msg.
       LOOP AT xml_tab.
         TRANSFER xml_tab TO lv_physcial_file.
       ENDLOOP.
    The ws_download function works
    CALL FUNCTION 'WS_DOWNLOAD'
    EXPORTING
                   BIN_FILESIZE = W_SIZE
                   FILENAME = GK_RUTA
                   FILETYPE = 'BIN'
    TABLES
                   DATA_TAB = XML_TAB
    EXCEPTIONS
                   OTHERS = 10.
    many thnaks

    Hi Chetan,
    Can you just try changing the syntax to the following, I not sure if that will help but just try and see.
    OPEN DATASET  lv_physcial_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    Regards
    Mohamed

  • VIEW XML IN SQL*PLUS

    how can we view xml on sql*plus?
    when xmltype is viewed on sql*prompt it shows incomplete xml.
    example:
    SQL> select xmlelement("ROOT",xmlforest(1 as A, 2 as B, 3 as C)) from dual;
    XMLELEMENT("ROOT",XMLFOREST(1ASA,2ASB,3ASC))
    <ROOT>
    <A>1</A>
    <B>2</B>
    <C>3</C>
    </ROOT>
    but i generate an xml from table so it becomes quite huge. say a forest is populated with 6-8 tags. it shows broken output.
    SQL> /
    ID LIST
    <DEPT>
    <EMPLOYEE>
    <ID>2109</ID>
    <ID>3108</ID>
    <ID>4107</ID>
    <ID>5106</ID>
    <ID
    i have tried increasing bufferwidth and bufferlength tp max value (1000 and 2000 respectively) eventhen it displays the output as shown above.
    how can i view my xml?

    use this sql plus command:
    set long 2000000
    You can increase\decrease the value as required.

Maybe you are looking for