Breaking a single query using for loop to improve performance

Hi,
This is a continuation of my previous post which I marked Answered and few things are were left from my side and I was advised to post a new thread...
[Will it be a good ply|http://forums.oracle.com/forums/thread.jspa?threadID=880922&tstart=0]
will it be applicable to any query because I took this to simplify the thing to explain my case
which is actually........... pull the data from some tables using joins and insert into some other tables .....
I used few procedures for diff conditions one of them use plain' insert into select' and others use bulk collect technique.
I followed the simple strategy (for DML ) by Tom Kytes ..and Steven Feuerstein
Use single statement whenever it is possible..
if not use PL/SQL with bulk collect to avoid for loop.
Please correct me if I am wrong.
Thanks and Regards,
Hesh.

A simple test can prove the case
SQL> set serveroutput on
SQL>
SQL> create table t
  2  as
  3  select * from all_objects where 1=2
  4  /
Table created.
SQL> declare
  2    ltime integer;
  3  begin
  4      ltime := dbms_utility.get_time;
  5      insert into t select * from all_objects;
  6      ltime := dbms_utility.get_time - ltime;
  7
  8      dbms_output.put_line(ltime);
  9  end;
10  /
187
PL/SQL procedure successfully completed.
SQL> rollback
  2  /
Rollback complete.
SQL> declare
  2      ltime integer;
  3      type tbl is table of t%rowtype index by pls_integer;
  4      l_tbl tbl;
  5      cursor c
  6      is
  7      select * from all_objects;
  8  begin
  9      ltime := dbms_utility.get_time;
10      open c;
11      loop
12          fetch c bulk collect into l_tbl limit 500;
13          exit when c%notfound;
14
15          forall i in 1..l_tbl.count
16            insert into t values l_tbl(i);
17      end loop;
18
19      ltime := dbms_utility.get_time - ltime;
20
21      dbms_output.put_line(ltime);
22  end;
23  /
390
PL/SQL procedure successfully completed.
SQL> rollback
  2  /
Rollback complete.

Similar Messages

  • Will using for loop decrease the performance

    Hi,
    Will using for loop with a query decrease the performance.
    for r_row in (select * from table) Loop
    end loop.
    This is done inside another for loop, most of the cases it returns only one value.
    will it decrease the peformance of the procedure.
    kindly advice.......
    Regards,
    Balu

    user575682 wrote:
    Will using for loop with a query decrease the performance.
    for r_row in (select * from table) Loop
    end loop.
    This is done inside another for loop, most of the cases it returns only one value.
    will it decrease the peformance of the procedure.Perhaps it is better to understand just what this PL/SQL loop construct does.
    PL/SQL is two languages. It is PL (programming logic code) like Pascal or C or Java. You can use a 2nd language inside it called SQL. The PL engine is clever enough to recognise when the 2nd language is used. And it compiles all the stuff that is needed for the PL engine to call the SQL engine, pass data to the SQL engine and get data back, etc. (compare this with the complexity of using the SQL language in Pascal or C or Java).
    So what does that loop do? The PL engine recognises the SQL SELECT statement. It creates an implicit cursor by calling the SQL engine to parse it (hopefully a soft parse) and then execute it.
    As part of the PL loop, the PL engine now calls the SQL engine to fetch the data (rows) from the cursor. With 10g and later, the PL engine is smart enough to use implicit bulk processing.
    Prior to 10g it used to fetch a row from the SQL engine, do the loop, fetch the next row, do the loop, etc. This means if there is a 1000 rows to fetch, it will call the SQL engine a 1000 times.
    With 10g and later it will fetch a 100 rows, store that in an internal buffer and then do the loop a 100 times. With a 1000 rows to fetch, it now only requires 10 bulk fetches instead of a 1000 single row fetches.
    These fetches require a context switch - as the PL engine has to step out and into the SQL engine and back, to fetch a row. This is an overhead and thus can become slow the more context switching there is.
    And this is the basics for this loop (and most other cursor loops) construct in PL/SQL.
    The ideal is to reduce the number of context switches. This is an overhead that can impact on performance.
    What about using a loop within a loop. Also "bad". This uses the outer loop to fetch data. This data is then used to drive the fetch in the inner or nested loop. So the outside loop pulls data from the SQL engine into PL variables. The inside loop pushes that very same data back to the SQL engine.
    Why? It would have been a lot faster no to pull and push that data between the loops using PL.
    It will be a lot faster doing it via SQL only. Write both loops as a single SQL statement and have the SQL engine directly drive these loops itself. This is called a JOIN in SQL. And the SQL engine can do it not only faster, but it has some froody algorithms that can be used that are even faster than a nested loop process (called merge joins, hash joins, etc).
    Bottom line. Maximise SQL. Minimise PL.*
    Do as much of your data crunching in SQL as possible. SQL is the best and fastest "place" to process data. Not PL (or Pascal/C/Java).

  • How do i sweep two voltage at the same time by using for loop ?

    Hello, Can anyone help me on this topic ?
    My problem is to sweep Vds and Vgs as same time vs Id in MOSFET by using for loop. I also use the Agilent power supply source. Let me tell a litle bit about what i'm doing. For different value of Vds, i will get Vgs vs Id curve. (The x axis is Vgs, the y-axis is Id).
    I started to create two for-loop, the inner to sweep Vgs, and the outer one to sweep Vds. My problem is don't know how to connect all the wire in  the for loop.
    In the for loop i saw N, i icon. Suppose I have the two variable for Vgs such as Vgs start and Vgs_stop. Should the Vgs_start( or Vgs_stop) be connected to N or leave it in the for_loop ?
     for example: I want to sweep Vgs from 0(for Vgs_start)  to  5(Vgs_strop) V, and the step increment is .5V how do i connect these variables in the for loop ?
    Thank you for your time
    Ti Nguyen

    It is easier to use a while loop.  Dennis beat me to the punch.  Here is my solution:
    You can remove the flat sequence structure if you use Error In and Error Out to ensure the execution flow will occur in the proper order.  Be sure to include the delay time in the loop so that your vi doesn't hog all the CPU time.
    Message Edited by tbob on 10-17-2005 01:00 PM
    - tbob
    Inventor of the WORM Global
    Attachments:
    RampVoltage.PNG ‏8 KB

  • Repeating nodes using FOR loop but when concating XML string then concating only last iteration of FOr loop ??

    I stuck with a problem that I am using FOR loop for generating repeating nodes. 
    Now when I concat the generated node in the main node then I got only last iteration of that FOR loop.
    can anybody suggest me a way to handle this error....
    FOR i IN 1..pl_phone_tab.Count
    LOOP
    SELECT xmlelement("Phone"     
                                        ,xmlelement("PHONETYPE",xmlattributes('01' AS "dmnADRP_PHONETYPE"),pl_phone_tab(i).p_phtype_tab)
                         ,xmlelement("PHONENUM",pl_phone_tab(i).p_phnum_tab)
                         ,xmlelement("PRIMARY_CONTACT",pl_phone_tab(i).p_prcon_tab)
    INTO p_phone_xml
    FROM dual; END LOOP;
    SELECT xmlelement("PhoneInfo"
                           ,xmlconcat(p_phone_xml))
    INTO p_phone_info_xml
    FROM dual;
    here I am getting only one node but there has to be two nodes for PHONE node

    Not that I'm encouraging you but here are two standalone examples explaining how to do what you want :
    1) Loop through the input collection and append each node to its target container :
    SQL> declare
      2 
      3    type t_emp_tab is table of scott.emp%rowtype;
      4 
      5    emp_tab       t_emp_tab;
      6    emp_info_xml  xmltype;
      7    emp_xml       xmltype;
      8 
      9  begin
    10 
    11    -- filling emp_tab with data
    12    select e.*
    13    bulk collect into emp_tab
    14    from scott.emp e
    15    where e.deptno = 10;
    16 
    17    emp_info_xml := xmltype('<EmpInfo/>');
    18 
    19    -- looping through emp collection and appending to EmpInfo element
    20    for i in 1 .. emp_tab.count loop
    21      select appendchildxml(
    22               emp_info_xml
    23             , '/*'
    24             , xmlelement("Emp"
    25               , xmlattributes(emp_tab(i).empno as "id")
    26               , xmlforest(
    27                   emp_tab(i).ename as "Name"
    28                 , emp_tab(i).job as "Job"
    29                 )
    30               )
    31             )
    32      into emp_info_xml
    33      from dual;
    34    end loop;
    35 
    36    dbms_output.put_line(emp_info_xml.getclobval(1,2));
    37 
    38  end;
    39  /
    <EmpInfo>
      <Emp id="7782">
        <Name>CLARK</Name>
        <Job>MANAGER</Job>
      </Emp>
      <Emp id="7839">
        <Name>KING</Name>
        <Job>PRESIDENT</Job>
      </Emp>
      <Emp id="7934">
        <Name>MILLER</Name>
        <Job>CLERK</Job>
      </Emp>
    </EmpInfo>
    PL/SQL procedure successfully completed
    2) Build a secondary collection of XML nodes and use XMLAgg to aggregate them in one go :
    SQL> declare
      2 
      3    type t_emp_tab is table of scott.emp%rowtype;
      4 
      5    emp_tab       t_emp_tab;
      6    emp_info_xml  xmltype;
      7    emp_xml_tab   xmlsequencetype := xmlsequencetype();
      8 
      9  begin
    10 
    11    -- filling emp_tab with data
    12    select e.*
    13    bulk collect into emp_tab
    14    from scott.emp e
    15    where e.deptno = 10;
    16 
    17    -- looping through emp collection and appending to the collection of Emp nodes
    18    for i in 1 .. emp_tab.count loop
    19 
    20      emp_xml_tab.extend;
    21 
    22      select xmlelement("Emp"
    23             , xmlattributes(emp_tab(i).empno as "id")
    24             , xmlforest(
    25                 emp_tab(i).ename as "Name"
    26               , emp_tab(i).job as "Job"
    27               )
    28             )
    29      into emp_xml_tab(i)
    30      from dual;
    31 
    32    end loop;
    33 
    34    select xmlelement("EmpInfo", xmlagg(t.column_value))
    35    into emp_info_xml
    36    from table(emp_xml_tab) t ;
    37 
    38    dbms_output.put_line(emp_info_xml.getclobval(1,2));
    39 
    40  end;
    41  /
    <EmpInfo>
      <Emp id="7782">
        <Name>CLARK</Name>
        <Job>MANAGER</Job>
      </Emp>
      <Emp id="7839">
        <Name>KING</Name>
        <Job>PRESIDENT</Job>
      </Emp>
      <Emp id="7934">
        <Name>MILLER</Name>
        <Job>CLERK</Job>
      </Emp>
    </EmpInfo>
    PL/SQL procedure successfully completed
    Both solutions give the same output.
    Test them both and see which one fits better into your scenario.

  • Procedure to insert same record for 30 times in a table using for loop

    Hi,
    I need to insert a record in a table which has to be iterated using for loop

    I think you are in the wrong forum. You can do that like this:
    CREATE TABLE my_table (my_column NUMBER);
    BEGIN
       FOR i IN 1 .. 30
       LOOP
          INSERT INTO my_table
                      (my_column
               VALUES (i
       END LOOP;
    END;
    /Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    http://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • Build 1D array using for loop

    Hi guys,
    I am testing out array. How do I create a 1D array of x-y using for loop?

    Nextal wrote:
    I am testing out array. How do I create a 1D array of x-y using for loop?
    OK, first of all you did not say what the array should contain. If you want an array that has one array element for each iteration of the while loop, you need to first think a bit harder. Your outer loop has no wait, thus it will spin millions of times per second and you will run out of memory soon, no matter how much memory you have. How many times should the while loop iterate? If you know the number before the program starts, you would use a FOR loop and autoindex at the loop boundary.
    If you want to use a whiile loop, you need a mechanism to keep the array size reasonable. For small final arrays, you can just build the array in a shift register if you need it updated as it happens. If you only need the array after the loop stops, you can autoindex at the right loop boundary.
    In any case, you should take a step back and decide what you really want. Currently the specifications are very vague and unreasonable.
    LabVIEW Champion . Do more with less code and in less time .

  • How to iterate List in jsp without using for loop

    Hi,
    I am developing a small application is struts. I have one ActionForm file which contain one List like getEmployeeDetailsList(). When I am using this list in jsp page for displaying data. I want to display it as employee name, employee address, employee designation and employee contact no. These all fields are available in the above list. Now what is the problem is that I am using logic:iterate method to iterate data. but this is not sufficient to display all records in order. like employee name should be in one table and they can be vertical not horizontal, employee address is also should be seperate. and same thing with employee designation and contact no. I don't want to use for loop to iterate this list. Please tell me about optionCollection for this list. only employee names should be one drop down and employee designation is also in another drop down.
    Please help. It is really urgent.
    Any help will be appreciated.
    Thanks in advance.
    Manveer

    I'm not sure what you problem is, but one thing you can do is to create a new class and pass the list into its constructor (and store it as a private variable). Then, provide a set of functions in the new class that extracts data from the list and returns it in a form that the various parts of the JSP page wants. For example, one function may return a sorted list of just the employee names. In this way, all the business logic for formatting the data into a form that JSP page likes is hidden inside the new class.

  • Incrementing var_(x) to var_(y) using FOR loop

    How can i keep incrementing var_(x) to var(y) using FOR loop.
    I want variables var_1 to var_3 displayed. So I tried the below mentioned method. But i got error.
    SQL> set serveroutput on
      declare
         var_1 number;
         var_2 number;
         var_3 number;
        begin
          var_1:=884;
          var_2:=646;
          var_3:=213;
          for i in 1..3 loop
          dbms_output.put_line(var_(i));
          end loop;
       end;
    SQL> /
         dbms_output.put_line(var_(i));
    ERROR at line 10:
    ORA-06550: line 10, column 26:
    PLS-00201: identifier 'VAR_' must be declared
    ORA-06550: line 10, column 5:
    PL/SQL: Statement ignored

    Thank you Padders. I have a complex requirement involving an UPDATE. To avoid unnecessary lines/repeat of UPDATE statements i somehow have to increase the variable number from var_(x) to var_(y)

  • Using Dynamic Query in For Loop

    I have a doubt whether i can use the result from dynamic query in the for loop.
    for example,
    declare
    v_sql varchar2(1000);
    v_Id INTEGER;
    begin
    v_sql := 'select id from table1 where id in ('||v_Id||')';
    FOR i in vsql LOOP
    dbms_output.put_line(i.id);
    end loop;
    end;
    The above query is possible ?

    And here's a basic example of opening up a cursor for your dynamic query...
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_sql varchar2(2000);
      3    v_cur sys_refcursor;
      4    i     emp.sal%type;
      5  begin
      6    v_sql := 'select sal from emp';
      7    open v_cur for v_sql;
      8    loop
      9      fetch v_cur into i;
    10      exit when v_cur%NOTFOUND;
    11      dbms_output.put_line('Salary: '||i);
    12    end loop;
    13* end;
    SQL> /
    Salary: 800
    Salary: 1600
    Salary: 1250
    Salary: 2975
    Salary: 1250
    Salary: 2850
    Salary: 2450
    Salary: 3000
    Salary: 5000
    Salary: 1500
    Salary: 1100
    Salary: 950
    Salary: 3000
    Salary: 1300
    PL/SQL procedure successfully completed.
    SQL>

  • Read data from text file one by one using for loop

    Dear Forum
    I want to read data of single colum of text file inside the for loop one by one(for each iteration value must be replaced by another value of text file).This value is used by a formula inside for loop. also after completion of iterations the values must be plotted on xy graph. How to do it.? please help me.
    profravi

    It's not very efficient to read a file line by line. Much simpler to read it all at once and then auto-index the results inside a for loop. The image below shows a generic solution to your problem. This assumes that the data in the file is in a single column.
    I would also recomend checking ou the learning LabVIEW resources here.
    I would aslos suggest that since this type of question is not specific to either NI-Elvis or the LabVIEW SE, you should post similar questions to the LabVIEW board. If you have problems, attaching a sample of the text file would help.
    Message Edited by Dennis Knutson on 10-18-2007 09:11 AM
    Attachments:
    XY Graph From File.PNG ‏4 KB

  • Geting ORA 936 -while building dynamic query in for loop.

    HI,
    I hav written a SP and its compiled and giving me the results for the data I am quering but giving ORA936 - missing expressin and giving ORA 6512 at 2 lines. Please help me me out where I am going wrong.
    CREATE OR REPLACE TYPE LIST as VARRAY(5000) of NUMBER;
    CREATE OR REPLACE PROCEDURE test( V_id IN LIST,
    v-fdate IN DATE,
    v-tdate IN DATE,
    v_flg IN CHAR)
    AS
    TYPE opfld IS RECORD (
    FID TAB.ID%TYPE,
    FCURR TAB.CURR %TYPE,
    FCNT TAB.CNT%TYPE,
    FTOT TAB.TOT%TYPE );
    TYPE OPLIST IS REF CURSOR;
    Rc oplist;
    Edtab opfld;
    Selstr VACHAR2(200);
    Whstr1 VACHAR2(200);
    Whstr2 VACHAR2(200);
    Whstr3 VACHAR2(200);
    Whstr VACHAR2(200);
    Grpstr VACHAR2(200);
    Andstr VACHAR2(200);
    Fullstr VACHAR2(200);
    BEGIN
    Selstr := ‘SELECT col1,col2,sum(col3),sum(col4) from tab1 ’;
    Whstr1 := ‘ WHERE tdate BETWEEN TO_DATE(‘||’’’’||vfdate||’’’’||’)’;
    Whstr2: = ‘ AND TO_DATE(‘||’’’’||vtdate||’’’’||’)’;
    Whstr := whstr1||whstr2;
    Grpstr := ‘GROUP BY col1,col2’;
    IF v_flg IS NOT NULL THEN
    Whstr3 := whstr||’AND FLAG = ‘||v_flg;
    else
    Whstr3 := whstr ;
    END IF;
    FOR I IN 1..id.COUNT LOOP
    BEGIN
    Andstr := ‘ AND id =’|| v_id(i);
    Whstr := whstr3 || andstr ;
    Fullstr := selstr||whstr||grpstr;
    OPEN rc for fullstr;
    LOOP
    FETCH rc into edtab
    EXIT when rc%NOTFOUND;
    END LOOP;
    Andstr := ‘’;
    Whstr :=’’;
    END; ---BEGIN of FOR loop
    END LOOP; -- for end
    CLOSE rc;
    END; -- proc end
    Created above SP and its compiled. When I try to execute the SP with below code I am getting--
    DECLARE
    V_t LIST;
    BEGIN
    V_t:= LIST();
    V_t.EXTEND(10);
    V_t(1) := 10;
    V_t(2) := 20;
    Test(v_t,’25-APR-2012’,’30-APR-2012’,’Y’);
    END;
    The SP is building correct dynamic querry and its getting executed for id = 10 and 20, giving the correct results but though I defined only 2 ids while executing and written FOR lOOP upto ID.COUNT its building query for third time and that time its not getting id, so for the third time the last part of where clause is built like
    SELECT.....
    WHERE....
    AND id = (its taking blank here)
    GROUP BY ...;
    and thus its giving me ORA 936 missing expression and ORA 06152 at line of RECORD TYPE declaration and line of OPEN rc for fullstr;
    ERROR at line 1
    ORA 00936 misssing expresiion
    ORA 006152 at line 9
    ORA 006512 at line 87
    I hav put DBMS_OUTPUT statements @ every build of dynamic wuery and its correct. here I have not copid the code I hav typed hereso not wriiten DBMS_OUTPUT.
    I tried lot of ways redefining Andstr := ‘’;
    Whstr :=’’; after for endloop but its giving the same error. is this because I am using varray? If am providing 2 ids in anonymous block then how its building query for third blank ID value.
    Please help me out here..
    Thanks a lot..

    >
    I hav written a SP and its compiled and giving me the results for the data I am quering
    >
    Then you should have posted the one that compiles and gives you results.
    The code you posted will not compile without errors. Edit your original post and provide the corrected code.
    When you do please add \ tags on the line before and after the code to preserve formatting. See the FAQ for details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Query Elements Description for a specific query - Useful for Translation

    Hello everyone,
    I would like to know how I can determine a list of all query elements (with their Element ID) within a single query. So, based on a query (technical name), I would like to have a list of all query elements used.
    I would prefer a list of Element IDs, so then I can check if the proper description of each element is available in different languages (in table RSZELTTXT).
    Or if there is a handy tool to check wether all elements are properly translated (and then I don't mean the translation module in the Adlinistration Workbnech, because it is not handy or opening Bex Query designer in different languages), please let me know.
    Kind regards from Belgium,
    Ben De Windt

    Hi,
    Please check for personalization, if the userid has hidden it?
    Regards,
    Harsha

  • How do I use For loop to check each node and import them to a new document?

    In my function I would like to use a For loop to get all the statutes (xml) inside the object
    objXmlBcaResponseDoc. In my case there are 2 statutes. I would like the output to look like the one I have posted here below. I am not sure how to do the For loop. The commented For loop is from another function but it is not working inside
    this function.
    The output is added into the **objXmlResponseMessageDoc** object and should look like this with 2 statutes (ns1:Statute) and a totalCount=2
    <BasicSearchQueryResponse xmlns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0">
    <StatutesXml>
    <Statutes runType="Request" runDateTime="2015-03-17T10:23:04" totalCount="2">
    <ns1:Statute xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0">
    <StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">8471</StatuteId>
    <Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">60</Chapter>
    <Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">55</Section>
    <Subdivision xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
    </ns1:Statute>
    <ns1:Statute>
    <StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">9722</StatuteId>
    <Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">90</Chapter>
    <Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">25</Section>
    <Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
    </ns1:Statute>
    </Statutes>
    </StatutesXml>
    </BasicSearchQueryResponse>
    My xml doc is found inside objXmlBcaResponseDoc Here is xml inside
    objXmlBcaResponseDoc object
    <BasicSearchQueryResponse xmlns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0">
    <ns1:Statutes xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0">
    <ns1:Statute>
    <StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">8471</StatuteId>
    <Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">60</Chapter>
    <Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">55</Section>
    <Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
    </ns1:Statute>
    <ns1:Statute>
    <StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">9722</StatuteId>
    <Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">90</Chapter>
    <Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">25</Section>
    <Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
    </ns1:Statute>
    </BasicSearchQueryResponse>
    Here is my function
    Function GetStatutesByChapter(ByVal aobjXmlGetStatuteRequestNode As XmlNode, ByVal aobjXMLNameSpaceManager As XmlNamespaceManager, ByVal aobjBroker As ServiceCatalog.Library.v4.Broker) As XmlDocument
    Dim objXmlRequestMessageDoc As XmlDocument
    Dim objXmlResponseMessageDoc As XmlDocument
    Dim intCount As Integer
    aobjBroker.PostMessageWarehouseInformationalMessage("Chapter found.", 1)
    objXmlResponseMessageDoc = New XmlDocument
    'Add the first element into the document GetStatuteByChapter with its namespace
    objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("BasicSearchQueryResponse", "http://crimnet.state.mn.us/mnjustice/statute/service/4.0"))
    'Build the initial response document
    objXmlResponseMessageDoc = New XmlDocument
    'Add the first element into the document GetStatutesResponse with its namespace
    objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("GetStatutesResponse", "http://www.courts.state.mn.us/StatuteService/1.0"))
    'Add a child node to the GetStatutesResponse node
    objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.CreateElement("StatutesXml", "http://www.courts.state.mn.us/StatuteService/1.0"))
    objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.CreateElement("Statutes", "http://www.courts.state.mn.us/StatuteService/1.0"))
    'Convert the node Statutes into an element and set the runType attribute (runType="Request") by adding it's value Request
    CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("runType", "Request")
    'Convert the node Statutes into an element and set the attribute (runDateTime="2015-03-05T10:29:40") by adding it
    CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("runDateTime", Format(Now, "yyyy-MM-ddTHH:mm:ss"))
    'Create the BCA request message
    objXmlRequestMessageDoc = New XmlDocument
    objXmlRequestMessageDoc.AppendChild(objXmlRequestMessageDoc.CreateElement("ns:BasicSearchQueryRequest", aobjXMLNameSpaceManager.LookupNamespace("ns")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns1:BasicSearchCriteria", aobjXMLNameSpaceManager.LookupNamespace("ns1")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Chapter", aobjXMLNameSpaceManager.LookupNamespace("st")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Section", aobjXMLNameSpaceManager.LookupNamespace("st")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Subdivision", aobjXMLNameSpaceManager.LookupNamespace("st")))
    'Uncomment last working section below
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Chapter", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Chapter", aobjXMLNameSpaceManager).InnerText
    'check if there is a section and or subdivision if it is there then set the value
    If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager) Is Nothing) Then
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Section", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager).InnerText
    End If
    If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager) Is Nothing) Then
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Subdivision", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager).InnerText
    End If
    'check if there is a section and or subdivision if it is there then set the value
    aobjBroker.PostMessageWarehouseSnapshot(objXmlRequestMessageDoc.OuterXml, "Request Message", 1)
    'Call the BCA service
    intCount = 0
    'This is where I want to use a For loop to check for the statutes found using the Chapter
    'Loop through each Id
    'For Each objXmlStatuteIdNode In aobjXmlGetStatuteRequestNode.SelectNodes("ss:Statute/ss:StatuteId/ss:Id[string-length(.)>0]", aobjXMLNameSpaceManager)
    'Create the BCA request message
    'objXmlRequestMessageDoc = New XmlDocument
    'objXmlRequestMessageDoc.AppendChild(objXmlRequestMessageDoc.CreateElement("ns:SingleStatuteRequest", aobjXMLNameSpaceManager.LookupNamespace("ns")))
    'objXmlRequestMessageDoc.SelectSingleNode("ns:SingleStatuteRequest", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns:statuteId", aobjXMLNameSpaceManager.LookupNamespace("ns")))
    'objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns:statuteId", aobjXMLNameSpaceManager).InnerText = objXmlStatuteIdNode.InnerText aobjBroker.PostMessageWarehouseSnapshot(objXmlRequestMessageDoc.OuterXml, "Request Message", 1)
    'intCount = intCount + 1
    'objXmlBcaResponseDoc = New XmlDocument
    'File name is BCASearchQueryResponse.xml
    'objXmlBcaResponseDoc.Load("\\j00000swebint\mscapps\deve\appfiles\temp\BCASearchQueryResponse.xml")
    'objXmlResponseMessageDoc.DocumentElement.SelectSingleNode("ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.ImportNode(objXmlBcaResponseDoc.DocumentElement.SelectSingleNode("ns1:Statute", aobjXMLNameSpaceManager), True))
    'Next
    'Count how many Statute nodes found
    CType(objXmlResponseMessageDoc.SelectSingleNode("ss:BasicSearchQueryResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("totalCount", CStr(intCount))
    Return objXmlResponseMessageDoc
    End Function

    What is XPath and what does it do that you're impressed with?
    Yes, I see your link, but give me the abbreviated elevator speech on what it is please. It has me curious.
    http://searchsoa.techtarget.com/definition/XPath
    http://www.techrepublic.com/article/easily-navigate-xml-with-vbnet-and-xpath/
    http://www.techrepublic.com/article/using-xpath-string-functions-in-xslt-templates/
    The way that all this is being used by me now on a project is the HTML controls on the screen are built by XML not only about what the controls are and their attributes,   but the data from from the database is XML too with both going through transfermations
    vis XSLT as the HTML controls are built dynamically by XML data for the controls and the XML database data with decision being made in the transfermation on the fly.
    There are many usages with Xpath not just this one I am talking about with Xpath. You can do the same kind of thing with XAML and WPF forms as they are dynamically built. But it goes well beyond what I am talking about and the usage of Xpath. Xpath 3.0
    is the latest version. 
    http://www.balisage.net/Proceedings/vol10/html/Novatchev01/BalisageVol10-Novatchev01.html
    Thanks - I'll look into that at some point.
    Still lost in code, just at a little higher level.

  • How can I make a Java program pyramid using for loops??

    Hi guys, so I'm stuck with my program here... I don't know how to make it work, and i've been trying really hard.. So now i give up and need some guidance.. Please help me here.
    Your job in this assignment is to write programs to solve each of these six problems.
    1. Write a GraphicsProgram subclass that draws a pyramid consisting of bricks
    arranged in horizontal rows, so that the number of bricks in each row decreases by
    one as you move up the pyramid, as shown in the following sample run:
    The pyramid should be centered at the bottom of the window and should use
    constants for the following parameters:
    BRICK_WIDTH The width of each brick (30 pixels)
    BRICK_HEIGHT The height of each brick (12 pixels)
    BRICKS_IN_BASE The number of bricks in the base (14)
    The numbers in parentheses show the values for this diagram, but you must be able
    to change those values in your program.
    * File: Pyramid.java
    * Name:
    * Section Leader:
    * This file is the starter file for the Pyramid problem.
    * It includes definitions of the constants that match the
    * sample run in the assignment, but you should make sure
    * that changing these values causes the generated display
    * to change accordingly.
    import acm.graphics.*;
    import acm.program.*;
    import java.awt.*;
    public class Pyramid extends GraphicsProgram {
    /** Width of each brick in pixels */
         private static final int BRICK_WIDTH = 30;
    /** Width of each brick in pixels */
         private static final int BRICK_HEIGHT = 12;
    /** Number of bricks in the base of the pyramid */
         private static final int BRICKS_IN_BASE = 14;
         public void run() {     
    }That's my problem.

    yo, so i figure out my for loop. my code is very very very very ugly, so dont laugh i know its ugly! just wanna ask for some tips
    public void run() {
              int initBrick = 30;
              int initPlacement = (getWidth() - BRICK_WIDTH) / 2;
              for (int i = 0; i < initBrick; i += 30)
                   int initX = i;
                   int x = initX + initPlacement;
                   GRect brick = new GRect(x, 0, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 60; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 15;
                   int y = 12;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 90; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 30;
                   int y = 24;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 120; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 45;
                   int y = 36;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 150; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 60;
                   int y = 48;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 180; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 75;
                   int y = 60;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 210; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 90;
                   int y = 72;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 240; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 105;
                   int y = 84;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 270; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 120;
                   int y = 96;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 300; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 135;
                   int y = 108;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 330; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 150;
                   int y = 120;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 360; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 165;
                   int y = 132;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 390; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 180;
                   int y = 144;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
              for (int i = 0; i < 420; i += 30)
                   int initX = i;
                   int x = (initX + initPlacement) - 195;
                   int y = 156;
                   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
                   add(brick);
         }So yeah, it's very ugly. not general. BUT now; I know the logic of the program..
    I need to change 3 variables here.
    the Y var, the X variable, and the size of the loop test..
    so I need to make a one compact for loop that will change those 3 for every time the loop finish, or for every row the variable will change...
    Ill try to think again, ill head to the balcony, and squeeze my brain. YEAH it took me this long to figure this out, anyway im a noob YET. But i was working a while ago.
    ANYWAY, leave some tips please.. I NEED TIPS NOT SOLUTION

  • How to use for loops with Multiple Initializers and Incrementers

    I found that my for loop is printing out wrong, because I am using two for loops. I have searched but all I can find out is you can't use multiple inializers and increments, does anyone know how to get around this? How would I use an array for this?
    Thanks very much for your help.
    import java.util.Random;
    import java.util.Arrays;
    /** Generate numnodes value for random integers in the range 0..499. */
    public final class RandomInteger {
    public static final void main(String... aArgs){
    log("Generating 6 random integers in range 0..499.");
    int numnodes = 6;
    //Randomly generate a number between 0 and 499 for the x and y coordinates for the nodes
    Random randomGenerator = new Random();
    for (int x = 0; x < numnodes; ++x) {
    int randomInt = randomGenerator.nextInt(500);
    Random randomGenerator2 = new Random();
    for (int y = 0;y < numnodes; ++y) {
    int randomInt2 = randomGenerator2.nextInt(500);
    log("Generated : " + randomInt + " " + randomInt2);
    log("Done.");
    }

    Sorry that code works, but I want to use both my x and y coordinates to get a random number from 0 to 499 in both of them, then I want to do some comparisons of the values, then return it to another function. As it stands now, I get the wrong results when I run it, as you can see at the bottom.
    Thanks very much for your help. I have been stumped all mornign on this and have looked everywhere trying to find an example. I don't won't to use math random. I am on a tight deadline to finish and at the rate I am going, I will not complete it.
    /** Generate numnodes value for random integers in
    the range 0..499. */
    public final class RandomInteger {
    public static final void main(String... aArgs){
    log("Generating 6 random integers in range
    0..499.");
    int numnodes = 6;
    //Randomly generate a number between 0 and 499 for
    the x and y coordinates for the nodes
    Random randomGenerator = new Random();
    for (int x = 0; x < numnodes; ++x) {
    int randomInt = randomGenerator.nextInt(500);
    Random randomGenerator2 = new Random();
    for (int y = 0;y < numnodes; ++y) {
    int randomInt2 = randomGenerator2.nextInt(500);
    log("Generated : " + randomInt + " " + randomInt2);
    log("Done.");
    private static void log(String aMessage){
    System.out.println(aMessage);
    Output:
    --------------------Configuration:
    <Default>--------------------
    Generating 6 random integers in range 0..499.
    Generated : 98 254
    Generated : 98 347
    Generated : 98 359
    Generated : 98 25
    Generated : 98 277
    Generated : 98 148
    Generated : 416 401
    Generated : 416 165
    Generated : 416 354
    Generated : 416 169
    Generated : 416 144
    Generated : 416 354
    Generated : 295 158
    Generated : 295 138
    Generated : 295 349
    Generated : 295 324
    Generated : 295 18
    Generated : 295 193
    Generated : 197 451
    Generated : 197 416
    Generated : 197 480
    Generated : 197 33
    Generated : 197 490
    Generated : 197 494
    Generated : 324 412
    Generated : 324 490
    Generated : 324 213
    Generated : 324 386
    Generated : 324 467
    Generated : 324 163
    Generated : 379 180
    Generated : 379 446
    Generated : 379 314
    Generated : 379 52
    Generated : 379 113
    Generated : 379 271
    Done.
    Process completed.

Maybe you are looking for

  • Can 10g Express be installed on a machine that has MS SQL2000/2005?

    I just discovered the 10g Express edition and I have been wanting to learn and work with Oracle for some time now so this is awesome. I have a Windows 2003 Server here at my house that currently has both Microsoft SQL 2000 and Microsoft SQL 2005 deve

  • Problem with ORACLE 10g on VirtualBox ....

    Hi, Currently, I installed an instance of ORACLE 10g on Virtual Server with Windows Server 2K3 Enterprise x86, but after to turn off o restart the virtaul Machine, areceived an error of ORACLE "ORA-12514"... I had created the virtual server 3 times b

  • Missing scroll bar in browser

    Hi, I got a very simple flex app which has a height that is bigger than the default height of the web browser. When it was run in a browser (had been maximized and both IE and FF had the same problem), sadly there was no scroll bar and thereby the bo

  • Why isn't the Submit button submitting responses?

    I created an evaluation form using Forms Central and distributed it. 4/5 respondents filled it out with no problems. The last person filled it out twice and lost her responses once through an error on her end and the second time she doesn't know why

  • Please help, DVD not playing in Mac that burnt t

    I recently bought an iMac Core duo 17in. I finished my first project in iDVD and everything looked fine when I previewed in iDVD (I used slideshows exported from iPhoto as movies). Then I burnt it to a Fujifilm DVD+R. The process went smoothly and wh