XML from the Oracle Table data

Hi all

I'm new to this network. I'm also new to oracle XML package. I want a help with the query below.

CREATE TABLE EMP (ID NUMBER PRIMARY KEY, NAME VARCHAR2 (10), TELEPHONE NUMBER);

INSERT INTO EMP (ID, NAME, PHONE) VALUES (11, 'Joy', 1234);
INSERT INTO EMP (ID, NAME, PHONE) VALUES (22, 'Mike', 5678).
INSERT INTO EMP (ID, NAME, PHONE) VALUES (33, "Jason", NULL);
COMMIT;

I want to export data from the EMP table in an XML file with the format below.

Power required:

<? XML version = "1.0" encoding = "UTF-8"? > < Joy STATICDATA > < EMP > < ID > 11 < /ID > < NAME > < / NAME > < / EMP > < / STATICDATA >
<? XML version = "1.0" encoding = "UTF-8"? > < Mike STATICDATA > < EMP > < ID > 22 < /ID > < NAME > < / NAME > < / EMP > < / STATICDATA >
<? XML version = "1.0" encoding = "UTF-8"? > < Jason STATICDATA > < EMP > < ID > 33 < /ID > < NAME > < / NAME > < / EMP > < / STATICDATA >

I used some XML functions and you wrote the following query.

Select XMLROOT (XMLELEMENT (staticdata, XMLELEMENT (EMP, XMLELEMENT(ID,ID), XMLELEMENT(NAME,NAME))), version "1.0" encoding = "UTF - 8') xml EMP;

my query output:

<? XML version = "1.0" encoding = "UTF-8"? >
< STATICDATA >
< EMP >
< ID > 11 / < ID >
Joy of < NAME > < / NAME >
< / EMP >
< / STATICDATA >
<? XML version = "1.0" encoding = "UTF-8"? >
< STATICDATA >
< EMP >
< ID > 22 / < ID >
< NAME > Mike < / NAME >
< / EMP >
< / STATICDATA >
<? XML version = "1.0" encoding = "UTF-8"? >
< STATICDATA >
< EMP >
< ID > 33 / < ID >
Jason < NAME > < / NAME >
< / EMP >
< / STATICDATA >


But I want the out as the power required above. all records in a single line. can someone help me achieve the desired output. also can I export all columns of the table with something like select * from the table in the XML file?

Thank you
Delobelle

Don't know why you need it on a single line, but you could:

Select XMLTYPE (REGEXP_REPLACE (XMLROOT (XMLELEMENT (staticdata, XMLELEMENT (EMP, XMLELEMENT(ID,ID), XMLELEMENT(NAME,NAME))), version "1.0" encoding = "UTF - 8'), CHR (10) |)) ' *<><'))>
FROM EMP;

SY.

Tags: Database

Similar Questions

  • Generation of the XML from the Oracle tables

    I'm using Oracle 11 g R1.

    I have two tables header and the line:

    CREATE THE TABLE HEADER
    (
    EXPENSE_INFO VARCHAR2 (2000).
    NUMBER OF ERROR_CODE,
    REASON_OF_FAILURE VARCHAR2 (4000)
    )
    /


    CREATE THE ROW IN THE TABLE
    (
    EXPENSE_INFO VARCHAR2 (2000).
    DATE OF EXPENSE_DATE,
    EXPENSE_CODE VARCHAR2 (10),
    EXPENSE_REF VARCHAR2 (2000).
    GROSS_AMOUNT NUMBER,
    NUMBER OF TAX_AMOUNT,
    NUMBER OF ERROR_CODE,
    REASON_OF_FAILURE VARCHAR2 (4000)
    )
    /

    These tables are linked by the EXPENSE_INFO column.

    Complete the tables with the following data:

    Insert in the header (ErrorCode, EXPENSE_INFO, REASON_OF_FAILURE)
    values ('A', 0, 'SUCCESS');

    Insert (EXPENSE_INFO, EXPENSE_DATE, EXPENSE_CODE, EXPENSE_REF, GROSS_AMOUNT, TAX_AMOUNT, ERROR_CODE, REASON_OF_FAILURE) online
    values ('A', to_date (December 14, 2012 ', 'dd-mm-yyyy'), 'ABC', 'HOTEL', 100, 500, 0, 'SUCCESS');

    Insert (EXPENSE_INFO, EXPENSE_DATE, EXPENSE_CODE, EXPENSE_REF, GROSS_AMOUNT, TAX_AMOUNT, ERROR_CODE, REASON_OF_FAILURE) online
    values ('A', to_date (December 14, 2012 ', 'dd-mm-yyyy'), 'DEF', 'MOVIE', 10, 50, 1, "Cost Code does not exist.");

    Insert in the header (ErrorCode, EXPENSE_INFO, REASON_OF_FAILURE)
    values ('B', 1, "Emp Id does not exist.");

    Insert (EXPENSE_INFO, EXPENSE_DATE, EXPENSE_CODE, EXPENSE_REF, GROSS_AMOUNT, TAX_AMOUNT, ERROR_CODE, REASON_OF_FAILURE) online
    values ('B', to_date (December 14, 2012 ', 'dd-mm-yyyy'), "XYZ", "MILEAGE", 200, 300, 0, 'SUCCESS');



    I want to generate the XML following these tables:


    COSTS of <>
    < EXPENSE_DETAILS >
    < EXPENSE_INFO > is < / EXPENSE_INFO >
    < ERROR_CODE > 0 < / ERROR_CODE >
    SUCCESS of < REASON_OF_FAILURE > < / REASON_OF_FAILURE >
    < EXPENSE_LINES >
    < EXPENSE_LINE_REC >
    < EXPENSE_INFO > is < / EXPENSE_INFO >
    < EXPENSE_DATE > 14/12/2012 00:00:00 < / EXPENSE_DATE >
    ABC of < EXPENSE_CODE > < / EXPENSE_CODE >
    HOTEL < EXPENSE_REF > < / EXPENSE_REF >
    < GROSS_AMOUNT > 100 < / GROSS_AMOUNT >
    < > 500 TAX_AMOUNT < / TAX_AMOUNT >
    < ERROR_CODE > 0 < / ERROR_CODE >
    SUCCESS of < REASON_OF_FAILURE > < / REASON_OF_FAILURE >
    < / EXPENSE_LINE_REC >
    < EXPENSE_LINE_REC >
    < EXPENSE_INFO > is < / EXPENSE_INFO >
    < EXPENSE_DATE > 14/12/2012 00:00:00 < / EXPENSE_DATE >
    DEF < EXPENSE_CODE > < / EXPENSE_CODE >
    FILM of < EXPENSE_REF > < / EXPENSE_REF >
    < GROSS_AMOUNT > 10 < / GROSS_AMOUNT >
    < TAX_AMOUNT > 50 < / TAX_AMOUNT >
    < ERROR_CODE > 1 < / ERROR_CODE >
    < REASON_OF_FAILURE > fresh Code does not exist. < / REASON_OF_FAILURE >
    < / EXPENSE_LINE_REC >
    < / EXPENSE_LINES >
    < / EXPENSE_DETAILS >
    < EXPENSE_DETAILS >
    B < EXPENSE_INFO > < / EXPENSE_INFO >
    < ERROR_CODE > 1 < / ERROR_CODE >
    < REASON_OF_FAILURE > Employee Id does not exist. < / REASON_OF_FAILURE >
    < EXPENSE_LINES >
    < EXPENSE_LINE_REC >
    B < EXPENSE_INFO > < / EXPENSE_INFO >
    < EXPENSE_DATE > 14/12/2012 00:00:00 < / EXPENSE_DATE >
    XYZ < EXPENSE_CODE > < / EXPENSE_CODE >
    POINT MILE < EXPENSE_REF > < / EXPENSE_REF >
    < > 200 GROSS_AMOUNT < / GROSS_AMOUNT >
    < > 300 TAX_AMOUNT < / TAX_AMOUNT >
    < ERROR_CODE > 0 < / ERROR_CODE >
    SUCCESS of < REASON_OF_FAILURE > < / REASON_OF_FAILURE >
    < / EXPENSE_LINE_REC >
    < / EXPENSE_LINES >
    < / EXPENSE_DETAILS >
    < / SPENDING >


    I'm not able to generate the XML file. Kindly help me.

    Kind regards
    Sudhanshu

    I love working at the deepest level and then "wrap" with external level tags.

    You want to list all columns of each LINE by line. XMLFOREST is good for this:

    select xmlforest(
      expense_info, expense_date, expense_code, expense_ref,
      gross_amount, tax_amount, error_code, reason_of_failure
    )
    from line;
    
    A
    2012-12-14
    ABC
    HOTEL
    100
    500
    0
    SUCCESS
    ...
    

    Now you want to wrap this up in EXPENSE_LINE_REC

    select xmlelement("EXPENSE_LINE_REC",
      xmlforest(
        expense_info, expense_date, expense_code, expense_ref,
        gross_amount, tax_amount, error_code, reason_of_failure
      )
    )
    from line;
    
    
      A
      2012-12-14
      ABC
      HOTEL
      100
      500
      0
      SUCCESS
    
    

    So far, you have a XML fragment by line in the table of the LINE. You can use XMLAGG to put those together in a single fragment - or rather, a fragment by EXPENSE_INFO.

    Then you use XMLELEMENT again to give the name "EXPENSE_LINES" in this fragment.

    Then you gather the header values and the 'EXPENSE_LINES' fragment in "EXPENSE_DETAILS". This gives you all the information for each row header and associated lines of the LINE.

    Then, you gather all the information into one with XMLAGG header, and give everything a name with XMLELEMENT

    select xmlelement("EXPENSES",
      xmlagg(
        xmlelement("EXPENSE_DETAILS",
          xmlforest(expense_info, a.error_code, a.reason_of_failure),
          xmlelement("EXPENSE_LINES",
            xmlagg(
              xmlelement("EXPENSE_LINE_REC",
                xmlforest(
                  b.expense_date, b.expense_code, b.expense_ref,
                  b.gross_amount, b.tax_amount, b.error_code, b.reason_of_failure
                )
              )
            )
          )
        )
      )
    )
    from header a join line b using(expense_info)
    group by expense_info, a.error_code, a.reason_of_failure;
    

    _Note: _ with the GROUP BY clause, you can 'total' twice, once at the expense_info level and then overall. That's what I do with the two XMLAGGs: the second he puts just all the different stuff EXPENSE_DETAILS together in one package that I wrap "CHARGES" tag autour.

    Also, I omit EXPENSE_INFO of each LINE as it is already in the header information.

    Published by: stew Ashton on December 17, 2012 14:03

  • Insert data as XML into the Oracle Table

    Hi all

    I have a requirement where the data in XML format, and I need to insert into the Oracle Table. For example, I get XML data in the following format,
    < results >
    < row >
    < BANK_ACCOUNT_ID > 10010 < / BANK_ACCOUNT_ID >
    < BANK_ID > 300968 < / BANK_ID >
    Vision operations < LEGAL_ENTITY > < / LEGAL_ENTITY >
    < BANK_NAME > BofA < / BANK_NAME >
    < BANK_ACCOUNT_NUM > 10271-17621-619 < / BANK_ACCOUNT_NUM >
    < BANK_ACCOUNT_NAME > BofA-204 < / BANK_ACCOUNT_NAME >
    < BRANCH_NAME > New York < / BRANCH_NAME >
    USD < CURRENCY_CODE > < / CURRENCY_CODE >
    < BALANCE_DATE > 2007 - 11 - 09 < / BALANCE_DATE >
    < LEDGER_BALANCE > 432705900.56 < / LEDGER_BALANCE >
    < / row >
    < row >
    < BANK_ACCOUNT_ID > 10091 < / BANK_ACCOUNT_ID >
    < BANK_ID > 300984 < / BANK_ID >
    Vision industries < LEGAL_ENTITY > < / LEGAL_ENTITY >
    Barclay Bank < BANK_NAME > < / BANK_NAME >
    < BANK_ACCOUNT_NUM > 70986798 < / BANK_ACCOUNT_NUM >
    Bank Multi currency-626 < BANK_ACCOUNT_NAME > Barclays < / BANK_ACCOUNT_NAME >
    Reading < BRANCH_NAME > < / BRANCH_NAME >
    GBP < CURRENCY_CODE > < / CURRENCY_CODE >
    < BALANCE_DATE > 2007 - 11 - 14 < / BALANCE_DATE >
    < LEDGER_BALANCE > 24244085.24 < / LEDGER_BALANCE >
    < / row >
    < row >
    < BANK_ACCOUNT_ID > 10127 < / BANK_ACCOUNT_ID >
    < BANK_ID > 300968 < / BANK_ID >
    < LEGAL_ENTITY > SSC U.S. 01 < / LEGAL_ENTITY >
    < BANK_NAME > BofA < / BANK_NAME >
    < BANK_ACCOUNT_NUM > 4898744 < / BANK_ACCOUNT_NUM >
    < BANK_ACCOUNT_NAME > BofA SSC U.S. 02-7188 < / BANK_ACCOUNT_NAME >
    < BRANCH_NAME > New York < / BRANCH_NAME >
    USD < CURRENCY_CODE > < / CURRENCY_CODE >
    < BALANCE_DATE > 2007 - 11 - 28 < / BALANCE_DATE >
    < LEDGER_BALANCE > 10783815.28 < / LEDGER_BALANCE >
    < / row >
    < / results >

    I like to write PLSQL code that will receive these data with XML tags and insert it into the Oracle Table. Is this possible with built-in XML features provided in the Oracle database?

    Please Guide...

    Kind regards
    Priyanka

    But the problem is the file XML is to have the details of the records if you carefully observed the XML file. But by using more high statement select I get output in the following format.
    ORG_ID REQ_LINE PO_NUMBER EXPECTED_REC_QTY USER_NAME REQ_NUMBER
    204204 1444714450 11 64446445 11 OPERATIONSOPERATIONS

    The table has only one row, so you get a single row as output.
    I'm surprised that you find useful examples showing how to divide the data into several lines.

    (1) create the table with the following option, it will optimize the performance of storage and query for large XML documents:

    CREATE TABLE xxios_xml_data_test(xml_data XMLTYPE)
    XMLTYPE COLUMN xml_data STORE AS SECUREFILE BINARY XML
    ;
    

    (2) interview table with:

    SQL> select x.*
      2  from xxios_xml_data_test t
      3     , xmltable(
      4         '/Results/Row'
      5         passing t.xml_data
      6         columns ORG_ID           number       path 'ORG_ID'
      7               , REQ_NUMBER       number       path 'REQ_NUMBER'
      8               , REQ_LINE         number       path 'REQ_LINE'
      9               , PO_NUMBER        number       path 'PO_NUMBER'
     10               , EXPECTED_REC_QTY number       path 'EXPECTED_REC_QTY'
     11               , USER_NAME        varchar2(30) path 'USER_NAME'
     12       ) x
     13  ;
    
        ORG_ID REQ_NUMBER   REQ_LINE  PO_NUMBER EXPECTED_REC_QTY USER_NAME
    ---------- ---------- ---------- ---------- ---------------- ------------------------------
           204      14447          1       6444                1 OPERATIONS
           204      14450          1       6445                1 OPERATIONS
     
    
  • Help to download the xml of the oracle table below

    Dear all,

    I tried best to download the below xml to oracle table but giving the link between the tables is very difficult for me. can someone help me to import the XML below for oracle table

    <? XML version = "1.0" encoding = "utf-8"? >
    < Claim.Submission xmlns:tns = "http://www.haad.ae/DataDictionary/CommonTypes" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: noNamespaceSchemaLocation = "http://www.haad.ae/DataDictionary/CommonTypes/ClaimSubmission.xsd" >
    < header >
    MF65 < SenderID > < / SenderID >
    C014 < ReceiverID > < / ReceiverID >
    < TransactionDate > 03/12/2012 10:40 < / TransactionDate >
    < RecordCount > 1 < / RecordCount >
    < DispositionFlag > PRODUCTION < / DispositionFlag >
    < / header >
    < claim >
    < ID > 23112 / < ID >
    < MemberID > 100000874 < / MemberID >
    A022 < PayerID > < / PayerID >
    MF65 < ProviderID > < / ProviderID >
    < EmiratesIDNumber > 111-1111-1111111-1 < / EmiratesIDNumber >
    < raw > 115 < / gross >
    < PatientShare > 20 < / PatientShare >
    < net > 95 < / Net >
    < meeting >
    MF65 < FacilityID > < / FacilityID >
    < type > 1 < / Type >
    < > 47685 PatientID < / PatientID >
    < Start > 02/11/2012 12:00 < / Start >
    < / meeting >
    < Diagnostics >
    Principal of < type > < / Type >
    < code > < code > 461.9
    < / Diagnosis >
    < Diagnostics >
    Secondary < type > < / Type >
    < code > < code > 462
    < / Diagnosis >
    < activity >
    23112_1 < ID > < /ID >
    < Start > 02/11/2012 12:00 < / Start >
    < type > 3 < / Type >
    < code > < code > 99202
    < quantity > 1 < / quantity >
    < net > 95 < / Net >
    D1310 < clinician > < / clinician >
    < / activity >
    < / claim >
    < Claim.Submission >

    Pls tell me how I can get

    Have you considered using the storage relational object for this?
    Since you have patterns, you could record in the database, which will automatically create storage appropriate for your XML documents as well as validate at the time of insertion.
    You can then create individual views to query the nested parts of the document and finally insert the data into relational tables final.

    See the documentation for an introduction to the concepts:
    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e23094/partpg2.htm#g997354

    You will find examples on the {forum: id = 34} forum and its FAQ: {: identifier of the thread = 410714}

  • XML document to the oracle tables - data isn't fatching

    Hello
    I'm new to xml and trying to extract some fields of XML to oracle to use more in the application tables. I wrote the following to extract the values, but nothing is fatching document:



    <? XML version = "1.0" encoding = "UTF-8"? >
    -dmsgo:DMS_GO_Interface xmlns:dmsgo = "https://globalordering.daimler.com/start/dms/interface/DMS_GO_Interface/v1" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "https://globalordering.daimler.com/start/dms/interface/DMS_GO_Interface/v1 DMS_GO_Interface_v1.xsd" >
    < dmsgo:majorversion > 1 < / dmsgo:majorversion >
    < dmsgo:identity context = datetimecreated "CONFGOFR_OUT" = "03/01/2011 10:51 ' source = 'go' sourceversion ="1.410.1"/ >"
    -< dmsgo:prospect >
    < code dmsgo:requestresponse = "0" / >
    < dmsgo:references / >
    -dmsgo:configurationcontext dataversion = LangueCode "2163" = "" orderingmarket = '867' saleslevel "O" = >
    < dmsgo:configurationdate > 03/01/2011 < / dmsgo:configurationdate >
    < / dmsgo:configurationcontext >
    -< dmsgo:vehicle >
    < dmsgo: variant baumuster = "2120482" manufacturercode = "2120482" / >
    < dmsgo:desc > E 200 CGI BlueEFFICIENCY sedan RHD < / dmsgo:desc >
    -< dmsgo:colorcombination >
    < dmsgo:interiorcolor codeowner = 'C' manufacturercode = "4201" = ppmtype "to THE" > black leather < / dmsgo:interiorcolor >
    < dmsgo:exteriorcolor = 'C' manufacturercode codeowner = "2497" ppmtype "READ" = > metal Brown corrosion < / dmsgo:exteriorcolor >
    < dmsgo:paintzone manufacturercode = "" preference = "2" / > "
    < / dmsgo:colorcombination >


    INSERT INTO p1 (flux_name, elment_1, elment_2, elment_3)
    SELECT flux_name, elment_1, elment_2, elment_3
    FROM XMLTable)
    XMLNamespaces ('https://globalordering.daimler.com/start/dms/interface/DMS_GO_Interface/v1' as 'dmsgo'),
    "dmsgo:DMS_GO_Interface/perspective/vehicle.
    passage xmltype (bfilename('DMLDIR','prospect.xml'), nls_charset_id ('CHAR_CS'))
    columns
    path of varchar2 (20) flux_name "dmsgo:variant/@baumuster"
    path of varchar2 (20) elment_1 "dmsgo:desc"
    path of varchar2 (20) elment_2 ' dmsgo:colorcombination / interiorcolor',
    path of varchar2 (20) elment_3 'dmsgo:colorcombination/interiorcolor/@manufacturercode '.
    );

    Help, please.

    Looking forward to early response.

    Thank you
    Usman

    Hello

    'Re missing you the prefix to namespace on elements.
    This should work:

    SQL> SELECT flux_name, elment_1, elment_2, elment_3
      2  FROM XMLTable(
      3    XMLNamespaces ('https://globalordering.daimler.com/start/dms/interface/DMS_GO_Interface/v1' as "dmsgo"),
      4    'dmsgo:DMS_GO_Interface/dmsgo:prospect/dmsgo:vehicle'
      5    passing xmltype(bfilename('DMLDIR','prospect.xml'), nls_charset_id('CHAR_CS'))
      6    columns
      7      flux_name varchar2(20) path 'dmsgo:variant/@baumuster',
      8      elment_1  varchar2(40) path 'dmsgo:desc',
      9      elment_2  varchar2(20) path 'dmsgo:colorcombination/dmsgo:interiorcolor',
     10      elment_3  varchar2(20) path 'dmsgo:colorcombination/dmsgo:interiorcolor/@manufacturercode'
     11  );
    
    FLUX_NAME            ELMENT_1                                 ELMENT_2             ELMENT_3
    -------------------- ---------------------------------------- -------------------- --------------------
    2120482              E 200 CGI BlueEFFICIENCY Sedan RHD       Leather black        4201
     
    
  • Create the flat file data from the oracle table

    d_adp_num char (10)
    d_schd_date tank (8)
    d_sched_code tank (25)
    d_pay_code char (50)
    d_mil_start char (4)
    d_mil_end char (4)
    d_duration char (5)
    d_site_code char (4)
    d_dept_id tank (6)

    Select payroll_id,
    schedule_date,
    reason_code, (sched_code)
    reason_code, (pay_code)
    start_time,
    end_time,
    total_hours,
    site_code,
    department_id
    of dept_staff
    where schedule_date between (sysdate + 1) and (sysdate + 90)


    loading data for the date range instead.
    sched_code - if 'Unavailable' reason_code = 'OD' and 'THE '.

    pay_code - "Berevevement BD" If reason_code = "BD".
    "UP PTO without reasonable excuse" If reason_code = 'UP '.
    "RG" If reason_code = "SH".
    "PTO" If reason_code = "GO".
    Here are some...

    start_time and end_time - convert military time
    based on start_ampm and end_ampm

    On this basis, I need help to create a flat file. Sewing of the flat and data file in dept_staff sample

    If site_code is there so no need to get department_id (see the sample flat file)
    ------------------------------------

    examples of data to flat file

    ZZW002324006072012 PTO
    0800160008.00
    ZZW002428106072012 RG
    1015174507.50HM34
    ZZW002391606072012 RG
    1100193008.50
    ZZW002430406072012 RG
    1100193008.50 130000
    ----------------------------

    dept_staff table data

    REASON_CODE_1 PAYROLL_ID SCHEDULE_DATE REASON_CODE START_TIME, END_TIME START_AMPM END_AMPM TOTAL_HOURS SITE_CODE DEPARTMENT_ID
    ZZW0024468 08/06/2012 HS HS 730 HAS 400 850 12 P
    ZZW0000199 08/06/2012 HS HS 730 HAS 400 850 14 P
    ZZW0023551 08/06/2012 SH SH 1145 A 930 975 GH08 95 P
    ZZW0024460 08/06/2012 SH SH 515 HAS 330 P 1025 GH08 95
    ZZW0023787 08/06/2012 SH SH 630 HAS 300 850 24 P
    ZZW0024595 08/06/2012 TR TR 730 HAS 400 850 90 P
    ZZW0023516 08/06/2012 OD OD 800 HAS 400 800 95 P
    ZZW0023784 08/06/2012 OD OD 800 HAS 400 800 5 P
    ZZW0024445 08/06/2012 SH SH 1145 A GH08 930 975 5 P
    ZZW0024525 08/06/2012 OD OD 800 HAS 400 800 23 P
    ZZW0024592 08/06/2012 TR TR 730 HAS 400 850 5 P
    ZZW0024509 08/06/2012 SH SH 95 MK21 830 HAS 330 P 700

    ZZW0023916 06/14/2012 SH SH 1100 A 850 27 730 P

    How to ask questions
    SQL and PL/SQL FAQ

    UTL_FILE allows to write the OS file

  • Loading XML into the relational Table data

    Hello

    I get a generated XML file to other tools (Windows), I am trying to create a Linux shell script that will gather the necessary XML file to my Linux server, then ask Oracle to use this file to load the XML data into a relational table. This activity and the data will be needed on an ongoing basis.

    I tried two ways. First, I loaded the XML document into the database and tried to extract the data directly from the document, but it does not work. Now I want to try to read the data directly from the file on the server through select, however I don't get all the returned data. In the Select statement below, I am trying to query the data to see what is returned for my tests.

    Create Table ci_results_table (transactionID Varchar2 (100), //transactionID should be PrimaryKey but became errors in test of insert, PK so deleted NULL value)

    message Varchar2 (200),

    This Varchar2 (50).

    XMLType of the ProcessedDate,

    status Varchar2 (50).

    sourceFile VarChar2 (100));

    Select x.*

    from XMLTable)

    ' TSPLoadResults/results '.

    PASSAGE xmltype (bfilename('CMDB_DEVADHOCRESULTS_DIR','LoadResults-HP_146.results.xml'), nls_charset_id ('AL32UTF8'))

    COLUMNS

    transactionID PATH Varchar2 (100) 'TransactionID '.

    Result XMLType PATH 'result ',.

    Message Varchar2 (200) PATH "Message."

    PrimaryKey Varchar2 (50) PATH "PrimaryKey"

    Date of ProcessedDate path "ProcessedDate."

    Status Varchar2 (50) PATH "Status."

    SourceFile VarChar2 (100) PATH "SourceFileName.

    ) x

    ;

    Eventually, I'll have to build on that to limit the returned data to records where SourceFileName is like '% PA' and insert what is returned in to the ci_results_table. Attached is an example of the XML results file I am trying to load, it is named "ResultsTransformedtoUnix" because I used dos2Unix to convert Unix which can be good or bad. (I send the output file must be converted to the format BACK until the other application can read). Original (before converting Unix) file named in the script is also attached.

    Help, please. Thank you!

    Hello

    I see some bad things in your query.

    (1) obvious one, explaining why you get all the data: there is a typing error in the XQuery expression, there 'result' not'slead.

    (2) ProcessedDate can be extracted as a date (at least not directly) because it actually represents a timestamp, use the TIMESTAMP WITH time ZONE HOURS and cast back to DATE data type in the SELECT clause

    (3) transactionID is an attribute, it must be accessible with ' @' (or ' attribute:' axis)

    (4) if the encoding of file really is ISO-8859-1 as suggested in the prologue, then do not use AL32UTF8 but the name of the corresponding character set: WE8ISO8859P1

    Here is the query to work:

    select x.transactionID
         , x.Message
         , x.Primarykey
         , cast(x.ProcessedDate as date) ProcessDate
         , x.Status
         , x.SourceFile
    from XMLTable(
           '/TSPLoadResults/Result'
           PASSING xmltype(bfilename('XML_DIR','LoadResults-HP_146.results.xml'), nls_charset_id('WE8ISO8859P1'))
           COLUMNS
             transactionID Varchar2(100)            PATH '@transactionID',
             Message       Varchar2(200)            PATH 'Message',
             PrimaryKey    Varchar2(50)             PATH 'PrimaryKey',
             ProcessedDate timestamp with time zone PATH 'ProcessedDate',
             Status        Varchar2(50)             PATH 'Status',
             SourceFile    VarChar2(100)            PATH 'SourceFileName'
         ) x
    ;
    

    Directly on the file using this query will only be decently (for large files) on 11.2.0.4 and beyond.

    On older versions, first load the file into a (temporary) XMLType column with binary XML storage and CHOOSE from there.

    because I used dos2Unix to convert Unix which can be good or bad.

    This conversion should not be necessary.

  • Remove duplicates from the oracle table using 2 columns

    Hello

    I need to remove the duplicates of an oracle table based on 2 columns in the table.i tried to remove duplicates using the join, but get the error like sql error ora-00933

    Thank you

    Hello

    Here's one way:

    DELETE FROM table_x

    WHERE ROWID NOT IN)

    SELECT MIN (ROWID)

    FROM table_x

    Col_1, col_2

    );

    I hope that answers your question.

    If this isn't the case, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.

    In the case of a DML operation (for example, REMOVE) the sample data should show what look like the paintings before the DML, and results will be the content of the or the tables changed after the DML.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

  • Best practices for retrieving a single value from the Oracle Table

    I'm using Oracle Database 11 g Release 11.2.0.3.0.

    I would like to know the best practice to do something like that in a PL/SQL block:

    DECLARE
        v_student_id    student.student_id%TYPE;
    BEGIN
        SELECT  student_id
        INTO    v_student_id
        FROM    student
        WHERE   last_name = 'Smith'
        AND     ROWNUM = 1;
    END;

    Of course, the problem here is that when there is no success, the NO_DATA_FOUND exception is thrown, which interrupts the execution.  So, what happens if I want to continue despite the exception?

    Yes, I could create a block nested with EXCEPTION section, etc, but it seems awkward for what seems to be a very simple task.

    I've also seen this handled like this:

    DECLARE
        v_student_id    student.student_id%TYPE;
        CURSOR c_student_id IS
            SELECT  student_id
            FROM    student
            WHERE   last_name = 'Smith'
            AND     ROWNUM = 1;
    BEGIN
        OPEN c_student_id;
        FETCH c_student_id INTO v_student_id;
        IF c_student_id%NOTFOUND THEN
            DBMS_OUTPUT.PUT_LINE('not found');
        ELSE
            (do stuff)
        END IF;
        CLOSE c_student_id;   
    END;

    But it still seems to kill an Ant with a hammer.

    What is the best way?

    Thanks for any help you can give.

    Wayne

    201cbc0d-57b2-483a-89f5-cd8043d0c04b wrote:

    What happens if I want to continue despite the exception?

    It depends on what you want to do.

    You expect only 0 or 1 rank. SELECT INTO waiting for exactly 1 row. In this case, SELECT INTO may not be the best solution.

    What exactly do you do if you return 0 rows?

    If you want to set a variable with a NULL value and continue the treatment, Frank's response looks good, or else use the modular Billy approach.

    If you want to "do things" when you get a line and 'status quo' when you don't get a line, then you can consider a loop FOR:

    declare
      l_empno scott.emp.empno%type := 7789;
      l_ename scott.emp.ename%type;
    begin
      for rec in (
        select ename from scott.emp
        where empno = l_empno
        and rownum = 1
      ) loop
    l_ename := rec.ename;
        dbms_output.put_line('<' || l_ename || '>');
      end loop;
    end;
    /
    

    Note that when no line is found, there is no output at all.

    Post edited by: StewAshton - Oops! I forgot to put the result in l_ename...

  • Load the XML of the DB table

    Hello world

    I have a urgent need of loading XML from the Oracle table... pls let me know how to achieve this.

    I know that the overthrow of the same thing but impossible to continue any further with this req

    (ODI: 11.1.1.5, operating system: Solaris, DB: Oracle 11 g)

    Kind regards

    M

    Its resolved, use sqlunloader.

    I saw these videos Chantal, thanks for your help

  • XML from the master-child tables

    Hello

    Just post here again for a quick response.

    XML from the master-child tables


    Best regards
    Hari

    Hello

    Using SQL/XML functions is the way to go in this case.

    SQL> select xmlroot(
      2           xmlelement("ROWSET",
      3             xmlagg(
      4               xmlelement("MASTER",
      5                 xmlforest(tm.master_id, tm.master_name, tm.master_location),
      6                   (
      7                    select xmlagg(
      8                             xmlelement("CHILD",
      9                               xmlforest(tc.child_id, tc.child_name, tc.child_location)
     10                             ) order by tc.child_id
     11                           )
     12                    from t_child tc
     13                    where tc.master_id = tm.master_id
     14                   )
     15               ) order by tm.master_id
     16             )
     17           )
     18         , version '1.0')
     19  from t_master tm
     20  where tm.master_id = 1
     21  ;
    
    XMLROOT(XMLELEMENT("ROWSET",XM
    --------------------------------------------------------------------------------
    
    
      
        1
        master name
        master location
        
          1
          child name 1
          child location 1
        
        
          2
          child name 2
          child location 2
        
        
          3
          child name 3
          child location 3
        
      
    
     
    

    Note that the first XMLAgg is optional here, since you want just a MASTER at a time.
    But if you need an XML document containing several masters, he will work as well.

    Alternatively, you can write a similar query with a GROUP BY clause (no correlated subquery, but a join between the master and the child instead):

    select xmlroot(
             xmlelement("ROWSET",
               xmlagg(
                 xmlelement("MASTER",
                   xmlforest(tm.master_id, tm.master_name, tm.master_location),
                     xmlagg(
                       xmlelement("CHILD",
                         xmlforest(tc.child_id, tc.child_name, tc.child_location)
                       ) order by tc.child_id
                     )
                 ) order by tm.master_id
               )
             )
           , version '1.0'
           )
    from t_master tm
         join t_child tc on tc.master_id = tm.master_id
    where tm.master_id = 1
    group by tm.master_id, tm.master_name, tm.master_location
    ;
    

    Published by: odie_63 on June 15, 2011 15:06

  • Select values from the db1 table and insert into the DB2 table

    Hello

    I have three databases oracle running in three different machines. their ip address is different. among the DB can access databases. (means am able to select values and insert values into tables individually.)

    I need to extract data from the DB1 table (ip say DB1 is 10.10.10.10 and the user is DB1user and the table is DB1user_table) and insert the values into DB2 table (say ip DB2 is 11.11.11.11 and the user is DB2user and table DB2user_table) of DB3 that is to have access to the two IPs DB.

    How do I do this

    Edited by: Aemunathan on February 10, 2010 23:12

    Depending on the amount of data must be moved between DB1 and DB2, and the frequency at which this should happen, you might consider the SQL * COPY more control. I think it's very useful for one-off tasks little, so I can live within its limits of the data type. More http://download.oracle.com/docs/cd/E11882_01/server.112/e10823/apb.htm#i641251.

    Change some parameter of sqlplus session are almost mandatory in order to get decent transfer rates. Tuning ARRAYSIZE and COPYCOMMIT can make a huge difference in flow. LONG change may be necessary, too, depending on your data. The documentation offers these notes on use:

    To activate the copy of data between Oracle and databases non-Oracle, NUMBER of columns is replaced by DECIMAL columns in the destination table. Therefore, if you are copying between Oracle databases, a NUMBER column with no precision will become a DECIMAL column (38). When copying between Oracle databases, you must use SQL commands (CREATE TABLE AS and INSERTION), or you must make sure that your columns have a specified precision.

    SQL * the VALUE LONGER variable limits the length of the LONG column you are copying. If all LONG columns contain data exceeds the value of LONG, COPY truncates the data.

    SQL * Plus performs a validation at the end of each successful COPY. If you set the SQL * variable more COPYCOMMIT DEFINED to a value positive n, SQL * Plus performs a validation after copying all lots n of records. The SQL * Plus ARRAYSIZE variable SET determines the size of a batch.

    Some operating environments require that the service names be placed between double quotes.

    From a SQL * Plus term on DB3, can resemble the command to move all content from my_table in DB1 to the same table in DB2

    COPY from user1/pass1@DB1 to user2/pass2@DB2 -
    INSERT INTO my_table -
    USING select * from my_table
    

    Note the SQL code * more line-continuation character ' - '. It is used to escape the newline character in a SQL * Plus command if you do not have to type all on one line. I use it all the time with this command, but I can't locate the documentation on that right now. Maybe someone else can put their finger on it.

    There are other ways to accomplish what the command copy and it is not without its quirks and limitations, but I find that there is usefulness in an Oracle Toolbox.

  • ORA-22992: cannot use LOB Locators selected from the remote tables...

    Oracle 10.2.1.0.4
    Solaris 10

    We try to access a table in another database via a db_link.

    The table we are trying to access has a LOB.

    We get the following error: ora-22992: cannot use LOB Locators selected from the remote tables.

    Is there a way to get around this? We need the data in the BLOB field.

    Thank you.

    See on metalink:

    ORA-22992 has a workaround solution in 10 gr 2
    DOC - ID: 436707.1

    Werner

  • ODI - read CSV file and write to the Oracle table

    Hello world

    After 4 years, I started to work again with ODI, and I'm completely lost.

    I need help, I don't know what to use for each step, interfaces, variables, procedures...

    What I have to do is the following:

    (1) reading a CSV file-> I have the topologies and the model defined

    (2) assess whether there is a field of this CSV file in TABLE A-> who do not exist in the table is ignored (I tried with an interface joining the csv with the TABLE model a model and recording the result in a temporary data store)

    Evaluate 3) I need to update TABLE C and if not I need to INSERT if another field that CSV exists in TABLE B-> if there

    Could someone help me with what use?

    Thanks in advance

    Hi how are you?

    You must:

    Create an interface with the CSV template in the source and a RDBM table in the target (I'll assume you are using Oracle). Any type of filter or the transformation must be defined to be run in the stadium. (you must use a LKM for SQL file and add an IKM Sql control (it is best to trim them and insert the data when it cames to a file if you want after this process, you may have an incremental update to maintain history or something like that).)

    For validation, you will use a reference constraints in the model of the oracle table: (for this you need a CKM Oracle to check constraints)

    Then, you must select the table that you sponsor and in the column, you choose which column you will match.

    To article 3, you repeat the above process.

    And that's all. Pretty easy. If you do not have the two tables that you need to use your validation that you need to load before loading the CSV file you need valid.

    Hope this can help you

  • Delete triggers in DAC to the Oracle apps data source

    Hey guys,.

    We use OLIVIER 7.9.6.1 and OBIEE 10.1.3.4.0. data source is Oracle apps 11.5.9.

    We had a problem in the report. drillthrough report 6 records where as source has only 4 records. Looks like 2 deleted source records and we have never implemented here delete triggers. I'm new to this project and don't know how to implement for the Oracle apps data source delete triggers. because there is no concept of picture table in oracle apps.

    I tried a full load of the fact table, and it is fetching 4 records as expected. so please tell me how to apply delete triggers for the oracle apps data source. explain the process step by step.

    Thank you for your help.

    Thank you
    Jay.

    You can follow the same EP and remove the mapping process that are out of the box for your custom tables. Make sure you include a DELETE_FLG on the custom tables and follows the same logic of PE and Delete is used in vanilla maps. You must have a primary key to check the records of if.which have been removed. Once you have the full mappings, you can set the DAC to assocaiated tasks and include them with your execution plans. As Oracle has followed this process, its best to stay w the same strategy.

Maybe you are looking for