Looping through a set of data

seq     |     id|     Name|     TotalPc
1     |     22|     ABA |     20
1     |     23|     ABB |     20
2     |     24|     ABC |     20
3     |     25|     ABD |     20
3     |     26|     ABE |     20
3     |     27|     ABF |     20
4     |     28|     ABG |     20
5     |     29|     ABH |     20
6     |     30|     ABI |     20
6     |     31|     ABJ |     20
6     |     32|     ABK |     20
6     |     33|     ABL |     20The above result is returned in a resultset. What i would like to achieve is store these rows in an object that is structured as shown below
public class Name{
     String seq
     String name;
     Arraylist namePcs = new ArrayList()
public class NamePcs{
     String id;
     String totalPcs;
}Now as you can see in the data, some of the rows belong to the same element. For example, all those with seq=6 should be stored in the same object because they below to the same group i.e. 6.
I tried several combinations of approaches but i always seem to either miss the last one, duplicate them or exhaust the resultset.
Here are some examples of what i tried to do.
Example 1 - This example copies every name into every element.
while(rs.next()){
     Name name = new Name();
     name.seq = rs.getString("seq");
     name.name = rs.getStrign("name");
     NamePcs namePcs= new NamePcs()
     namePcs.id = rs.getString("id");
     namePcs.totalPcs = rs.getString("totalPcs")
     name.namePcs.add(namePcs);
seq_no = rs.getString("seq");
}Example 2 - In this example i try to save the child elements only if the seq number is the same but i still get duplicates.
String seq_no = "";
while(rs.next){
     if(!seq_no.equals(rs.getString("seq_no"){
               Name name = new Name();
               name.seq = rs.getString("seq");
               name.name = rs.getStrign("name");
     if(seq_no.equals(rs.getString("seq_no");{
          NamePcs namePcs= new NamePcs()
          namePcs.id = rs.getString("id");
          namePcs.totalPcs = rs.getString("totalPcs")
          name.namePcs.add(namePcs);
seq_no = rs.getString("seq");
}I also tried an inner while loop with an inner rs.next() but that exhausts the resultset. Is there a better way to do this? Thansk in advanc.e
Edited by: ziggy on Sep 23, 2008 9:10 AM

Hi,
Sorry for not being clear enough. The above was just a quick example to try and show what i am trying to achieve.
What i am trying to achieve is to store the data in objects. The data itself has a one to many relationship. This means that many names will be related to the same sequence number. I would like to store the common names (i.e. those with the same seq no) in the same object in an arraylist.
Maybe this data structure makes more sense
public class seq{
     String seq     
     Arraylist namePcs = new ArrayList() //will contain all names with the same sequence
public class NamePcs{
     String id;
     String name;
     String totalPcs;
}What im hoping to achieve is the following
- The seq object will contain one seq row (either 1,2,3,4,5,6)
- Array list in the seq object should contain all the rows for each individual seq.
- As an example if seq[3].seq = 6, the seq.namePcs() should contain all NamePcs objects tha t have id's (30,31,32,33).
Here is what i am hoping to achieve as the end result (for the first 6 rows)
seq[0]
     seq = 1
     namePcs[0]
          id = 22
          name = ABA
          TotalPcs = 20
     namePcs[1]
          id = 23
          name = ABB
          TotalPcs = 20
seq[1]
     seq = 2
     namePcs[0]
          id = 24
          name = ABC
          TotalPcs = 20
seq[2]
     seq = 3
     namePcs[0]
          id = 25
          name = ABD
          TotalPcs = 20
     namePcs[1]
          id = 26
          name = ABE
          TotalPcs = 20
     namePcs[1]
          id = 27
          name = ABF
          TotalPcs = 20               I hope that made it a bit clear.
Thanks
Edited by: ziggy on Sep 23, 2008 9:41 AM

Similar Messages

  • Loop through a range of data

    Hi guys
    I have this set of numbers. 54 55 56 58 59 61 64 66. I want to loop through this set of number to give an array of result of 54 55 56 0 58 59 0 61 0 0 64 0 66.
    Simply, i am trying to insert zero into the blank of the +1 interval in this set of number. I could not figure out how to do this.
    Please help me thank you
    Cheers
    PX
    Solved!
    Go to Solution.

    Hi pengxin,
    see the attached image.
    Mike
    Attachments:
    Insert0.PNG ‏8 KB

  • Problem while looping through record set and tem table for matching data

    hi I am using one record set and ane temp table and looping through both to find the match between dates.
    If date matches then it shud do some processing otherwise it will return default values(null values).
    FOR i IN student_rec .FIRST..student_rec .LAST          /*student_rec.school_date has 01-MAR-2012,02-MAR-2012,03-MAR-2012,04-MAR-2012,05-MAR-2012*/
    LOOP
    l_return_out.school_date := student_rec(i).school_date;
    l_return_out.marks_obtained := student_rec(i).marks_obtained;
    FOR i IN selected_dates .FIRST..selected_dates .LAST          /*selected_dates has 02-MAR-2012,03-MAR-2012,05-MAR-2012*/
    LOOP
    DBMS_OUTPUT.PUT_LINE(selected_dates(i));
    IF selected_dates(i)=student_rec(i).sett_date
    THEN
    EXIT;
    end if;
         ---------call procedure P1
    -----------get output as ret_val1               /*getting ret_val1 as 10 for 02-MAR-2012,03-MAR-2012,05-MAR-2012 */
         ----------call procedure P2
    ---------get ouput as ret_val2               /*getting ret_val1 as 20 for 02-MAR-2012,03-MAR-2012,05-MAR-2012 */
    if ret_val1>0 0r ret_val2>0
    then
    l_return_out.has_csts := yes;
    l_return_out.cst_present := 10;
    l_return_out.cst_absent := 20;
    else
    l_return_out.has_csts :=No;
    l_return_out.cst_present:= 0;
    l_return_out.cst_absent := 0;
    end if;
    end loop;
    l_return_out.has_cst := student_rec(i).has_csts;
    l_return_out.cst_missing := student_rec(i).cst_present;
    l_return_out.cst_existing := student_rec(i).cst_absent;
    PIPE ROW(l_return_out);
    END LOOP;
    RETURN ;
    I am expecting this as result
    school_date     marks_obtained     has_csts     cst_present cst_absent
    01-MAR-2012     20          
    02-MAR-2012     30          yes 10          20
    03-MAR-2012     40           yes 10          20
    04-MAR-2012     70          
    05-MAR-2012     60          yes 10          20
    but this as result
    school_date     marks_obtained     has_csts     cst_present cst_absent
    01-MAR-2012     20          
    02-MAR-2012     30          
    03-MAR-2012     40           
    04-MAR-2012     70          
    05-MAR-2012     60          
    Can anybody please highlight the mistake i am doing while processing the logic??
    Edited by: 942390 on Jul 13, 2012 8:44 PM
    Edited by: 942390 on Jul 13, 2012 8:45 PM

    I am getting a set values from a record set....student_rec
    and on pipelining this record set from 1st till last
    i am getting this
    school_date     marks_obtained     has_csts     cst_present cst_absent
    01-MAR-2012     20          
    02-MAR-2012     30          
    03-MAR-2012     40           
    04-MAR-2012     70          
    05-MAR-2012     60     
    so initially has_csts, cst_present and cst_absent is null for all dates.
    now have a temp table of selected_dates(which contains these dates 02-MAR-2012,03-MAR-2012,05-MAR-2012)
    now I am want to populate has_csts, cst_present and cst_absent with data only for those dates which is present in selected_dates temp table(02-MAR-2012,03-MAR-2012,05-MAR-2012) and that too has_csts, cst_present and cst_absent will be populated with some condition (based on the values from procedure got from P1 and P2).
    so want result set to look like
    school_date     marks_obtained     has_csts     cst_present cst_absent
    01-MAR-2012     20          
    02-MAR-2012     30          yes 10          20
    03-MAR-2012     40           yes 10          20
    04-MAR-2012     70          
    05-MAR-2012     60          yes 10          20
    so what could be the possible solution to obtained this....

  • Nested Loops...looping through one month of data at a time year by year

    Hi all,
    I'm trying to create an insert statement that loops through a table that has 10 years of data (2001 to 2010) month by month to minimize impact on server and commits more frequently to avoid filling up the redo logs and rollback tablespaces. The table is large, has about 40 millions records per year. Lets say the structure of the table is the following:
    Customer_ID number(9),
    Order_Item_1 number(6),
    Order_Item_2 number(6),
    Order_Item_3 number(6),
    Order_date date
    The table is in flat format but I want to normalize it so that it looks like the following:
    Customer_ID Order_Seq Order_Item Order_date
    999999999 1 555555 01-jan-2001
    999999999 2 666666 01-jan-2001
    999999999 3 444444 01-jan-2001
    888888888 1 555555 03-jan-2001
    888888888 2 666666 03-jan-2001
    But because I want to loop through month by month....I need to set it up so that it loops through month by month, year by year (Using the Order Date Field) and Order_item by Order_item. Something like:
    so my insert statements would be something like if I hardcoded instead of put the insert statement into a loop:
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,1,Order_item,Order_date where Order_item_1 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='01';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,2,Order_item,Order_date where Order_item_2 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='01';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,3,Order_item,Order_date where Order_item_3 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='01';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,1,Order_item,Order_date where Order_item_1 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='02';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,2,Order_item,Order_date where Order_item_2 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='02';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,3,Order_item,Order_date where Order_item_3 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='03';
    Hope this makes sense.
    Thanks

    Does the sequence of items in an order really matter? In other words, do we really need to preserve that an item was in position 2 versus position 1? I bet that the sequence or position of each item in an order is not meaningful. They were probably numbered 1, 2, and 3 just to make them uniquely named columns so there would be three slots to hold up to 3 items in the denormalized table.
    You only have about 400 million rows to insert, so it could feasibly be done in a single transaction (depending on your database environment).
    You can always do a create table as select (CTAS) to help with undo / redo issues and get better performance. You could run it in parallel, and spit it out to a new table partitioned by month. Single DDL statement running in parallel making your new table--sounds good to me.
    How about something like this:
    CREATE TABLE ORDERS_NORMALIZED
    (CUSTOMER_ID, ORDER_ITEM, ORDER_DATE)
    PARTITION BY RANGE(ORDER_DATE)
    PARTITION p200901 VALUES LESS THAN (TO_DATE('200902','YYYYMM')),
    PARTITION p200902 VALUES LESS THAN (TO_DATE('200903','YYYYMM')),
    PARTITION p201012 VALUES LESS THAN (TO_DATE('201101','YYYYMM'))
    as SELECT CUSTOMER_ID, ORDER_ITEM_1, ORDER_DATE
       FROM OTHER_TABLE
       WHERE ORDER_ITEM_1 IS NOT NULL
       UNION ALL
       SELECT CUSTOMER_ID, ORDER_ITEM_2, ORDER_DATE
       FROM OTHER_TABLE
       WHERE ORDER_ITEM_2 IS NOT NULL
       UNION ALL
       SELECT CUSTOMER_ID, ORDER_ITEM_3, ORDER_DATE
       FROM OTHER_TABLE
       WHERE ORDER_ITEM_3 IS NOT NULL.....................
    Out of curiosity, why not normalize it further? You could have used two tables instead of one.
    One (ORDER) with:
    ORDER_ID
    CUSTOMER_ID
    DATE
    Order_id would be a new surrogate key / primary key.
    Another table (ORDER_ITEM) with:
    ORDER_ID
    ORDER_ITEM
    It would be a table that links ORDERS to ITEMS. You get the idea.

  • Loop through tables based on data dict values

    Hi,
    I working on an old v7.3.4 database that I'm not familiar with and I want to loop through the tables and count the occurrence of a field value based on table names i've retrieved from the data dictionary. None of the tables have relational keys defined.
    In a cursor I can loop thru all_tab_columns and load variables with the table, column names, and the datatype, but then I want to use these values in a second nested cursor to loop through each table found by the first cursor.
    When I do :
    Select var_colname from var_tabname
    i get
    The following error has occurred:
    ORA-06550: line 23, column 10:
    PLS-00356: 'V_TABNAME' must name a table to which the user has access
    ORA-06550: line 22, column 5:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 22, column 12:
    PLS-00320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 27, column 7:
    PL/SQL: SQL Statement ignored
    so it would seem I can't use a variable to substitute the table name in the 'from' clause. Does anyone know of a way round this ?
    Thanks in advance

    Hi,
    You will have to use dynamic sql to create your second cursor.
    DECLARE
         v_sql_query VARCHAR2(400);
         TYPE cur_typ IS REF CURSOR;
         c1 cur_typ;
         mYRec MyTable%rowtype;
    BEGIN
         v_sql_query := 'select * from MyTable';
         OPEN c1 FOR v_sql_query;
              LOOP
              FETCH c1 INTO mYRec;
                   EXIT WHEN c1%NOTFOUND;
                   EXIT WHEN c1%NOTFOUND IS NULL;
    /*processing here*/
              END LOOP;
         CLOSE c1;
    END;
    Regards

  • Loop through result set and delete row

    so here is what I need -
    I have a query that pulls rows from the Database through a stored procedure.(these are properties in an area)
    Before I start looping through the query, I need to check the distance between my current location and the property. If it less than 5 miles, only then should I display that property. The distance in miles will be chosen while submitting the search form.
    So is there a way to delete rows from the result set based on the criteria? Or
    Is there a better way to accomplish this? I am using the the google api to get the latitudes and longitudes. The other issue to keep in mind is the load time.
    Thanks

    You can do this the easy way or the hard way.  Depends on whether your condition that needs to be checked can be expressed in the form of a SQL where clause.  If it can, then do what BKBK suggested, and use a query of query to create a new resultset that only has the rows from the original resultset that don't meet your condition.
    If the calculation of the condition is more complex, then do a CFLOOP over the query and examine each row to see if you want to keep it or toss it.  if you want to toss it, the delete that row - there is a function in CFLIB.ORG called querydeleterow that should help you.  Or, you could just clear out the row's contents and then do the query of query as described in BKBK's post to create a new resultset that doesn't include the blank rows.

  • Looping through result set

    Hello, I am experience a heapdump while looping through a result set from a query I amr unning.
    Our system creates an instance of a transfer object representing one row in the result set for each row as it loops through. The result set brings back 36000 rows, so it is creating 36000 objects. As a result, a heapdump is occurring. What can be done to fix this error?

    even if it holds 360000 rows,
    I still think [zadok] idea is a great idea.
    you can get, for example first 1000 rows, cacluate it save result, and then get the next 1000 rows, is it make sense?
    if you still want to get it by one time, extend your vm mem, normal setting is 64M(I am not sure)

  • Extra Space coming while looping through Hash Set in JSP: URGENT

    Hi,
    I have to loop through the Hash Set in jsp, and display the contents with a comma seperated list.
    I am able to display the values withing the set, however.. after every value,
    i am getting an extra space and then a comma. How do i get rid of this extra space?
    Below is the code snippet
    <% Set tagSet = new HashSet();
         tagSet = (Set)request.getAttribute(PhotoConstants.REQ_RELATED_TAGS);     
         Iterator i = tagSet.iterator();     
         while(i.hasNext()){
         String tagName=(String)i.next();
    %>
    <a href="/outlook/photo/keywords?keywords=<%=URLEncoder.encode(tagName)%>"><%=tagName%></a>
    <%if(i.hasNext()==true){%>,<%}%>
    <%}%>
    I am getting following output:
    NY , sky , Sports & Recreation , clouds , New York City , New York
    Expected Output:
    NY, sky, Sports & Recreation, clouds, New York City, New York
    I want space after a comma, not befor comma...
    Any help is really appreciated..
    Thanks
    Deepti

    <% while(i.hasNext()) {
        String tagName=(String)i.next(); %>
        <a href="/outlook/photo/keywords?keywords=<%=URLEncoder.encode(tagName)
        %>"><%=tagName%></a><%if(i.hasNext()==true){ %>,<% } %>
    <% } %>I think this is an html whitespace thing... try moving your code around to look like what's above (ie move the end of line to inside your scriptlet tag)
    Code looks OK...

  • Loop through files locating specific data sets

    Hi there,
    I have been given the wonderful task of developing a setup which needs to do the following using JCAPS:
    - open and read through various flat files in a folder. These flat files have random data sets in them, where a line starting with 01, marks the start of a data set and 99, marks the end of a data set. 03, marks the line where the account number can be found.
    - retrieve the account number from the data sets and verify that against an external Oracle database table.
    - if account number is found, then read the data set from the flat file and write the data set to an output file.
    - if the account number is not found in the Oracle database table, just discard the dataset and continue with the next data set.
    If you have any ideas on how to set this up, that would be much appreciated. No need to spell things out, but if anyone has worked on a scenario like this or similar using JCAPS to do the trick please let me know.
    A scenario variant is that, instead of looking up the account number against the oracle database, we can use an if-statement like "if the currency is GBP, EUR, SEK, then take the data set from the input file and write the data set to the output file.
    I can create an input OTD to read in the data sets, and an output OTD which creates the output file. There is a blank line between data sets. The structure of a data set looks like this:
    01,CITIDIRECT,2978169,080922,0401,04010900,999,,2/
    02,2978169,400515,1,080919,0000,USD,2/
    03,57787314,USD,010,2191397371,,,015,2191397371,,,030,2191397371,,,040,2191397371,,,045,2191397371,,,060,2191397371,,,072,000,,,074,000,,,100,000,0,,400,000,0,,470,000,0,/
    49,13148384226,2/
    03,57787322,USD,010,1494730626,,,015,1494730626,,,030,1494730626,,,040,1494730626,,,045,1494730626,,,060,1494730626,,,072,000,,,074,000,,,100,000,0,,400,000,0,,470,000,0,/
    49,8968383756,2/
    03,57787349,USD,010,423382915,,,015,423382915,,,030,423382915,,,040,423382915,,,045,423382915,,,060,423382915,,,072,000,,,074,000,,,100,000,0,,400,000,0,,470,000,0,/
    49,2540297490,2/
    98,24657065472,3,8/
    99,24657065472,1,10/
    Thanks & Kind Regards,
    Richard

    Yes
    1. Have a variable inside SSIS to get folder path. Set path based on your rule using an expression
    like
    (@[User::ProductName] == "Product" ? "\\....\Src\Product" : (@[User::ProductName] == "Product_NCP" ? \\....\Src\Product_NCP:..))
    similary archive
    (@[User::ProductName] == "Product" ? "\\....\Src\Product\Archive" : (@[User::ProductName] == "Product_NCP" ? "\\....\Src\Product_NCP\Archive" :..))
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Perl API: growing memory problem in loops over large sets of data

    Hi,
    When going through all XmlResults like this:
    while ($results->next($val)) {
    print $val->asString, "\n";
    The process size keeps growing. It does not when I comment $val->asString method out, but then I have no way of getting the results.
    This becomes a significant problem when the number of results is huge. I am doing this on a database of over a million short XML documents (400-800 bytes each).
    The more complete code is here:
    eval {
    $env = new DbEnv();
    $env->open($dbDir, Db::DB_JOINENV | Db::DB_INIT_LOCK
    | Db::DB_INIT_MPOOL | Db::DB_CREATE, 0);
    my $mgr = new XmlManager($env, DbXml::DBXML_ADOPT_DBENV);
    my $db = $mgr->openContainer(undef, $dbName, Db::DB_RDONLY);
    my $context = $mgr->createQueryContext(XmlQueryContext::LiveValues,
    XmlQueryContext::Lazy);
    my $lookup = $mgr->createIndexLookup($db, "", $nodeName,
    "node-$nodeType-equality-$syntax",
    new XmlValue($types{$nodeType}, $value), XmlIndexLookup::GTE);
    my $results = $lookup->execute(undef, $context);
    my $val = new XmlValue();
    while ($results->next($val)) {
    print $val->asString, "\n";
    if (my $e = catch std::exception) {
    die $e->what() . "\n";
    The process size just grows until the system limit is reached, then the process quits saying 'Out of memory'.
    I suspect the problem is with the std::string result returned by C++ XmlValue::asString() const.
    The (left-hand-side) result string is likely allocated by new std::string and receives the value by calling the string copy operator. Then the Perl scalar result is prepared, but when it gets returned to my code, the C++ string is not deleted.
    Moving the Sleepycat::XmlValue Perl object inside the loop does not help either:
    while ($results->hasNext()) {
    my $val = new XmlValue();
    $results->next($val);
    print $val->asString, "\n";
    In fact, the process seems to grow faster, possibly because the old $val instances do not get destroyed by Perl at the end of the loop. Where is Perl's garbage collection?
    I am using DB XML version: 2.2.13; BDB version: 4.4.20.2; OS: FreeBSD 6-STABLE. However the problem seems to be common for any OS or BDB XML version as it involves Perl-to-C++ interface.
    Has anyone experienced similar problems?
    Thanks,
    Konstantin.
    Konstantin @ Chuguev.com

    Good catch - you found a memory leak. Luckily the fix is very straightforward. Edit the file
    dbxml/src/perl/common.h
    and find this line
    #define newSVfromString(str) newSVpvn(str.c_str(), str.length())
    Change it to this
    #define newSVfromString(str) sv_2mortal(newSVpvn(str.c_str(), str.length()))
    and recompile the module.
    Paul

  • Need a Firefox script to loop through a set of web pages

    Hi all,
    I was wondering if anyone had come across a script for this purpose?
    I need to power on a PC of mine, have it automatically start Firefox on startup (easy so far) then load a "loop" of predefined internal web pages that it keeps up on-screen for, say 5 seconds each webpage (5 pages in total that it would flick through)
    Is it also possible to script or force Firefox to open in Full screen mode?
    Thanks in advance,
    Chris

    Sounds more like you want a slide show, the only difference is if any of those web pages change. Quick check of addons: '''slide show seconds'''
    '''[http://example.com Tab Slideshow]''' (13.3 KB) :: Add-ons for Firefox
    -- Cycles through tabs as a slideshow. A minimalist extension that offers a configurable time to automatically switch to and display the next tab (and wrap around from the last to the first tab). The slideshow can be customized to auto-refresh tabs, as well as go into slideshow immediately when you open the browser. Extension offers a configurable time to automatically switch to and display the next tab (and wrap around from the last to the first tab).
    Quick HOW TO: To start and stop the slideshow, find the "Start Tab Slideshow" menu item under the "Tools" menu (or with Firefox 4 on recent Windows versions, the orange Firefox app button). To change delay and refresh settings, go to the Add-ons Manager, find the extension in the list, and click the Options button (or "Preferences" on a Mac).
    When in full screen, you can start/pause the slideshow by pressing ALT+T, and then T. (ALT+T: Open "Tools" menu; T: Start Tab Slideshow)
    https://addons.mozilla.org/firefox/addon/tab-slideshow/

  • Loop Through Date Range

    Hi guys,
    I have date range as parameter like 01/JAN/2009 TO 16/JAN/2009 now i want to loop through this date range and want to get date like
    01/JAN/2009,02/JAN/2009.....16/JAN/2009.how can i achive this ?
    Thanks
    Ron

    Hi,
    What do you mean by loop through?
    SQL> with dates as (select to_date('01/JAN/2009', 'dd/mm/yyyy') start_date
                         ,to_date('16/JAN/2009', 'dd/mm/yyyy') end_date from dual)
    select start_date + level - 1 from dates connect by level <= end_date - start_date + 1
    START_DATE
    01/01/2009
    02/01/2009
    03/01/2009
    04/01/2009
    05/01/2009
    06/01/2009
    07/01/2009
    08/01/2009
    09/01/2009
    10/01/2009
    11/01/2009
    12/01/2009
    13/01/2009
    14/01/2009
    15/01/2009
    16/01/2009
    16 rows selected.Regards
    Peter

  • How to loop through dates using For Loop?

    Hi All,
    I assume the For Loop is the best way to loop through days in a date range, but I can't figure out how to add a day in the "AssignExpression" box.  The following gets the errors "The expression contains unrecognized token 'DAY'",
    and "Attempt to parse the expression 'DATEADD(DAY, 1, @CounterPlayer)' failed and returned error code 0xC00470A4."
    InitExpression: @CounterPlayer = @DownloadFileDatePlayer
    EvalExpression: @CounterPlayer <= @Today
    AssignExpression: @CounterPlayer = DATEADD(DAY, 1, @CounterPlayer)
    I need to step through days, not through files.  What am I doing wrong here?  I changed "DAY" to "Day," but that didn't fix it.
    Thanks,
    Eric

    DOH!  It just needed properly placed quotes.  Here's the answer:
    AssignExpression: @CounterPlayer = DATEADD("DAY", 1, @CounterPlayer)

  • How to loop through columns of a table?

    Hi, guys
    Is there a way to loop through each column of a table? If there is a way, then how?
    I have a table with columns of different datatypes , and I want to set default values for each column with a loop but don't know how to make it happen.
    For example,
    Table: Employees
    declare
      rec  Employees%ROWTYPE;
    begin
      for col in rec.empno .. rec.location loop
         if col = rec.empno then -- set default value for column empno;
      end loop;
    end;
    /Sorry, I am a newbie to PL/SQL. Please help!
    Thanks in advance.
    Edited by: HappyJay on 2010/05/11 10:36

    Hi,
    You can query the data dictionary views all_tab_columns (or user_tab_columns) to get the names of all the columns in a particular table.
    Here's an easy way (but not a very efficient way) to loop through them:
    SET     SERVEROUTPUT     ON
    BEGIN
         FOR  c IN ( SELECT  column_name
                         FROM    all_tab_columns
                  WHERE   owner     = 'SCOTT'     -- Remember ot use UPPER CASE inside quotes
                  AND         table_name     = 'EMP'
         LOOP
              dbms_output.put_line (c.column_name || ' = column_name inside loop');
         END LOOP;
    END;
    /I'm confused about what you want to do, though.
    Do you want the PL/SQL code to write and/or execute an ALTER TABLE command for each column?

  • Automator - Loop through a text file and process data through a 3rd party software

    Just stumbled on Automator the other day (I am a mac n00b) and would like to automate the processing of a text file, line-by-line, using a third party tool.  I would like Automator to loop through the text file one line at a time, copy the string and keep as a variable.  Next, place the variable data (copied string) into the text field of the 3rd party software for processing.  Once the processing is complete, I would like Automator to fetch the next line/string for processing.  I see items like "copy from clipboard" and  "variables" within the menu but I am not finding much documentation on how to utilizle this tool.  Just hear how potentially powerful it is. 
    The 3rd party software is not a brand name, just something made for me to process text.  I may have to use mouse clicks or tabs + [return] to navigate with Automator.  A term I heard on Bn Walldie's itunes video series was "scriptable software" for which I don't think this 3rd party app would be. 
    Kind regards,
    jw

    Good news and bad news...
    The good news is that it should be entirely possible to automate your workflow.
    The bad news is that it will be a nightmare to implement via Automator, if it's even possible.
    Automator is, essentially a pretty interface on top of AppleScript/Apple Events, and with the pretty interface comes a certain stranglehold on features. Knowing how to boil rice might make you a cook, but understanding flavor profiles and ingredient combinations can make you a chef, and it's the same with AppleScript and Automator. Automator's good at getting you from points A to B but if there are any bumps in the road (e.g. the application you're using isn't scriptable) then it falls apart.
    What I'm getting at is that your requirements are pretty simple to implement in AppleScript because you can get 'under the hood' and do exactly what you want, as opposed to Automator's restricted interface.
    The tricky part is that if no one else can see this app it's going to be hard to tell you what to do.
    I can give you the basics on reading a file and iterating through the lines of text in it, and I can show you how to 'type' text in any given application, but it may be up to you to put the pieces together.
    Here's one way of reading a file and working through each line of text:
    -- ask the user for a file:
    set theFile to (choose file)
    -- read the file contents:
    set theFileContents to (read file theFile)
    -- break out the lines/paragraphs of text:
    set theLines to paragraphs of theFileContents
    -- now iterate through those lines, one by one:
    repeat with eachLine in theLines
      -- code to perform for eachLine goes here
    end repeat
    Once you have a line of text (eachLine in the above example) you can 'type' that into another application via something like:
    tell application "AppName" to activate
    tell application "System Events"
              tell process "AppName"
      keystroke eachLine
              end tell
    end tell
    Here the AppleScript is activating the application and using System Events to emulate typing the contents of the eachLine variable into the process. Put this inside your repeat loop and you're almost there.

Maybe you are looking for