extraction of XMLType column value

Hi team,

Am new on querying XML and would like to ask for your help on the underside.

I have a Table - DEQUEUE_3_OUT

DESC DEQUEUE_3_OUT

Name of Type Null

------- ---- ---------

XML_MSG XMLTYPE()

Now my Table has a record participation in the XML below-

" < ROW_LCR xmlns =" http://xmlns.Oracle.com/streams/schemas/LCR "" xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance " xsi: schemaLocation = " http://xmlns.Oracle.com/Streams/schemas/LCR http://xmlns.oracle.com/streams/schemas/lcr/streamslcr.xsd" > ""

< source_database_name > ORCL. ST - IDC. IDC. ORACLE.COM < / source_database_name >

updated < command_type > < / command_type >

< proprietaire_objet > XYZABC < / proprietaire_objet >

< object_name > NOTIFY_TABLE < / object_name >

< transaction_id > 4.23.3135 < / transaction_id >

< SNA > 4727635 < / SNA >

< old_values >

< old_value >

< nom_de_colonne > NOTIFICATION_ID < / nom_de_colonne >

< data >

< varchar2 > 6 < / varchar2 >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > NOTIFICATION_TYPE < / nom_de_colonne >

< data >

< varchar2 > 2 ERROR < / varchar2 >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > SOURCE_SYSTEM < / nom_de_colonne >

< data >

GFIPRD < varchar2 > < / varchar2 >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > POINT < / nom_de_colonne >

< data >

DNB < varchar2 > < / varchar2 >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > ERROR_SOURCE < / nom_de_colonne >

< data >

MULTIPLE_MATCHES_LOC < varchar2 > < / varchar2 >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > BATCH_ID < / nom_de_colonne >

< data >

< number > 3 < / number >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > BATCH_DESC < / nom_de_colonne >

< data >

GFIPRD < varchar2 > < / varchar2 >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > ASSIGNED_TO < / nom_de_colonne >

< data >

OLD_USER < varchar2 > < / varchar2 >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > PRIORITY < / nom_de_colonne >

< data >

< number > 3 < / number >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > STATUS_CODE < / nom_de_colonne >

< data >

< varchar2 > NEW < / varchar2 >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > ESCALATION_REQD < / nom_de_colonne >

< data >

< varchar2 xsi: Nil = "true" / >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > ESCALATION_LEVEL < / nom_de_colonne >

< data >

< number xsi: Nil = "true" / >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > NEED_ENRICH_DATA < / nom_de_colonne >

< data >

Y < varchar2 > < / varchar2 >

< / data >

< / old_value >

< old_value >

COMMENTS from < nom_de_colonne > < / nom_de_colonne >

< data >

< varchar2 xsi: Nil = "true" / >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > CREATED_BY < / nom_de_colonne >

< data >

< varchar2 xsi: Nil = "true" / >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > CREATION_DATE < / nom_de_colonne >

< data >

< timestamp >

< value / >

<>SYYYY/MM/DD HH24:MI:SSXFF9 format < / size >

< / timestamp >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > LAST_UPDATED_BY < / nom_de_colonne >

< data >

< varchar2 xsi: Nil = "true" / >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > LAST_UPDATE_DATE < / nom_de_colonne >

< data >

< timestamp >

< value / >

<>SYYYY/MM/DD HH24:MI:SSXFF9 format < / size >

< / timestamp >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > EMAIL_FLAG < / nom_de_colonne >

< data >

< varchar2 xsi: Nil = "true" / >

< / data >

< / old_value >

< old_value >

< nom_de_colonne > CREATED_BY_MODULE < / nom_de_colonne >

< data >

< varchar2 xsi: Nil = "true" / >

< / data >

< / old_value >

< / old_values >

< new_values >

< new_value >

< nom_de_colonne > ASSIGNED_TO < / nom_de_colonne >

< data >

NEW_USER < varchar2 > < / varchar2 >

< / data >

< / new_value >

< / new_values >

< / ROW_LCR >

I need to ask in such a way that I need the below output

Column name Old_Value new_value

--------------------              --------------            ---------------

NOTIFICATION_ID 6 NULL

ASSIGNED_TO OLD_USER NEW_USER

Thanks in advance.

You probably want to use a FULL OUTER JOIN in this case:

SQL > with old_values like)

2 select x.column_name, x.old_value

dequeue_3_out 3 t

4, xmltable)

5 xmlnamespaces (default 'http://xmlns.oracle.com/streams/schemas/lcr')

6, ' for $old in/ROW_LCR/old_values/old_value

7. let $val: = $old / data / *.

8 return element {} r

$old 9/column_name

10, element old_value {}

11 typeswitch ($val)

12 element (timestamp) case return $val / value

back 13 by default $val

14              }

15            }'

16 passage t.xml_msg

path of varchar2 (30) 17 column column-name 'column_name '.

18 road of varchar2 (4000) old_value "old_value".

(19) x

(20),

21 new_values as)

22 select x.column_name, x.new_value

dequeue_3_out 23 t

24, xmltable)

25 xmlnamespaces (default 'http://xmlns.oracle.com/streams/schemas/lcr')

26, ' for $new in/ROW_LCR/new_values/new_value

27 let $val: = $ new / data / *.

28 return element {} r

$29 new/column_name

30, item new_value by {}

31 typeswitch ($val)

32 element (timestamp) case return $val / value

return default 33 $val

34             }

35           }'

36 passage t.xml_msg

path of varchar2 (30) 37 column column_name 'column_name '.

38, new_value varchar2 (4000) path 'new_value '.

(39) x

40)

41 select column_name nvl (old.column_name, new.column_name)

42, old.old_value

43, new.new_value

44 of old_values old outer join complete new new_values

45 on old.column_name = new.column_name

46;

COLUMN_NAME OLD_VALUE NEW_VALUE

------------------------------ ---------------------- -----------

ASSIGNED_TO OLD_USER NEW_USER

NEED_ENRICH_DATA Y

STAGE DNB

ESCALATION_LEVEL

BATCH_DESC GFIPRD

LAST_UPDATED_BY

ESCALATION_REQD

STATUS_CODE NEW

SOURCE_SYSTEM GFIPRD

EMAIL_FLAG

NOTIFICATION_TYPE ERROR 2

CREATED_BY_MODULE

COMMENTS

LAST_UPDATE_DATE

CREATION_DATE

NOTIFICATION_ID 6

PRIORITY 3

BATCH_ID 3

CREATED_BY

ERROR_SOURCE MULTIPLE_MATCHES_LOC

20 selected lines

Tags: Oracle Development

Similar Questions

  • problems with selection of XMLType column value

    I want to extract my XMLType column values. Can someone tell me why this works
    select XMLCAST
              (
                XMLQUERY
                (
                   'declare default element namespace  "urn:hl7-org:v3"; (: :)
                    declare namespace voc = "urn:hl7-org:v3/voc"; (: :)
                    $doc/ClinicalDocument/recordTarget/patientRole/patient/name/family'
                    passing CCD_DOC as "doc"
                    returning content
                )
                as VARCHAR2(4000)
              )
         from CCD
    but it does not work?
    select
        ccdid,
        extractvalue(CCD_DOC,'/recordTarget/patientRole/patient/name/given') "given",
        extractvalue(CCD_DOC,'/recordTarget/patientRole/patient/name/family') "family",
        extractvalue(CCD_DOC,'/recordTarget/patientRole/providerOranization/name') "name",
        extractvalue(CCD_DOC, 'title') as Title
    from CCD
    where ClinicalDocument is the root element?

    I don't get any errors on the other, but the three XML derived columns are null. The values are not retrieved while the values ARE retrieved using the first method.

    Thank you!

    XMLTable...

    select x.*
      from CCD,
           XMLTable
           (
             xmlNamespaces
             (
               default 'urn:hl7-org:v3',
               'urn:hl7-org:v3/voc' as "voc"
             ),
             '$doc/ClinicalDocument/recordTarget/patientRole'
             passing CCD_DOD as "doc"
             columns
             given varchar2(128) path 'patient/name/given',
             family varchar2(128) path 'patient/name/family',
             name varchar2(128) path 'providerOranization/name'
           ) x
    
  • Questions to extract the XMLtype column attributes

    I cannot retrieve the values of a column of the XML data type. There are 16 fields and when I try to extract the data the XML snippet is that each of them in 1 great return value. I have tried everything but the problem seems to be that the domain name is an attribute and everything I try fails. I appreciate any help in advance and I'm extremely new XML so please let me know if you need more information.

    With the help of Oracle 11.2.0.2 Express

    -Created table that has a column of XMLTYPE OF CLOB
    CREATE THE TABLE HR. XMLTABLESTORE (key_id VARCHAR2 (10) PRIMARY KEY, xmlloaddate date, xml_column XMLTYPE) AS CLOB XmlType xml_column STORE;

    -Insert the XML code in the column
    INSERT INTO HUMAN RESOURCES. VALUES XMLTABLESTORE (HR. XMLSEQUENCE. NEXTVAL, SYSDATE, XMLType (bfilename ('XMLDIRX', 'PROD_20110725_211550427_220b.xml'),
    nls_charset_id ('AL32UTF8')));

    I managed to get the values for

    SELECT extract (xml_column, ' / / MapItem/@ProductNum "") ProductNum go OF HR. XMLTABLESTORE

    '63481062975'

    Vain, get the data under the domain name, as it is to return all names or values

    SELECT extract (xml_column, ' / / MapItem/Field/@Name "") OF HR. XMLTABLESTORE

    'lowDispUnitsPerPackdosageFormmedicaidUnitTypemedicareUnitTypemedicareUnitsPerPackunitConversiontypeunitMeasurepricingUnitMeasurelabelerCodeproductNumdescriptionlongDescriptiondesiIndicatorgenericBrandTypeendoOrgCode'

    How can I return a row of data both for the name and value?

    <? XML version = "1.0"? > < entries >
    < ProductNum category = NDC "634810629" = "634810629" Name = "634810629" Ndc9Flag = "true" >
    < = field name "type" Type = "java.lang.String" Value = "Category" / > "
    < name of field = "productNum" Type = "java.lang.String" Value = "634810629" / > "
    "" "< MapItem ProductNum = NDC"63481062975"="63481062975"Ndc9Flag ="false"name ="PERCOCET 10/325 MG x 100 UD' status = "0" Description ="PERCOCET 10/325 MG x 100 UD ' MedicaidUnitsPerPack ="100.0"MarketEntryDate ="2001-11-23 00:00:00 "FirstSalesDate =" 2001-11-23 00:00:00 "fdaApprovalDate ="2001-11-23"fdaRegName ="000000006348162975"ManuTermDate ="2003-09-30 00:00:00 "ShelfLifeExpDate =" 2003-09-30 00:00:00 "drugType ="Rx"DrugCategory =" N"TheraCode ="NR"EligibleForVA ="false"EligibleForPHS ="false"EligibleForASP ="false"EligibleForMedicaid ="true"NonCmtyPharmaDrug ="false">"
    * < name of field = "lowDispUnitsPerPack" Type = "java.lang.String" Value = "1000" / > * "
    * < name of field = 'dosageForm"Type =" java.lang.String"Value = 'TAB' / > *"
    * < name of field = "medicaidUnitType" Type = "java.lang.String" Value = 'TAB' / > * "
    * < name of field = "medicareUnitType" Type = "java.lang.String" Value = 'TAB' / > * "
    * < name of field = "medicareUnitsPerPack" Type = "java.lang.String" Value = "100.0" / > * "
    * < name of field = "unitConversion" Type = "java.lang.String" Value = "1" / > * "
    * < = field name "type" Type = "java.lang.String" Value = "Item" / > * "
    * < name of field = 'unitMeasure' Type = "java.lang.String" Value = "EA" / > * "
    * < name of field = "pricingUnitMeasure" Type = "java.lang.String" Value = "EA" / > * "
    * < name of field = "labelerCode" Type = "java.lang.String" Value = "63481" / > * "
    * < name of field = "productNum" Type = "java.lang.String" Value = "63481062975" / > * "
    * < field name = "description" Type = "java.lang.String" Value ="PERCOCET 10/325 MG x 100 UD" / > * "
    * < field name = "longDescription" Type = "java.lang.String" Value ="PERCOCET 10/325 MG x 100 UD" / > * "
    * < name of field = "desiIndicator" Type = "com.modeln.bp.catalog.CMnDesiDrugIndicator" Value = "2" / > * "
    * < name of field = "genericBrandType" Type = "com.modeln.bp.struct.contract.enums.CMnGenericBrandItemType" Value = "BRND" / > * "
    * < name of field = "endoOrgCode" Type = "java.lang.String" Value = "0010" / > * "
    < / MapItem >
    < / category >
    < / input >

    Thank you
    Shawn

    You can get a picture with lines like ['name', 'value']

    with t as
    (select xmltype('
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ') xml from dual)
    
    select  x.name, x.value
    from t
        ,xmltable('/Entries/Category/MapItem/Field'
                  passing t.xml
                  columns name varchar2(20) path '@Name',
                   value varchar2(20) path '@Value'
                 ) x 
    
    NAME                 VALUE
    -------------------- --------------------
    lowDispUnitsPerPack  1.000
    dosageForm           TAB
    medicaidUnitType     TAB
    medicareUnitType     TAB
    medicareUnitsPerPack 100.0
    unitConversion       1
    type                 Item
    unitMeasure          EA
    pricingUnitMeasure   EA
    labelerCode          63481
    productNum           63481062975
    description          PERCOCET 10/325MG x
    longDescription      PERCOCET 10/325MG x
    desiIndicator        2
    genericBrandType     BRND
    endoOrgCode          0010                 
    
    16 rows selected           
    
  • extraction of xmltype and excluding all the tags of the namespace?

    Hi all
    I am trying to extract the xmltype column in another xmltype column in another table.

    Select xt.attachment_content, xt.attachment_type, xt.attachment_format
    OF document_version dva.
    XMLTABLE)
    XMLNamespaces ('http://oracle.com/test1/1.0'),
    "AttachmentList/attachment.

    PASSAGE document_content
    COLUMNS
    attachment_content path of xmltype "content."
    path of varchar2 (100) to attachment_type 'type,'
    XT attachment_format varchar2 (100) path 'format')

    This query returns results, BUT the content has tags and namespaces in the game too. I just want to return the content than ANY version of xml without xmlns: (xmlnamespaces) and etc.

    Please help me how to do this.

    OK, thanks for the effort, however, this is not a test case from work, by far...

    The input XML is not valid because you probably just copied the version without escape sequence and paste here.
    The cuts you made in the XML load make invalid too.

    The query is not true either, syntax XMLNamespaces is bad, but also the XPath expression.

    I understand that you want to present a simplified scenario based on but you are in fact wasting time by not giving something that we can run.

    Now, if I have a query document_attachments table content column displays the results, but with all the tags of the namespace and etc.

    As said, I doubt that the request you give will never recover anything, but that is a different problem.

    What I would like to know because my first answer is why namespaces are a problem for you? They are part of the document and it is easy to deal with them once we know how to do it.

    For example, this retrieve the value of the content as CLOB (plain text) and convert on the fly of XMLType:

    INSERT INTO document_attachments (doc_id, content, type, format)
    SELECT dva.doc_id
         , xmlparse(document xt.attachment_content) as content
         , xt.attachment_type as type
         , xt.attachment_format as format
    FROM document_version dva
       , XMLTable (
           XMLNamespaces(default 'http://optimal.com/SP/2/RandPCommon/DocumentStore/GatewayRequestStore/1.0')
         , 'AttachmentList/attachment'
           PASSING document_content
           COLUMNS
             attachment_content clob          path 'content'
           , attachment_type    varchar2(100) path 'type'
           , attachment_format  varchar2(100) path 'format'
         ) xt
    ;
    

    Now, the contents column is:

    
    
     
    6 6
    /1/2/28/8 /SSRF/Body/Location[@serial='USA:AF:LT:4341b33adc0442a']/Address[1]/@country Brownsville U TX /1/2/27/8 /SSRF/Body/Location[@serial='USA:AF:LT:7c5c3cef2cf74ef']/Address[1]/@country Brownsville U There is no successfully completed Engineering Analysis attached to this proposal. Please run an an There is no successfully completed Engineering Analysis attached to this proposal. Please run an analysis or provide a detailed justification for omitting it. Prepare & Submit Workflow Rules test

    Is this OK so far?

    What do you do next with the content column?
    Yet once there is no need to remove any namespace, or if he really exists, please explain what requirement business dictates who and how the attachment must be treated thereafter.

    Published by: odie_63 on May 26, 2012 19:07

  • Inserting XML data in xmltype column

    Oracle version: 10.1.0.5
    OpenVms Alpha V8.3

    (1) tried this and getting the error below. Place a zero and remove charset. Same mistake.

    INSERT INTO xml_demo (donnees_xml) - xmltype column
    VALUES
    (
    XmlType
    (
    BFILENAME ('XML_DIR ',' MOL.) XML').
    nls_charset_id ('AL32UTF8')
    ),
    );


    ORA-22993: much of the specified input is greater than the quantity real source
    ORA-06512: at "SYS." DBMS_LOB", line 637
    ORA-06512: at "SYS." XMLTYPE", line 283
    ORA-06512: at line 1


    (2) this PL/SQL block works. However maximum brute size about 32K. The file may be around 100 K. May be I can load into a table of raw and somehow concatnate to insert. Not sure if it's possible, but I'm sure there must me a simple way to do this.

    Subset of the xml file is pasted below.


    Set serveroutput size 1000000
    DECLARE
    bfile file1;
    XMLType v_xml;
    len1 number (6);
    v_rec1 raw (32000);

    BEGIN
    File1: = bfilename ('XML_DIR ',' MOL.) XML');
    DBMS_LOB. FileOpen (File1, DBMS_LOB.file_readonly);
    len1: = DBMS_LOB.getLength (file1);
    v_rec1: = dbms_lob.substr(file1,len1,1);
    v_xml: = xmltype (UTL_RAW. CAST_TO_VARCHAR2 (v_rec1));

    INSERT INTO xml_demo (donnees_xml) VALUES (v_xml);
    COMMIT;
    DBMS_LOB. FileClose (file1);

    exception
    while others then
    dbms_output.put_LINE (sqlerrm);
    DBMS_LOB. FileClose (file1);
    END;
    /




    <? XML version = "1.0" encoding = "UTF-8"? >
    < MolDocument DtdVersion = "3" DtdRelease = "0" >
    < DocumentIdentification v = "MOL_20100331_1500_1600" / >
    < DocumentVersion v = "1" / >
    < V DocumentType = "A43" / >
    < CodingScheme = v "A01" SenderIdentification = "17X100Z100Z0001H" / >
    < SenderRole v = "35" / >
    < ReceiverIdentification codingScheme = v "A01" = "10XFR-TEN - Q" / >
    < ReceiverRole v = "A04" / >
    < CreationDateTime v = "2010-03 - 31 T 14: 10:00Z" / >
    < ValidTimeInterval v = "2010-03 - 31 T 15: 00Z / 2010-03 - 31 T 16: 00Z" / >
    < codingScheme domain = "A01" v = "10YDOM-1001A001A" / >
    < MolTimeSeries >
    < ContractIdentification v = "RTE_20100331_1500_16" / >
    < ResourceProvider codingScheme = v "A01" = "10XFR-TEN - Q" / >
    < CodingScheme = v "A01" AcquiringArea = "17Y100Z100Z00013" / >
    < ConnectingArea codingScheme = v "A01" = "10YFR-TEN - C" / >
    < AuctionIdentification v = "AUCTION_20100331_1500_1600" / >
    < BusinessType v = "10" / >
    < BidTimeInterval v = "2010-03 - 31 T 15: 00Z / 2010-03 - 31 T 16: 00Z" / >
    < MeasureUnitQuantity v = "MAW" / >
    < v currency = "EUR" / >
    < MeasureUnitPrice v = "MWH" / >
    < v direction = "A02" / >
    < MinimumActivationQuantity v = "50" / >
    < v status = "A06" / >
    < period >
    < v TimeInterval = "2010-03 - 31 T 15: 00Z / 2010-03 - 31 T 16: 00Z" / >
    < resolution v = "PT60M" / >
    <>interval
    < v pos = "1" / >
    < v Qty = "50" / >
    < character v = "50.45" / >
    < / interval >
    < / period >
    < / MolTimeSeries >
    < / MolDocument >

    Hello

    A couple of workarounds, try:

    DECLARE
    
       v_lob   CLOB;
       v_file  BFILE;
    
    BEGIN
    
       v_file := BFILENAME('XML_DIR','mol.xml');
       DBMS_LOB.createtemporary(v_lob, true);
       DBMS_LOB.fileopen(v_file);
       DBMS_LOB.loadfromfile(v_lob, v_file, DBMS_LOB.getlength(v_file));
    
       INSERT INTO xml_demo VALUES( xmltype(v_lob) );
    
       DBMS_LOB.fileclose(v_file);
       DBMS_LOB.freetemporary(v_lob);
    
    END;
    /
    

    or,

    DECLARE
    
       v_lob   CLOB;
    
    BEGIN
    
       v_lob := DBMS_XSLPROCESSOR.read2clob('XML_DIR', 'mol.xml', nls_charset_id('AL32UTF8'));
    
       INSERT INTO xml_demo VALUES( xmltype(v_lob) );
    
    END;
    /
    
  • How to extract a string from a varchar column value

    Hello
    I have a varchar2 column that got the xml data. I want to extract the value of a tag < test > < / test >

    I can't use EXTRACT because the column is not XMLTYPE.

    Please suggest.

    Insert first only the first two columns:

    INSERT INTO TESTXML (id,name) VALUES(1, 'ABCDEFTEST');
    INSERT INTO TESTXML (id,name) VALUES(2, 'XYZUVWTEST');
    INSERT INTO TESTXML (id,name) VALUES(2, 'XYZUVWTES');
    

    Make this update:

    update testxml set temp=rtrim(ltrim(regexp_substr(name,'(.*?)'),''),'');
    

    Edited by: hartmutm the 01.10.2010 05:13

  • [11g] ORA-22993 when extracted xmltype great values in the outbreak of the BIU as a CLOB in another table

    [I ask nicely for a few comments for this question.

    Someone else can reproduce it with the test below?

    Is my code invalid or false?

    Or what is the problem here?

    -Thank you

    Frank

    ]

    Hello

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    CORE Production 11.2.0.3.0

    AMT for Linux: Version 11.2.0.3.0 - Production

    NLSRTL Version 11.2.0.3.0 - Production

    Trigger Before Insert or Update to a table, I invoke a PL/SQL package function to check the size of an xmltype column (passing as IN OUT NOCOPY).

    PL/SQL functions retrieves the xmltype. GetClobVal(), check its size, and when it is beyond a limit, he tries to insert the data into another table (GTT - global temporary table).

    Finally, it changes the value of the value of the column of xmltype to the shorter XML (just by referring to the corresponding record in the TWG).

    But the Insert SQL in the TWG operation strike ORA-22993: specified input is greater than the amount actual source.

    I don't know why this happens. In the internet I only find references on importing files in lob/clob.

    Anyone have the same problem?

    I know that you prefer to have a sample program to demonstrate the problem - I'll try to post one, but it will take time.

    But maybe someone can help me based on the information above already.

    -Thanks a lot!

    Best regards

    Frank

    I have reproduced the issue.

    It must be a bug.

  • How to extract the values of column aliases based on different column values?

    Hello gurus,

    I have a table with the following struture-
    "drop table T;
    create table T(Name, Symbol, Amount,dep) as select
    'Anderia', 'AA', 1050000,'HR' from dual union all select
    'Michael', 'ML',150000,'Sales' from DUAL union all select
    'Bill', 'BL', 1050000,'Finance' from dual union all select
    'Nancy', 'NY', 4000,'HR' from DUAL union all select
    'Anderia', 'AA',3000,'HR' from dual union all select
    'Michael', 'ML',1050000,'Sales' from DUAL union all select
    'Bill', 'BL', 1200000,'Finance' from DUAL union all select
    'Anderia', 'AA', 1200000,'HR' from DUAL union all select
    'Vish', 'VH', 1200000,'Marketing' from DUAL;"
    And try to find the values of the column as
    Name, symbol, dep, amount, % Total, Total $Cumm, rank but some additional as-columns

    Amount HR, % HRTotal, $HR Cumm Total,
    Finance amount, FinanceTotal %, $Finance Cumm Total
    Sales amount, a percentage of Total sales, $Sales Cumm Total.
    Amount marketing, MarketingTotal %, $Marketing Cumm Total

    then I use the following query to retrieve the name, the symbol, the dep, amount, % Total, Total $Cumm, rank columns.
    select name
         , decode(grouping(symbol), 0, symbol, 'Total') symbol
         , dep
         , sum(amount) amount
         , sum(per_total) "% Total"
         , decode(grouping(symbol), 0, max(Cum_per_total), null) "% Cumm Total"
         , decode(grouping(symbol), 0, max(rank), null) rank
      from (
              select name
                   , symbol
                , dep
                   , amount
                   , per_total 
                   , sum(per_total) over(order by rk) cum_per_total
                   , rank
                   , rk
                from (     
                        select name
                             , symbol
                    , dep
                             , sum(amount) amount
                             , round((sum(amount)/max(total_amount)) * 100,2) per_total
                             , dense_rank () over (order by sum(amount) desc) as rank
                             , row_number() over(order by sum(amount) desc) as rk
                          from (
                                 select name
                                      , symbol
                                      , amount
                          , dep
                                      , sum(amount) over() total_amount 
                                      , sum(amount) over () 
                                   from t
                               )
                         group 
                            by name, symbol, dep
                    )
            )
      group         
         by grouping sets((name, symbol, dep), ())
      order by rank, max(rk) nulls last
    But I want to extract the following columns so... How can I do?

    Amount HR, % HRTotal, $HR Cumm Total,
    Finance amount, FinanceTotal %, $Finance Cumm Total
    Sales amount, a percentage of Total sales, $Sales Cumm Total.
    Amount marketing, MarketingTotal %, $Marketing Cumm Total


    as I want that all records, then will the dep..do-specific I need to use the case here?
    Thanks for all your time and effort in advance

    If I understand your needs, you need pivot: SQL and PL/SQL FAQ

  • Compare the values of the XMLType column to two different lines using XMLDiff in GR 11, 2

    I have a table of data with a row of XMLType and I need a way to compare the XML data against the other. I guess I could use a function and return a XMLDIFF base output to the caller, but the function logic is a bit fuzzy. Would be nice to format the output finally in a table format.

    I looked on http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions241.htm#SQLRF20025 and output in a format of table as shown in Re: how to find compare and identify between xmldocs .

    I ran across some examples do not explain the best way to compare the XML code that is in the best performing XMLType column.

    Any help would be appreciated.

    Are you referring to different rows in the same table or different tables or?

    Basically, you need to change the example of Odie so that the XMLDiff retrieves the XML from places in Pb, say something like

    XMLDIFF(SELECT aXml FROM table WHERE ...,
            SELECT bXml FROM table WHERE ...)
    

    This allows to avoid bringing the XML of the DB in the client code.

    Don't know if that's what you're looking for, but hopefully it helps a little.

  • Add to the XMLTYPE column

    Hello

    I have a requirement to insert a new XML tag in the existing XMLTYPE column.

    Oracle version: Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    create table rds_xml_config (module_name varchar2 (32), module_type varchar2 (100), config_xml xmltype);

    insert into rds_xml_config values ('TRANSMIT_SEQ', 'INTERFACE',' < transmit_seq > <!-file sequence number will be updated after each race-> < file = "RTP" Type_de_fichier > < file_seq_num > 2457 < / file_seq_num > < / file > < file Type_de_fichier = 'RTS' > < file_seq_num > 2453 < / file_seq_num > < / file > < Type_de_fichier = "RTL" file > < file_seq_num >) 2522 < / file_seq_num > < / file > < / transmit_seq > ');

    I have to add < file = "RTX" Type_de_fichier > < file_seq_num > 0 < / file_seq_num > < / file >.

    As a temporary work around, I used below the update statement.

    Update rds_xml_config

    Set config_xml =' < transmit_seq > <!-file sequence number will be updated after each race-> < file = "RTP" Type_de_fichier > < file_seq_num > 2457 < / file_seq_num > < / file > < file Type_de_fichier = 'RTS' > < file_seq_num > 2453 < / file_seq_num > < / file > < Type_de_fichier = "RTL" file > < file_seq_num > 2522 < / file_seq_num > < / file > < file = "RTX" file_type > < file_seq_num > 0 < / file_seq_num > < / file > < / transmit_seq > '

    WHERE module_type = "INTERFACE".

    AND module_name = "TRANSMIT_SEQ";

    SEQ numbers will be modified for each race of the file, so I cannot use the work temporary around during migration to production, have we a way to add new XMLtag.

    Thank you

    Rambeau

    Search in INSERTCHILDXML

    http://docs.Oracle.com/CD/B19306_01/server.102/b14200/functions066.htm

    SQL> select a.config_xml.extract('*') old_xml
      2       , insertchildxml(config_xml, '/transmit_seq', 'file',xmltype('10000')).extract('*') new_xml
      3    from rds_xml_config a;
    
    OLD_XML                                                                                              NEW_XML
    ---------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------
                                                                                           
                                                 
                                                                                     
        2457                                                                 2457
                                                                                                    
                                                                                     
        2453                                                                 2453
                                                                                                    
                                                                                     
        2522                                                                 2522
                                                                                                    
                                                                                            
                                                                                                             10000
                                                                                                           
                                                                                                         
    
  • Ask about the structured storage of XMLTYPE column in Oracle Xml db

    Dear all,

    Version of DB: Oracle 11g (11.2.0.3.0)

    I have a table with an XMLTYPE column with a structured storage.

    CREATE TABLE Orders
        (
        Order_id NUMBER NOT NULL,
        Order_etc VARCHAR2(100),
        Order_desc XMLType NOT NULL
        )
        XMLTYPE Order_desc STORE AS OBJECT RELATIONAL XMLSCHEMA  "http://localhost/public/xsd/order_desc_xsd.xsd" ELEMENT "OrderState";
    

    I then recorded the XSD XML Db schema that is required for the structured storage.

    Before the creation of the table, I had created a table XMLTYPE (db_objects) and was able to use the query to verify that all objects, the XMLTYPE table got broken into when I signed his XSD below.

        SELECT column_name,      
               data_type
        FROM   user_tab_cols
        WHERE  table_name = 'DB_OBJECTS';
    

    And used under query to find data stored in the object-relational structure for my table (DB_OBJECTS) created with definition of XMLTYPE.

      SELECT EXTRACTVALUE(xseq.column_value, '/THISROW/OWNER')       AS owner
        ,      EXTRACTVALUE(xseq.column_value, '/THISROW/OBJECT_NAME') AS object_name
        ,      EXTRACTVALUE(xseq.column_value, '/THISROW/OBJECT_TYPE') AS object_type
        ,      EXTRACTVALUE(xseq.column_value, '/THISROW/OBJECT_ID')   AS object_id
        ,      EXTRACTVALUE(xseq.column_value, '/THISROW/CREATED')     AS created
        FROM   db_objects do
         ,      TABLE(XMLSEQUENCE(EXTRACT(VALUE(do), '/ROWSET/THISROW'))) xseq  
        WHERE  ROWNUM <= 10;
    

    Now could someone let me know, How to find how the column of XMLTYPE (Order_desc) was divided between other objects, just as I did for the Table with XMLTYPE (as shown above)?

    Thank you very much.

    First of all, because you are on 11.2, ExtractValue is obsolete and the documentation lists three options to use instead.  Here's an (untested) option

    SELECT owner, object_name, object_type, object_id, created
      FROM db_objects do,
           XMLTable('/ROWSET/THISROW'
                    PASSING do.object_value
                    COLUMNS
                    -- Set data types accordingly
                    owner        VARCHAR2(20) PATH 'owner',
                    object_name  VARCHAR2(20) PATH 'object_name',
                    object_type  VARCHAR2(20) PATH 'object_type',
                    object_id    VARCHAR2(20) PATH 'object_id',
                    created      VARCHAR2(20) PATH 'created');
    

    Secondly, why the column order matter?  You store in a method of object / relational.  As long as the XML is valid per the schema, Oracle will be able to store the data and thus to retrieve later.  How these data are mainly internal Oracle and shouldn't be touched because it can be changed from one version to another.  You can use the schema annotation to control how Oracle cards and stores the XML content, but nothing in there specifies the column order I know.

    It seems several details are missing information which could help others to answer your question as to what you need.

  • The xmltype column search and listing content in relational format

    Hi all

    I have a database of GR 11, 1 subject table containing the xmltype column. I'm writing a query that displays conetents xml in a relational format.
    SQL*Plus: Release 11.1.0.7.0 - Production on Thu Jan 17 11:45:06 2013
    
    Copyright (c) 1982, 2008, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 11g Release 11.1.0.7.0 - 64bit Production
    SQL > select * from v version $;

    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11 g Release 11.1.0.7.0 - 64 bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE Production 11.1.0.7.0
    AMT for 64-bit Windows: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production

    SQL > BULKMESSAGES Desc;
    Name of Type Null
    --------------- ---- -------------
    TRANSFER_ID VARCHAR2 (100)
    TRANSFER_LOGS XMLTYPE()
    TRANSFER_RESULT VARCHAR2 (10)

    SQL > select * from BULKMESSAGES
    where TRANSFER_RESULT = "REFUSED."
    /
    TRANSFER_ID TRANSFER_LOGS TRANSFER_RESULT
    ---------------- ---------------------------------------------------------------- ---------------
    T3217 < env:Envelope xmlns:env = 'http://www.w3.org/2003/05/soap-envelope' > REJECTED



    Column of xmltype TRNASFER_LOGS stores the SOAP responses. Response SOAP sample (dummied) of the TRANSFER_LOGS xml column is below:
    <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
         <env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope"/>
         <env:Body xmlns:env="http://www.w3.org/2003/05/soap-envelope">
              <env:Fault xmlns:env="http://www.w3.org/2003/05/soap-envelope">
                   <env:Code xmlns:env="http://www.w3.org/2003/05/soap-envelope">
                        <env:Value xmlns:env="http://www.w3.org/2003/05/soap-envelope">env:Receiver</env:Value>
                        <env:Subcode xmlns:env="http://www.w3.org/2003/05/soap-envelope">
                             <env:Value xmlns:fault="http://www.es.com/soapfaults" xmlns:env="http://www.w3.org/2003/05/soap-envelope">fault:MessageBlocked</env:Value>
                        </env:Subcode>
                   </env:Code>
                   <env:Reason xmlns:env="http://www.w3.org/2003/05/soap-envelope">
                        <env:Text lang="en" xmlns:env="http://www.w3.org/2003/05/soap-envelope">connection rejected</env:Text>
                   </env:Reason>
                   <env:Detail xmlns:fault="http://www.es.com/soapfaults" fault:type="faultDetails" fault:messageId="0000013a6" xmlns:env="http://www.w3.org/2003/05/soap-envelope">
                        <fault:path policy="Request Message">
                             <fault:filter status="Fail" name="Call 'Process request '">
                                  <fault:path policy="Process xml ">
                                       <fault:filter status="Fail" name="Call 'Call 3rdparty service'">
                                            <fault:path policy="Call external service">
                                                 <fault:filter status="Pass" name="Extract message"/>
                                            </fault:path>
                                       </fault:filter>
                                  </fault:path>
                             </fault:filter>
                        </fault:path>
                        <fault:attributes>
                             <fault:attribute name="monitoring.enabled" value="true"/>
                             <fault:attribute name="requestor" value="none"/>
                             <fault:attribute name="circuit.failure.reason" value="connection rejected"/>
                             <fault:attribute name="message_protocol" value="SOAP"/>
                             <fault:attribute name="user_id" value="31274556"/>
                             <fault:attribute name="ws_name" value="PUSHDOC"/>
                             <fault:attribute name="user.enabled" value="N"/>
                             <fault:attribute name="http.request.clientaddr" value="/10.254.123.44:43840"/>
                             <fault:attribute name="soap_action" value="pushDocument"/>
                             <fault:attribute name="message.reception_time" value="1349769769742"/>
                             <fault:attribute name="user.api_logging_flag" value="Y"/>
                             <fault:attribute name="circuit.exception" value="com.es.circuit.CircuitAbortException: connection rejected"/>
                             <fault:attribute name="end_point" value="https://es.live.com/pdfs"/>
                             <fault:attribute name="message.protocol.type" value="http"/>
                             <fault:attribute name="user.incoming_date" value="09-11-2013 09:02:49"/>
                             <fault:attribute name="http.destination.host" value="es.live.com"/>
                             <fault:attribute name="message.local.address" value="/100.25.40.82:8085"/>
                             <fault:attribute value="N"/>
                        </fault:attributes>
                   </env:Detail>
              </env:Fault>
         </env:Body>
    </env:Envelope>
    My goal is to search for documents TRANSFER_LOGS for lines that contain flaws: attribute name = "circuit.exception". Then report "fault: name attribute" and their values in relational format. For example:
    TRANSFER_ID    TRANSFER_RESULT FAULT_FAIL_REASON    FAULT_CIRCUIT_EXCEPTION                               FAULT_WS_NAME   FAULT_DESTINATION_HOST
    ----------     --------------- ----------------     -------------------------------------------------------- -------------   ---------------------
    T3217          REJECTED       CONNECTION REJECTED  com.es.circuit.CircuitAbortException: connection rejected  PUSHDOC       es.live.com
    I am new to oracle XML sql querying. Documents in the column of xmltype TRANSFER_LOGS have many namespaces and the query I've tried does not work. So, any help or pointers to search and extract TRANSFER_LOGS in above format is greatly appreciated.

    Thanks in advance.

    VC

    Hello

    You can use something like this:

    SQL> select t.transfer_id, t.transfer_result, x.*
      2  from bulkmessages t
      3     , xmltable(
      4         xmlnamespaces(
      5           'http://www.w3.org/2003/05/soap-envelope' as "e"
      6         , 'http://www.es.com/soapfaults' as "f"
      7         )
      8       , '/e:Envelope/e:Body/e:Fault/e:Detail/f:attributes'
      9         passing t.transfer_logs
     10         columns
     11           FAULT_FAIL_REASON       varchar2(200) path 'f:attribute[@name="circuit.failure.reason"]/@value'
     12         , FAULT_CIRCUIT_EXCEPTION     varchar2(200) path 'f:attribute[@name="circuit.exception"]/@value'
     13         , FAULT_WS_NAME           varchar2(200) path 'f:attribute[@name="ws_name"]/@value'
     14         , FAULT_DESTINATION_HOST  varchar2(200) path 'f:attribute[@name="http.destination.host"]/@value'
     15         ) x
     16  where xmlexists(
     17         'declare namespace e = "http://www.w3.org/2003/05/soap-envelope"; (: :)
     18          declare namespace f = "http://www.es.com/soapfaults"; (: :)
     19          /e:Envelope/e:Body/e:Fault/e:Detail/f:attributes/f:attribute[@name="circuit.exception"]'
     20          passing t.transfer_logs
     21        ) ;
    
    TRANSFER_ID     TRANSFER_RESULT FAULT_FAIL_REASON        FAULT_CIRCUIT_EXCEPTION                                       FAULT_WS_NAME    FAULT_DESTINATION_HOST
    --------------- --------------- ------------------------ ------------------------------------------------------------- ---------------- -------------------------
    T3217           REJECTED        connection rejected      com.es.circuit.CircuitAbortException: connection rejected     PUSHDOC          es.live.com
     
    

    Or, more simply:

    SQL> select t.transfer_id, t.transfer_result, x.*
      2  from bulkmessages t
      3     , xmltable(
      4         xmlnamespaces(
      5           'http://www.w3.org/2003/05/soap-envelope' as "e"
      6         , 'http://www.es.com/soapfaults' as "f"
      7         )
      8       , '/e:Envelope/e:Body/e:Fault/e:Detail/f:attributes'
      9         passing t.transfer_logs
     10         columns
     11           FAULT_FAIL_REASON       varchar2(200) path 'f:attribute[@name="circuit.failure.reason"]/@value'
     12         , FAULT_CIRCUIT_EXCEPTION     varchar2(200) path 'f:attribute[@name="circuit.exception"]/@value'
     13         , FAULT_WS_NAME           varchar2(200) path 'f:attribute[@name="ws_name"]/@value'
     14         , FAULT_DESTINATION_HOST  varchar2(200) path 'f:attribute[@name="http.destination.host"]/@value'
     15         ) x
     16  where x.FAULT_CIRCUIT_EXCEPTION is not null ;
    
    TRANSFER_ID    TRANSFER_RESULT FAULT_FAIL_REASON      FAULT_CIRCUIT_EXCEPTION                                      FAULT_WS_NAME      FAULT_DESTINATION_HOST
    -------------- --------------- ---------------------- ------------------------------------------------------------ ------------------ --------------------------
    T3217          REJECTED        connection rejected    com.es.circuit.CircuitAbortException: connection rejected    PUSHDOC            es.live.com
      
    
  • Create indexes for an XMLType column.

    Hello

    I have a table that has a column of XMLType, the XSD is saved in DB. The XML is something like -

    < primary >
    < sub1 >
    < child1_1 / >
    < child1_2 / >
    < child1_3 / >
    < / sub1 >
    < sub2 >
    < child2_1 / >
    < child2_2 / >
    < child2_3 / >
    < / sub2 >
    < sub3 >
    < child31_1 / >
    < child3_2 / >
    < child3_3 / >
    < / sub3 >
    < / elementary school >

    I want to create indexes for child nodes. I read THAT XML structure cannot have collection as index it should be singleton.
    So can someone tell me no work around to create indexes for these nodes, or whatever it is that I missed as follows.

    Thank you

    #1. Since you're on 11g stop using the syntax of depricated... (extractValue, table (xmlsequence))

    SQL> create table PURCHASEORDER_TAB
      2  (
      3    PID number(4),
      4    PURCHASEORDER XMLTYPE
      5  )
      6  xmltype column PURCHASEORDER
      7  store as OBJECT RELATIONAL
      8  XMLSCHEMA "http://localhost:80/publishedContent/SB-XML/xsd/2010/purchaseOrder.xsd" Element "PurchaseOrder"
      9  /
    
    Table created.
    
    SQL> select table_name, table_type_name
      2  from user_nested_tables where parent_table_name = 'PURCHASEORDER_TAB';
    
    TABLE_NAME                     TABLE_TYPE_NAME
    ------------------------------ ------------------------------
    SYS_NTdmDOdAAMQsuXdRy6lc0H/A== Action64442_COLL
    SYS_NT8EIzAbUOQFGN2u6hCXP39g== LineItem64443_COLL
    
    SQL> rename "SYS_NT8EIzAbUOQFGN2u6hCXP39g==" to LINEITEM_NT
      2  /
    
    Table renamed.
    
    SQL> create index QTY_INDEX on LINEITEM_NT ("Quantity");
    
    Index created.
    
    SQL> set autotrace on explain lines 250 pages 50 trimspool on
    SQL> --
    SQL> select t.pid, quantity
      2    from PURCHASEORDER_TAB t,
      3         XMLTABLE
      4         (
      5           '/PurchaseOrder/LineItems/LineItem'
      6           passing t.PURCHASEORDER
      7           columns
      8           QUANTITY number(4) path 'Quantity'
      9         )
     10   where QUANTITY = 3
     11  /
    
    no rows selected
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1929272390
    
    --------------------------------------------------------------------------------------------------
    | Id  | Operation                    | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT             |                   |     1 |    46 |     3   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS                |                   |       |       |            |          |
    |   2 |   NESTED LOOPS               |                   |     1 |    46 |     3   (0)| 00:00:01 |
    |*  3 |    TABLE ACCESS FULL         | LINEITEM_NT       |     1 |    23 |     2   (0)| 00:00:01 |
    |*  4 |    INDEX UNIQUE SCAN         | SYS_C00429284     |     1 |       |     0   (0)| 00:00:01 |
    |   5 |   TABLE ACCESS BY INDEX ROWID| PURCHASEORDER_TAB |     1 |    23 |     1   (0)| 00:00:01 |
    --------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(CAST(TO_NUMBER(TO_CHAR("Quantity")) AS number(4) )=3)
       4 - access("NESTED_TABLE_ID"="T"."SYS_NC0002900030$")
    
    Note
    -----
       - dynamic sampling used for this statement (level=2)
    
    SQL> select t.pid, quantity
      2    from PURCHASEORDER_TAB t,
      3         XMLTABLE
      4         (
      5           '/PurchaseOrder/LineItems/LineItem'
      6           passing t.PURCHASEORDER
      7           columns
      8           QUANTITY number(12,4) path 'Quantity'
      9         )
     10   where QUANTITY = 3
     11  /
    
    no rows selected
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 3093486066
    
    --------------------------------------------------------------------------------------------------
    | Id  | Operation                    | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT             |                   |     1 |    46 |     2   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS                |                   |       |       |            |          |
    |   2 |   NESTED LOOPS               |                   |     1 |    46 |     2   (0)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL         | PURCHASEORDER_TAB |     1 |    23 |     2   (0)| 00:00:01 |
    |*  4 |    INDEX RANGE SCAN          | QTY_INDEX         |     1 |       |     0   (0)| 00:00:01 |
    |*  5 |   TABLE ACCESS BY INDEX ROWID| LINEITEM_NT       |     1 |    23 |     0   (0)| 00:00:01 |
    --------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       4 - access("Quantity"=3)
       5 - filter("NESTED_TABLE_ID"="T"."SYS_NC0002900030$")
    
    Note
    -----
       - dynamic sampling used for this statement (level=2)
    
    SQL> select t.pid, quantity
      2    from PURCHASEORDER_TAB t,
      3         XMLTABLE
      4         (
      5           '/PurchaseOrder/LineItems/LineItem'
      6           passing t.PURCHASEORDER
      7           columns
      8           QUANTITY path 'Quantity'
      9         )
     10   where QUANTITY = 3
     11  /
    
    no rows selected
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 3093486066
    
    --------------------------------------------------------------------------------------------------
    | Id  | Operation                    | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT             |                   |     1 |    46 |     2   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS                |                   |       |       |            |          |
    |   2 |   NESTED LOOPS               |                   |     1 |    46 |     2   (0)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL         | PURCHASEORDER_TAB |     1 |    23 |     2   (0)| 00:00:01 |
    |*  4 |    INDEX RANGE SCAN          | QTY_INDEX         |     1 |       |     0   (0)| 00:00:01 |
    |*  5 |   TABLE ACCESS BY INDEX ROWID| LINEITEM_NT       |     1 |    23 |     0   (0)| 00:00:01 |
    --------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       4 - access("Quantity"=3)
       5 - filter("NESTED_TABLE_ID"="T"."SYS_NC0002900030$")
    
    Note
    -----
       - dynamic sampling used for this statement (level=2)
    
    SQL> SELECT t.pid, extractValue(Value(sta),'/LineItem/Quantity')
      2    FROM PURCHASEORDER_TAB t,
      3    table(xmlsequence(extract(t.purchaseOrder,'/PurchaseOrder/LineItems/LineItem'))) sta
      4    WHERE extractValue(Value(sta),'/LineItem/Quantity')= 3
      5  /
    
    no rows selected
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 3093486066
    
    --------------------------------------------------------------------------------------------------
    | Id  | Operation                    | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT             |                   |     1 |    46 |     2   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS                |                   |       |       |            |          |
    |   2 |   NESTED LOOPS               |                   |     1 |    46 |     2   (0)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL         | PURCHASEORDER_TAB |     1 |    23 |     2   (0)| 00:00:01 |
    |*  4 |    INDEX RANGE SCAN          | QTY_INDEX         |     1 |       |     0   (0)| 00:00:01 |
    |*  5 |   TABLE ACCESS BY INDEX ROWID| LINEITEM_NT       |     1 |    23 |     0   (0)| 00:00:01 |
    --------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       4 - access("Quantity"=3)
       5 - filter("NESTED_TABLE_ID"="T"."SYS_NC0002900030$")
    
    Note
    -----
       - dynamic sampling used for this statement (level=2)
    
    SQL>
    

    Note the first example XMLTable does not use the index because the data type of AMOUNT is given wrong...

  • excerpt from the XMLType column

    In my XMLType column I'm storing XML content that is the xml below.

    <? XML version = "1.0" encoding = "UTF-8"? >

    < project >

    < basics >

    < attribute name = "Id" > 3197915 < / attribute >

    < attribute name = "Name" > 345 < / attribute >

    < attribute name = "Révision" / >

    < name of attribute 'Type' = > project < / attribute >

    < / basics >

    < relationship / >

    < children >

    < application >

    < basics >

    < name of attribute 'Type' = > Application < / attribute >

    < attribute name = "Name" > rty < / attribute >

    < = "Scope" attribute name > SCOPE_PROJECT < / attribute >

    < attribute name = "Révision" / >

    < attribute name = "Id" > 3197918 < / attribute >

    < / basics >

    < relationship type = "Project relationship Configuration" >

    < attribute name = "Subclassification subcomponent" / >

    < attribute name = 'Type of subcomponent' / >

    < attribute name = "Quantity" > 1 < / attribute >

    < attribute name = "Unit of measurement" / >

    < = "Scope" attribute name > SCOPE_PROJECT < / attribute >

    < attribute name = "Post number" / >

    < attribute name = "Additional Information" / >

    < / relationship >

    < children / >

    < / application >

    < typical >

    < basics >

    < name of attribute 'Type' = > rrrr < / attribute >

    < attribute name = "Name" > rrr_Mo < / attribute >

    < attribute name = "Id" > 944674 < / attribute >

    < = "Scope" attribute name > SCOPE_GLOBAL < / attribute >

    < attribute name = "Révision" / >

    < / basics >

    < children / >

    < / typical >

    < application >

    < basics >

    < name of attribute 'Type' = > Application < / attribute >

    < attribute name = "Name" > yu123 < / attribute >

    < = "Scope" attribute name > SCOPE_PROJECT < / attribute >

    < attribute name = "Révision" / >

    < attribute name = "Id" > 3197922 < / attribute >

    < / basics >

    < children / >

    < / application >

    < / children >

    < / project >

    How to write a query to extract the Application name?

    Here, it should return "anais" and "yu123".

    I'm using Oracle 11 g.

    Thanks in advance.

    Something like the following, where TMP_XML. DOC is my XMLType column:

    SQL> select x.*
      2  from tmp_xml t
      3     , xmltable('/Project/Children/Application/Basics'
      4         passing t.doc
      5         columns application_name varchar2(30) path 'Attribute[@Name="Name"]'
      6       ) x
      7  ;
    
    APPLICATION_NAME
    ------------------------------
    rty
    yu123
    
  • extraction of xmltype table in the xml output: redundant nodes

    Hi guys - see example below.  (edit: Sorry, did not use these forums for a while and can't seem to understand how to format the code...)

    [code] SQL > select *.

    the v version $2;

    BANNER

    --------------------------------------------------------------------------------

    Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production

    PL/SQL Release 11.2.0.4.0 - Production

    CORE Production 11.2.0.4.0

    AMT for Linux: Version 11.2.0.4.0 - Production

    NLSRTL Version 11.2.0.4.0 - Production

    [/ code]

    [/ code]

    SQL > create table mytesttable (item_id issue, x_data xmltype);

    Table created.

    SQL >

    SQL > insert into mytesttable

    2 with dat (select ' blah' point of double

    3 Union all the

    4 Select "blah" more than double)

    5, t as (select xmlelement ("x_data"

    6, xmlattributes (1 as "dummyattr")

    7, xmlagg (xmlelement ("item"

    8                                                ,item))

    9                              ) x_data

    10 dat

    11              )

    12. Select 1, x_data

    13 t;

    1 line of creation.

    SQL >

    SQL > select *.

    2 of mytesttable;

    ITEM_ID

    ----------

    X_DATA

    ---------------------------------------------------------------------------------------------

    -------

    1

    < x_data dummyattr = "1" >

    < item > blah < / item >

    < element > more blah < / item >

    < / x_data >

    1 selected line.

    SQL >

    SQL > select xmlelement ("outerelement"

    2, xmlelement ("itemID", item_id)

    3, xmlelement ("x_data", x_data)

    4                   )

    5 mytesttable;

    XMLELEMENT ("OUTERELEMENT", XMLELEMENT("ITEMID",ITEM_ID), XMLELEMENT("X_DATA",X_DATA))

    ---------------------------------------------------------------------------------------------

    -------

    < outerelement > < itemID > 1 < / itemID > < x_data > < x_data dummyattr = "1" >

    < item > blah < / item >

    < element > more blah < / item >

    < / x_data >

    < / x_data > < / outerelement >

    1 selected line.

    [/ code]

    Like the above, I have an xmltype in a table that has other non-xmltype columns.   I have a requirement to extract them out in a single xml document in a manner similar to the last SQL it.

    the problem is that if I do it according to the foregoing, I add a redundant node artificially.  the first node < x_data > is not necessary, but how can I go and add the xmltype column to the result without having to qualify it with another element around it?

    know how to do the following:

    < outerelement > < itemID > 1 < / itemID > < x_data dummyattr = "1" >

    < item > blah < / item >

    < element > more blah < / item >

    < / x_data > < / outerelement >

    ?

    Too bad... I had a moment mute:

    Select xmlelement ("outerelement"

    xmlelement ("itemID", item_id)

    x_data

    )

    of mytesttable;

Maybe you are looking for