XML in PLSQL without using SELECT statements

It maybe crazy but I cannot find a book or an example to differentiate between these two ones, if it is english or french based on XML below.
set serveroutput on size 1000000
DECLARE
l_doc VARCHAR2(2000);
l_domdoc dbms_xmldom.DOMDocument;
l_nodelist dbms_xmldom.DOMNodeList;
l_node dbms_xmldom.DOMNode;
l_value VARCHAR2(30);
l_xmltype XMLTYPE;
l_empx XMLTYPE;
l_index PLS_INTEGER;
l_col_ind PLS_INTEGER;
v_namespace_prfx varchar2(20):= 'ns0:';
v_namespace varchar2(200):= 'xmlns="http://www.rona.ca/SharedResources/SchemaDefinitions/Canonical"';
l_nsmap varchar2(200);
BEGIN
l_doc := '<?xml version = "1.0" encoding = "UTF-8"?>          
<ns0:Product type = "DEPAS" xmlns:ns0 = "http://www.rona.ca/SharedResources/SchemaDefinitions/Canonical">          
     <ns0:ProductIDs>     
          <ns0:ID type = "RONCD">48535003</ns0:ID>
     </ns0:ProductIDs>     
     <ns0:ProductUom Usage = "PURCU">     
          <ns0:Quantity uomCode = "EA">1</ns0:Quantity>
     </ns0:ProductUom>     
     <ns0:ProductUom Usage = "SALEU">     
          <ns0:Quantity uomCode = "EA">1</ns0:Quantity>
     </ns0:ProductUom>     
     <ns0:CreateDateTime>2003-02-16T00:00:00-04:00</ns0:CreateDateTime>     
     <ns0:Status>     
          <ns0:Code>ACTV</ns0:Code>
     </ns0:Status>     
     <ns0:Description languageCode = "fra" type = "REGID">DEPOT BOUTEILLE</ns0:Description>     
     <ns0:Description languageCode = "eng" type = "REGID">BOTTLE DEPOSIT</ns0:Description>          
     <ns0:Description languageCode = "fra" type = "LONGD">DEPOT BOUTEILLE D''EAU</ns0:Description>          
     <ns0:Description languageCode = "eng" type = "LONGD">DEPOSIT WATER BOTTLE</ns0:Description>          
     <ns0:Description languageCode = "fra" type = "REGI4">DEPOT BOUTEILLE</ns0:Description>          
     <ns0:Description languageCode = "eng" type = "REGI4">BOTTLE DEPOSIT</ns0:Description>          
     <ns0:Description languageCode = "fra" type = "CLEI4">DEPOT</ns0:Description>          
     <ns0:Description languageCode = "eng" type = "CLEI4">DEPOSIT</ns0:Description>          
     <ns0:Description languageCode = "eng" type = "LONG4">DEPOSIT WATER BOTTLE</ns0:Description>          
     <ns0:Description languageCode = "fra" type = "LONG4">DEPOT BOUTEILLE D''EAU</ns0:Description>          
</ns0:Product>';
l_xmltype := XMLTYPE(l_doc);
-- Method 3
dbms_output.new_line;
dbms_output.put_line('Method 3');
l_index := 1;
l_nsmap:=v_namespace;
--dbms_output.put_line('ID type = ' || l_xmltype.extract('/GetRequest/ProductIDs/ID[2]/@type', l_nsmap).getStringVal());
WHILE l_xmltype.Existsnode('/Product/'||'Description[' || To_Char(l_index) || ']',v_namespace) > 0
LOOP
dbms_output.put_line('I am here');
-- dbms_output.put_line('ID = ' || l_xmltype.extract('/GetRequest/ProductIDs/ID/text()', l_nsmap).getStringVal());
dbms_output.put_line('ID type = ' || l_xmltype.extract('/Product/'||'Description[' || To_Char(l_index) || ']/@type', l_nsmap).getStringVal());
dbms_output.put_line('ID type = ' || l_xmltype.extract('/Product/'||'Description[' || To_Char(l_index) || ']/text()', l_nsmap).getStringVal());
-- is it english or french ? how can I capture the difference ? my example does not work
dbms_output.put_line('ID type = ' || l_xmltype.extract('/Product/'||'Description[' || To_Char(l_index) || '][languageCode = "eng"]/text()', l_nsmap).getStringVal());
--dbms_output.put_line('Emp Name: '||l_value);
l_index := l_index + 1;
END LOOP;
END;

I think you already know this since you extract the "type" attribute too.
As well, languageCode is an attribute so you must access it with the "@" notation (or the attribute:: axis).
Now, it depends on what you want to do :
1- extract only Descriptions in a given language ?
2- extract all Descriptions along with their language ?
For 1) the current iteration method is not appropriate and you can't just add the corresponding predicate in the existsNode test because there's no correlation between the node position and the languageCode.
You have to count how many nodes of the given language there are and then loop from 1 to this count.
Or, fall back to case 2) and test the language within the loop after having extracted it.
For 2) add another extract call that targets the attribute :
WHILE l_xmltype.Existsnode('/Product/'||'Description[' || To_Char(l_index) || ']',v_namespace) > 0
LOOP
  dbms_output.put_line('type = ' || l_xmltype.extract('/Product/'||'Description[' || To_Char(l_index) || ']/@type', l_nsmap).getStringVal());
  dbms_output.put_line('languageCode = ' || l_xmltype.extract('/Product/'||'Description[' || To_Char(l_index) || ']/@languageCode', l_nsmap).getStringVal());
  dbms_output.put_line('Description = ' || l_xmltype.extract('/Product/'||'Description[' || To_Char(l_index) || ']/text()', l_nsmap).getStringVal());
  l_index := l_index + 1;
END LOOP;XMLTable is so much simpler to use in any case.

Similar Messages

  • Using plsql tables in select statement of report query

    Hi
    Anyone have experience to use plsql table to select statement to create a report. In otherwords, How to run report using flat file (xx.txt) information like 10 records in flat files and use this 10 records to the report and run pdf files.
    thanks in advance
    suresh

    hi,
    u can use the utl_file package to do that using a ref cursor query in the data model and u can have this code to read data from a flat file
    declare
    ur_file utl_file.file_type;
    my_result varchar2(250);
    begin
    ur_file := UTL_FILE.FOPEN ('&directory', '&filename', 'r') ;
    utl_file.get_line(ur_file, my_result);
    dbms_output.put_line(my_result);
    utl_file.fclose(ur_file);
    end;
    make sure u have an entry in ur init.ora saying that your
    utl_file_dir = '\your directory where ur files reside'
    cheers!
    [email protected]

  • Updating data without using update statement

    Hi,
    A quick question...
    Can any table data could be updated without using update statement from backend.
    Just wanted to make sure.
    Thanks in advance.

    Hi,
    What is your definition of Update?
    Since your question is vague and you dont explain what exactly you mean.
    here are my thoughts
    1) A record can be deleted and isnerted with new values.Where the nes values have only few columns changed from previous ones.
    2) I use pl/sql developer.If i need to update i can write select.. for update.Change the values (as in notepad)Commit.
         This is infact a update but with nice UI
    3) even your application can update data in your tables, if you code it and give correct privileges to the userRegards,
    Bhushan

  • Using Select statement in IF condition?

    hi all,
    Can i use select statement in IF COndition in pl sql ?
    eg like- if( select 1 from ASD) then
    end if;

    There is no way to do any kind of select statement inside if conditions.
    Why don't test simple cases like this first?
    An example to show it.
    SQL> begin
      2   if exists (select 1 from dual) then
      3    dbms_output.put_line('ok');
      4   end if;
      5  end;
      6  /
    if exists (select 1 from dual) then
    ERRORE alla riga 2:
    ORA-06550: line 2, column 5:
    PLS-00204: function or pseudo-column 'EXISTS' may be used inside a SQL
    statement only
    ORA-06550: line 2, column 2:
    PL/SQL: Statement ignored
    SQL> begin
      2   if ( (select count(*) from dual) > 0 ) then
      3    dbms_output.put_line('ok');
      4   end if;
      5  end;
      6  /
    if ( (select count(*) from dual) > 0 ) then
    ERRORE alla riga 2:
    ORA-06550: line 2, column 8:
    PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
    ( - + case mod new not null others <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> avg
    count current exists max min prior sql stddev sum variance
    execute forall merge time timestamp interval date
    <a string literal with character set specification>
    <a number> <a single-quoted SQL string> pipe
    <an alternatively-quoted string literal with character set specification>
    <an alternativ
    ORA-06550: line 2, column 33:
    PLS-00103: Encountered the symbol ")" when expecting one of the following:
    . , @ ; for <an identifier>
    <a double-quoted delimited-identifier> group having intersect
    minus order partition start subpartition union where connect
    SQL> begin
      2   if ( 0 in (select count(*) from dual) ) then
      3    dbms_output.put_line('ok');
      4   end if;
      5  end;
      6  /
    if ( 0 in (select count(*) from dual) ) then
    ERRORE alla riga 2:
    ORA-06550: line 2, column 12:
    PLS-00405: subquery not allowed in this context
    ORA-06550: line 2, column 2:
    PL/SQL: Statement ignoredBye Alessandro

  • CREATE XML PUBLISHER REPORT WITHOUT USING RDF

    Hi Every one ,
    Can anybody share his/her expertise on following issue ?
    "How to create XML Publisher Report without using RDF?"
    Your help is appreciated.

    Hi Swapnesh
    YOu do not need to create the XDODTEXE, its seeded for you. You need to do the following:
    1. Create and test the data template
    2. Load the data template to the template manager against a data definition
    3. Create a concurrent program definition that uses the XDODTEXE as its executable
    4. Create parameters (if required) for the CP and DT that match in name
    You're done
    Regards
    Tim

  • Number of rows inserted is different in bulk insert using select statement

    I am facing a problem in bulk insert using SELECT statement.
    My sql statement is like below.
    strQuery :='INSERT INTO TAB3
    (SELECT t1.c1,t2.c2
    FROM TAB1 t1, TAB2 t2
    WHERE t1.c1 = t2.c1
    AND t1.c3 between 10 and 15 AND)' ....... some other conditions.
    EXECUTE IMMEDIATE strQuery ;
    These SQL statements are inside a procedure. And this procedure is called from C#.
    The number of rows returned by the "SELECT" query is 70.
    On the very first time call of this procedure, the number rows inserted using strQuery is *70*.
    But in the next time call (in the same transaction) of the procedure, the number rows inserted is only *50*.
    And further if we are repeating calling this procedure, it will insert sometimes 70 or 50 etc. It is showing some inconsistency.
    On my initial analysis it is found that, the default optimizer is "ALL_ROWS". When i changed the optimizer mode to "rule", this issue is not coming.
    Anybody faced these kind of issues?
    Can anyone tell what would be the reason of this issue..? any other work around for this...?
    I am using Oracle 10g R2 version.
    Edited by: user13339527 on Jun 29, 2010 3:55 AM
    Edited by: user13339527 on Jun 29, 2010 3:56 AM

    You have very likely concurrent transactions on the database:
    >
    By default, Oracle Database permits concurrently running transactions to modify, add, or delete rows in the same table, and in the same data block. Changes made by one transaction are not seen by another concurrent transaction until the transaction that made the changes commits.
    >
    If you want to make sure that the same query always retrieves the same rows in a given transaction you need to use transaction isolation level serializable instead of read committed which is the default in Oracle.
    Please read http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_sqlproc.htm#ADFNS00204.
    You can try to run your test with:
    set  transaction isolation level  serializable;If the problem is not solved, you need to search possible Oracle bugs on My Oracle Support with keywords
    like:
    wrong results 10.2Edited by: P. Forstmann on 29 juin 2010 13:46

  • How to pass parameter in Function by using select statement?

    Hi,
    I got a problem. I cant pass in parameter to function by using select statement. But it can pass in parameter by using 'hardcode' method. How can I solve this problem?
    Eg,
    select * from table (SplitFunction('HS750020,HS750021')) <<< this work.
    but
    select * from table (SplitFunction(select LOT_NO from TRACER_SEARCH_SCHEDULE where JOB_ID = '36')) <<< do not work.
    Thanks for who try to help. Thanks.

    skymonster84 wrote:
    I have try this before. But it not work.here is an example
    create or replace type stringlist as table of varchar2(100)
    create or replace function splitstring(pstring in varchar2) return stringlist
    as
      lstringlist stringlist;
    begin
      select regexp_substr(pstring,'[^,]+',1, level) bulk collect into lstringlist
        from dual
      connect by level <= length(pstring)-length(replace(pstring,','))+1;
      return lstringlist;
    end;
    select * from table(select splitstring('xx,yy,zz') from dual)
    create table t(str varchar2(100))
    insert into t values('x,y,z')
    insert into t values('a,b,c')
    select * from table(select splitstring(str) from t where rownum<2)
    /If you supply multiple values then it will fail.
    select * from table(select splitstring(str) from t)
    /

  • Insert using select statement

    Hi,
    I am trying to insert values using select statement. But this is not working
    INSERT INTO contribution_temp_upgrade
    (PRO_ID,
    OBJECT_NAME,
    DELIVERY_DATE,
    MODULE_NAME,
    INDUSTRY_CATERGORIZATION,
    ADVANTAGES,
    REUSE_DETAILS)
    VALUES
    SELECT
    :P1_PROJECTS,
    wwv_flow.g_f08(vRow),
    wwv_flow.g_f09(vRow),
    wwv_flow.g_f10(vRow),
    wwv_flow.g_f11(vRow),
    wwv_flow.g_f12(vRow),
    wwv_flow.g_f13(vRow)
    FROM DUAL;
    Please let me know what i am missing..
    Thanks
    Sudhir

    Try this
    INSERT INTO contribution_temp_upgrade
    (PRO_ID,
    OBJECT_NAME,
    DELIVERY_DATE,
    MODULE_NAME,
    INDUSTRY_CATERGORIZATION,
    ADVANTAGES,
    REUSE_DETAILS)
    SELECT
    :P1_PROJECTS,
    wwv_flow.g_f08(vRow),
    wwv_flow.g_f09(vRow),
    wwv_flow.g_f10(vRow),
    wwv_flow.g_f11(vRow),
    wwv_flow.g_f12(vRow),
    wwv_flow.g_f13(vRow)
    FROM DUAL;Note: when you are selecting a value using select statement, you should not specify the keyword "values".
    i assume you have already assigned value for your bind variable :P1_PROJECTS and rest of the functions will return some value.
    Regards,
    Prazy

  • How can I select columns from a table EMP, using Select statement?.

    Hi Friends,
    How can I select columns from a table EMP?.
    I want to select columns of EMP table, using select statement.
    Please reply me urgently.
    Shahzad

    Something like this:
    scott@DBA> select empno,ename,job from emp;
         EMPNO ENAME      JOB
          7369 SMITH      CLERK
          7499 ALLEN      SALESMAN
          7521 WARD       SALESMAN
          7566 JONES      MANAGER
          7654 MARTIN     SALESMAN
          7698 BLAKE      MANAGER
          7782 CLARK      MANAGER
          7788 SCOTT      ANALYST
          7839 KING       PRESIDENT
          7844 TURNER     SALESMAN
          7876 ADAMS      CLERK
          7900 JAMES      CLERK
          7902 FORD       ANALYST
          7934 MILLER     CLERK
    14 rows selected.Check the documentation:
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9697
    Message was edited by:
    Delfino Nunez

  • How to fetch negative sign data using select statement

    hi gurus,,
                  i hv  to fetch data which is negative in nature  using select statement i m using ppdit table and wrbtr field.(it contains both negative and positive data)....wat sud i add with select statement...plz help me..
    thnx in advance
    Message was edited by:

    HI,
               I think you can use LT or < 0.0 in the WHERE clause to get all the -ve values. Once you get them treat them as negative.
    Regards,
    Sesh

  • FETCHING VALUES IN MULTI RECORD BLOCK FROM ANOTHER TABLE USING SELECT STATEMENT.

    Hi,
    I have one multi record block in which i want to fetch values
    (more then one record) from another table using select statement
    IN KEY NEXT ITEM.I am getting following error.
    ORA-01422: exact fetch returns more than requested number of rows
    Thanks in advance.

    In your case I see no reason to use non-database block and to try to populate it from a trigger with a query, instead of using the default forms functionality where you can associate the block and the fields with table, create where clause using bind variables and simply use execute_query() build-in to populate the block. The power of the forms is to use their build-in functionality to interact with the database.
    Also, you can base your block on a query, not on a table and you dynamically change this query using set_block_property() build-in. You can use any dynamic queries (based on different data sources) and you simply need to control the column's data type, the number of the columns and their aliases. Something like creating inline views as a block data source.
    However, you can replace the explicit cursor with implicit one like
    go_block('non_db_block_name');
    first_record();
    FOR v_tab IN (SELECT *
    FROM tab
    WHERE col_name = :variable)
    LOOP
    :non_db_block_name.field1 := v_tab.col1;
    :non_db_block_name.field2 := v_tab.col2;
    next_record();
    END LOOP;

  • Can i use select statements in LDB

    Hai All,
       Can i use select statements and internal table in a LDB program.
    my requirement is that if i enter company code , fiscal year and reporting periods.
    generally fiscal year will be jan to dec.but in my requirement the fiscal year is apr of previous year to march of currentyear.
    so as i require the last years data can iuse select statement in that ldb program or is there any solution for this.
    Thanks in Advance
    kiran

    Hi Kiran,
    To retrive records from ldb you have to use the
    GET <node> statement. This will invoke the selection screen of the node. An alternate solution is to use the function module LDB_PROCESS.
    Please see the following link for help and example
    http://help.sap.com/saphelp_nw04/helpdata/en/64/237f8cd43711d1950b0000e8353423/content.htm
    Thanks
    Vinod

  • How to get the inserted row primary key with out  using select statement

    how to return the primary key of inserted row ,with out using select statement
    Edited by: 849614 on Apr 4, 2011 6:13 AM

    yes thanks to all ,who helped me .its working fine
    getGeneratedKeys
    String hh = "INSERT INTO DIPOFFERTE (DIPOFFERTEID,AUDITUSERIDMODIFIED)VALUES(DIPOFFERTE_SEQ.nextval,?)";
              String generatedColumns[] = {"DIPOFFERTEID"};
              PreparedStatement preparedStatement = null;
              try {
                   //String gen[] = {"DIPOFFERTEID"};
                   PreparedStatement pstmt = conn.prepareStatement(hh, generatedColumns);
                   pstmt.setLong(1, 1);
                   pstmt.executeUpdate();
                   ResultSet rs = pstmt.getGeneratedKeys();
                   rs.next();
    //               The generated order id
                   long orderId = rs.getLong(1);

  • How to avoid data repetation when using select statements with innerjoin

    how to avoid data repetation when using select statements with innerjoin.
    thanks in advance,
    satheesh

    you can use a query like this...
      SELECT DISTINCT
             frg~prc_group1                  "Product Group 1
             frg~prc_group2                  "Product Group 2
             frg~prc_group3                  "Product Group 3
             frg~prc_group4                  "Product Group 4
             frg~prc_group5                  "Product Group 5
             prc~product_id                  "Product ID
             txt~short_text                  "Product Description
    UP TO 10 ROWS
    INTO TABLE l_i_data
    FROM
    Joining CRMM_PR_SALESG and
    COMM_PR_FRG_ROD
    crmm_pr_salesg AS frg
    INNER JOIN comm_pr_frg_rod AS prd
    ON frgfrg_guid = prdfragment_guid
    Joining COMM_PRODUCT and
    COMM_PR_FRG_ROD
    INNER JOIN comm_product AS prc
    ON prdproduct_guid = prcproduct_guid
    Joining COMM_PRSHTEXT and
    COMM_PR_FRG_ROD
    INNER JOIN comm_prshtext AS txt
    ON prdproduct_guid = txtproduct_guid
    WHERE frg~prc_group1 IN r_zprc_group1
       AND frg~prc_group2 IN r_zprc_group2
       AND frg~prc_group3 IN r_zprc_group3
       AND frg~prc_group4 IN r_zprc_group4
       AND frg~prc_group5 IN r_zprc_group5.
    reward it it helps
    Edited by: Apan Kumar Motilal on Jun 24, 2008 1:57 PM

  • Sorting techinque without using sort statement /Comparing table fields.

    Hi,
    How to achieve sorting techinque without using sort statement in tables.
    Also how to compare fields of 2 custom tables and check their compatability without using code ?

    Hi,
    Refer the below program, it will be helpful.
    types: begin of t_int,
             int type i,
            end of t_int.
    data: it_int type standard table of t_int,
           wa_int type t_int,
           wa_int1 type t_int.
    wa_int-int = 70.
    append wa_int to it_int.
    clear wa_int.
    wa_int-int = 50.
    append wa_int to it_int.
    clear wa_int.
    wa_int-int = 20.
    append wa_int to it_int.
    clear wa_int.
    wa_int-int = 30.
    append wa_int to it_int.
    clear wa_int.
    wa_int-int = 23.
    append wa_int to it_int.
    clear wa_int.
    wa_int-int = 23.
    append wa_int to it_int.
    clear wa_int.
    wa_int-int = 32.
    append wa_int to it_int.
    clear wa_int.
    wa_int-int = 77.
    append wa_int to it_int.
    clear wa_int.
    wa_int-int = 99.
    append wa_int to it_int.
    clear wa_int.
    wa_int-int = 1.
    append wa_int to it_int.
    clear wa_int.
    wa_int-int = 11.
    append wa_int to it_int.
    clear wa_int.
    wa_int-int = 90.
    append wa_int to it_int.
    clear wa_int.
    wa_int-int = 40.
    append wa_int to it_int.
    clear wa_int.
    data: wk_line type i.
    data: cnt type i.
    data: cnt1 type i.
    describe table it_int lines wk_line.
    clear: cnt,cnt1.
    data wk_flag type c.
       clear wk_flag.
    while wk_line gt cnt1.
       cnt = cnt + 1.
       read table it_int into wa_int index cnt.
       cnt1 = cnt + 1.
       read table it_int into wa_int1 index cnt1.
       if wa_int-int lt wa_int1-int.
         modify it_int from wa_int index cnt1.
         modify it_int from wa_int1 index cnt.
         wk_flag = 'X'.
       endif.
       if cnt1 eq wk_line.
         clear: cnt, cnt1.
         if wk_flag eq 'X'.
         clear wk_flag.
         continue.
         else.
           exit.
         endif.
       endif.
    endwhile.
    loop at it_int into wa_int.
       write: / wa_int-int.
    endloop.

Maybe you are looking for