Query or Loop

Hi,
I need help or suggestions in writing a pl/sql loop query against the data in Table A in order to get the output of Table B.
Table A               
id     type     valu     
1     a     x     
1     a     y     
1     a     x     
1     b     3     
1     c     33     
2     a     x     
2     b     55     
2     c     33     
The output should be inserted in a new table.The expected output
Table B output               
id     list_a     List_B     List_C
1     x,y,x     3     33
2     x     55     33
Thanks

Try this
SQL> with t
  2  as
  3  (
  4  select 1 id, 'a' type, 'x' value from dual union all
  5  select 1 id, 'a' type, 'y' value from dual union all
  6  select 1 id, 'a' type, 'x' value from dual union all
  7  select 1 id, 'b' type, '3' value from dual union all
  8  select 1 id, 'c' type, '33' value from dual union all
  9  select 2 id, 'a' type, 'x' value from dual union all
10  select 2 id, 'b' type, '55' value from dual union all
11  select 2 id, 'c' type, '33' value from dual
12  )
13  select id, max(decode(type, 'a', value)) list_a, max(decode(type, 'b', value)) list_b, max(decode(type, 'c', value)) list_c
14    from (
15            select id, type, max(value) value
16              from (
17                      select id, type, ltrim(sys_connect_by_path(value, ','),' ,') value
18                        from (
19                               select t.*, row_number() over(partition by id, type order by 1) rno
20                                 from t
21                             )
22                       start with rno = 1
23                      connect by rno = prior rno + 1
24                         and id = prior id
25                         and type = prior type
26                   )
27             group by id, type
28         )
29   group by id
30  /
        ID LIST_A     LIST_B     LIST_C
         1 x,y,x      3          33
         2 x          55         33
SQL>

Similar Messages

  • Urgent - I have written select query between loop and endloop, Ple help out

    Can any one help out me on this select query. I have written select query between loop and endloop. When I execute the program it will take too much time in this query. Please help me out. Its very urgent.
    LOOP AT l_i_invoices ASSIGNING <l_invoices>.
          CLEAR alv_wa.
          alv_wa-bukrs = <l_invoices>-bukrs.
          alv_wa-gsber = <l_invoices>-gsber.
          CLEAR l_instid.
          CONCATENATE <l_invoices>-belnr <l_invoices>-gjahr INTO l_instid.
          SELECT top_wi_id FROM sww_wi2obj INTO TABLE l_i_swwwihead
                  WHERE catid   = c_catid_business_object
                    AND instid  = l_instid
                    AND typeid  = c_typeid_invoice
                    AND removed = space
                    AND ( wi_rh_task = c_task_buyer_message
                       OR wi_rh_task = c_task_buyer_message2 ).
          IF sy-subrc = 0.
            <l_invoices>-flag = 'X'.
          ELSE.
            <l_invoices>-flag = ' '.
          ENDIF.
          MODIFY l_i_invoices FROM <l_invoices> TRANSPORTING flag
                                WHERE belnr = <l_invoices>-belnr
                                   AND gjahr = <l_invoices>-gjahr.
          APPEND alv_wa TO i_alv.
        ENDLOOP.
    Thanks in advance.

    Here is a way to solve this problem.
    Choose somewhere before this loop processing to use that select. Therefore, you'll need use FOR ALL ENTRIES <that_loop_table> clause, and in the WHERE condition you need to specify that same fields.
    This way, you will have an internal table with all data you'll need to check.
    Then, inside your loop statement, use the READ TABLE command with the clause WITH KEY field = value, to read that record and use the value found.
    Like this sample:
      SELECT bukrs lifnr umsks umskz augdt augbl zuonr gjahr belnr buzei
             waers xblnr blart gsber ebeln zfbdt zbd1t zlsch
      INTO TABLE tg_bsak
      FROM bsak
      FOR ALL ENTRIES IN tl_bkpf_sel
      WHERE bukrs EQ tl_bkpf_sel-bukrs AND
            lifnr IN s_lifnr AND
            augbl EQ tl_bkpf_sel-belnr.
    LOOP AT tg_bseg INTO wa_bseg.
        READ TABLE tg_bsak INTO wa_bsak WITH KEY bukrs = wa_bseg-bukrs
                                                 gjahr = wa_bseg-gjahr
                                                 belnr = wa_bseg-belnr
                                                 BINARY SEARCH.
    if sy-subrc = 0.
    * do something
    endif.
    ENDLOOP.

  • Query about loops in an APEX calendar...

    Hi everyone,</br></br>
    I would like to know how to make a loop with the following settings:</br></br>
    1. I have a calendar on Application Express 3.0.1.00.08.</br>
    2. I do create some events on it, and got a start and end date.</br>
    3. On the calendar I can only see the event on the start date, but I need it to be seen from the start one until the end one...
    </br></br>
    So I went to PL/SQL and made the following tests:</br></br>
    1. created a loop example and tried to understand it:</br></br>
    DECLARE</br>
    a NUMBER := 0;</br>
    FS DATE := SYSDATE;</br>
    FF DATE := (SYSDATE+5);</br></br>
    BEGIN</br></br>
    WHILE ( FS < FF ) LOOP</br>
    a := a + 1;</br>
    FS := FS + 1;</br>
    dbms_output.put_line('paso ' || a); </br>
    END LOOP;</br></br>
    dbms_output.put_line('Dato a: ' || a);</br>
    dbms_output.put_line('Dato FS: ' || FS);</br>
    END;</br></br>
    I do get this as an answer:</br>
    paso 1</br>
    paso 2</br>
    paso 3</br>
    paso 4</br>
    paso 5</br>
    Dato a: 5</br>
    Dato FS: 17-MAY-08</br></br>
    Statement processed.</br></br>
    0.00 seconds</br></br>
    2. Once I had this I decided to modify what I had:</br></br>
    This is the block of code that needs to be repeated.</br></br>
    select '< a title= " TGB SCHEDUL " href = "f?p = &APP_ID.:3:' || :APP_SESSION || '::::P3_ID: ' || ID || ' " > ' || EVENT_NAME || '</a>
    ' EVENT_NAME,
    START_DATE</br>
    from     APP_TGB</br></br>
    So I placed it in the middel of the loop...</br></br>
    DECLARE</br>
    FS DATE := SYSDATE;</br>
    FF DATE := (SYSDATE+5);</br></br>
    BEGIN</br></br>
    WHILE ( FS < FF ) LOOP</br>
    select '< a title= " TGB SCHEDUL " href = "f?p = &APP_ID.:3:' || :APP_SESSION || '::::P3_ID: ' || ID || ' " > ' || EVENT_NAME || '</a>
    ' EVENT_NAME, START_DATE
    from     APP_TGB;</br>
    END LOOP;</br></br>
    END;</br></br>
    And got this message:</br>
    1 error has occurred</br>
    ·     Query cannot be parsed, please check the syntax of your query. (ORA-06550: line 8, column 3: PLS-00428: an INTO clause is expected in this SELECT statement) </br></br>
    Yes it was my mistake, I forgot the cursors in the selects… but here is where I do really need your help as I really don’t know how to implement them, and now with the variables that I have got.</br></br>
    I do really appreciate if anyone can help me out with it.</br></br>
    Best regards.</br></br>
    Jaison González</br></br>

    Hi Dimitri,<br><br>
    Once again, thank you very much for your time and answer,<br><br>
    1. Is it really necessary to do this for your whole table? There is no WHERE clause in your statement <br>
    Yes you are right I in the block of code that I sent you, I don’t have any WHERE clause but on the tests that I made, I have the following:<br><br>
    select START_DATE+level-1<br>
    from ( SELECT '<a title="TGB SCHEDUL" href="f?p=&APP_ID.:3:' ||
    :APP_SESSION || '::::P3_ID: ' || ID || '">' || EVENT_NAME||
    '</a>
    EVENT_NAME, START_DATE, END_DATE from APP_TGB WHERE ID = 141)<br>
    a connect by level <= (END_DATE - START_DATE)<br><br>
    But I as I have more that one event on the calendar, which are identified by different IDs, I remove it (the WHERE clause) thinking about the calendar’s convenience… <br><br>
    2. I guess you want in your outer select also the event_name?
    select start_date+level-1 as sdate, event_name, start_date, end_date
    from (select ... )<br>
    Yes, I will prove it and tell you how it works… sorry about it… <br><br>
    3. Not sure what you mean with that?<br>
    Right now, if I have as start date 5 and end date 10, it shows me on the first day (one) EVENT_NAME, on the second (four) EVENT_NAME, on the third (twelve) EVENT_NAME… and go on till it gets to the 10th…<br><br>
    Thank you very much for your help.<br><br>
    Best regards,<br><br>
    Jaison

  • How to assign table name for select query in loop.

    Hi friends my requirement is count the no of records of all the database table which comes into an internal table ."Check the below coding". Iam  fetching the tables from dd03l table into an internal table .plz give me a sujjesion how to assign a table name in select query  in a loop.
      SELECT tabname FROM dd09l
                INTO TABLE i_dd09l
                WHERE protokoll = 'X'.
      IF sy-subrc = 0.
        SORT i_dd09l BY tabname.
      ENDIF.
      LOOP AT i_dd09l.
        SELECT COUNT(*) INTO val FROM i_dd09l-tabname.
        IF sy-subrc = 0.
          i_dd09l-count = val.
        ENDIF.
        MODIFY i_dd09l INDEX sy-index.
        CLEAR val.
      ENDLOOP.
    error : 'I_DD09L-TABNAME' is not defined in the abap dictionary as a table.

    data: dy_table type ref to data,
          dy_line type ref to data,
          xfc type lvc_s_fcat,
          ifc type lvc_t_fcat,
          dy_field type ref to data.
    LOOP AT i_dd09l.
    perform get_structure using i_dd09l-tabname .
    CREATE DATA dy_table TYPE TABLE OF (_dd09l-tab_name).
        UNASSIGN <dyn_table>.
        ASSIGN dy_table->* TO <dyn_table>.
    SELECT COUNT(*) INTO val FROM <dyn_table>.
    IF sy-subrc = 0.
    i_dd09l-count = val.
    ENDIF.
    MODIFY i_dd09l INDEX sy-index.
    CLEAR val.
    ENDLOOP.
    form get_structure using p_table.
      data : idetails type abap_compdescr_tab,
      xdetails type abap_compdescr.
      data : ref_table_des type ref to cl_abap_structdescr.
    Get the structure of the table.
      ref_table_des ?=
      cl_abap_typedescr=>describe_by_name( p_table ).
      idetails = ref_table_des->components.
      loop at idetails into xdetails.
        clear xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        append xfc to ifc.
      endloop.
    endform.                    "get_structure
    Try like this hope it will work.
    Regards,
    madan.

  • Error in sql query as "loop has run more times than expected (Loop Counter went negative)"

    Hello,
    When I run the query as below
    DECLARE @LoopCount int
    SET @LoopCount = (SELECT Count(*) FROM KC_PaymentTransactionIDConversion with (nolock) Where KC_Transaction_ID is NULL and TransactionYear is NOT NULL)
    WHILE (
        SELECT Count(*)
        FROM KC_PaymentTransactionIDConversion with (nolock)
        Where KC_Transaction_ID is NULL
        and TransactionYear is NOT NULL
    ) > 0
    BEGIN
        IF @LoopCount < 0
            RAISERROR ('Issue with data in KC_PaymentTransactionIDConversion, loop has run more times than expected (Loop Counter went negative).', -- Message text.
                   16, -- Severity.
                   1 -- State.
    SET @LoopCount = @LoopCount - 1
    end
    I am getting error as "loop has run more times than expected (Loop Counter went negative)"
    Could any one help on this issue ASAP.
    Thanks ,
    Vinay

    Hi Vinay,
    According to your code above, the error message make sense. Because once the value returned by “SELECT Count(*)  FROM KC_PaymentTransactionIDConversion with (nolock) Where KC_Transaction_ID is NULL and TransactionYear is NOT NULL” is bigger than 0,
    then decrease @LoopCount. Without changing the table data, the returned value always bigger than 0, always decrease @LoopCount until it's negative and raise the error.
    To fix this issue with the current information, we should make the following modification:
    Change the code
    WHILE (
    SELECT Count(*)
    FROM KC_PaymentTransactionIDConversion with (nolock)
    Where KC_Transaction_ID is NULL
    and TransactionYear is NOT NULL
    ) > 0
    To
    WHILE @LoopCount > 0
    Besides, since the current query is senseless, please modify the query based on your requirement.
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Dynamic Query in Loop

    My objective is similar as follows -
    declare
    v varchar2(100) := 'Select sysdate from dual';
    begin
    for rec in (v)
    loop
    message(rec.sysdate);
    end loop;
    end;
    The above statements returns the following error -
    Encountered the Symbol - LOOP when expecting one of the following -......
    Actually i am having a query, which will be created dynamically. I need to execute this query in a loop because i am having some calculation for each row.
    plz help.

    I guess you are looking for something like this:
    DECLARE
    TYPE EmpCurTyp IS REF CURSOR;
    emp_cv EmpCurTyp;
    emp_rec emp%ROWTYPE;
    sql_stmt VARCHAR2(200);
    my_job VARCHAR2(15) := 'CLERK';
    BEGIN
    sql_stmt := 'SELECT * FROM emp WHERE job = :j';
    OPEN emp_cv FOR sql_stmt USING my_job;
    LOOP
    FETCH emp_cv INTO emp_rec;
    EXIT WHEN emp_cv%NOTFOUND;
    -- process record
    END LOOP;
    CLOSE emp_cv;
    END;
    But the problem is you can not use dynamic cursors in Forms. Use this feature in a database procedure/function.

  • How to avoid select query in loop

    Hi All,
    I have to select entries from table iclpay looping it_dfkkop and delete the entries in it_dfkkop_tmp which are not present in iclpay.
    For this If use below code its working fine, but there is performance issue
        CLEAR: it_iclpay[],it_iclpay.
        LOOP AT it_dfkkop_tmp.
          SELECT claim documentref paycat status FROM iclpay
                    APPENDING CORRESPONDING FIELDS OF TABLE it_iclpay
                            WHERE
                                  active = c_active AND
                                  claim = it_dfkkop_tmp-claim AND
                                  documentref = it_dfkkop_tmp-opbel.
          IF sy-subrc NE 0.
            DELETE it_dfkkop_tmp.
          ENDIF.
        ENDLOOP.
    If I write the code like below its not working
        SELECT claim documentref paycat status FROM iclpay
                INTO TABLE it_iclpay
                        FOR ALL ENTRIES IN it_dfkkop_tmp WHERE
                              active = c_active AND
                              claim = it_dfkkop_tmp-claim AND
                              documentref = it_dfkkop_tmp-opbel.
    Can anyone help on this.

    It did not dump but did not get final(required) output.
    I got the solution now.
    Thanks a lot for responding.
    I have written the below code
    SELECT claim
               documentref
               paycat
               status
               FROM
               iclpay
               APPENDING CORRESPONDING FIELDS OF TABLE it_iclpay
               FOR ALL ENTRIES IN it_dfkkop_tmp WHERE
                                  active = c_active AND
                                  claim = it_dfkkop_tmp-claim AND
                                  documentref = it_dfkkop_tmp-opbel.
        SORT it_dfkkop_tmp BY claim opbel.
        LOOP AT it_dfkkop_tmp.
          READ TABLE it_iclpay INTO  wa_iclpay WITH KEY
                              claim        = it_dfkkop_tmp-claim
                              documentref  = it_dfkkop_tmp-opbel.
          IF sy-subrc NE 0.
            DELETE it_dfkkop_tmp.
          ENDIF.
        ENDLOOP.

  • Query on loop in Integration process

    what condition do we give in loop. is it end condition or looping condition?

    Hi,
    Loop is used in BPM when you want to execute series of step repeatedly, you apply loop between those step that you want to repeat so you never give looping condition but an end condition and looping stops when end condition is met.
    You define condition using condition editor and formulate logical condition by  linking 2 operand with an operator(like equal, not equal, exists).
    For more details on condition go through this page
    <a href="http://help.sap.com/saphelp_nw04/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm">http://help.sap.com/saphelp_nw04/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm</a>
    Thanks,
    Anu
    Rewars points if helpful

  • DNS Query Name Loop DoS Sig 6065/0

    We have IPS sensors distributed throughout our internal network and we're seeing signature 6065/0 show up between certain DNS servers at certain times. I have the IPS setup to log these packets and it looks like name queries that are failing keep happening again and again for a domain name I don't recognize, but I'm mostly concerned as to why it's being detected as a loop. Is anyone familiar with this type of network behavior? Is anyone else seeing this signature fire very much?
    I appreciate any input.
    Casey

    Hi Devi,
    Based on this issue, would you please provide the netmon trace to us? I suggest taking a look at this packet. Moreover, please let me know if you tired to update the DNS record via DHCP manually.
    Thank you.
    Best regards,
    Steven Song
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • Memory leak/overload when looping by index over a large query and updating each DB record

    I am importing a CSV file into a temporary table and then running a select query that joins my actual database table with the temporary table, looking for any changes in the data. If changes exist, the select query is looped from 1 to #recordCount# and an update is applied to each record via cfquery. It runs very quickly (much more quickly than looping the query itself), but my memory spikes and overloads after about 1500 updates are completed. I need to be able to do upwards of 20000 at a time, without killing my system. I have tried manually setting the runtime garbage collection to trigger after X number of loops, but that doesn't seem to help. I am running CF8. See below for loop example:
    <cfloop from="1" to="#updatedRecordsQuery.recordCount#" index="a">
    <cftry>
                    <cfquery datasource="#db#" name="doUpdate">
                        UPDATE
                            CI
                        SET
                            firstname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#updatedRecordsQuery.firstname[a]#" />,
                            lastname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#updatedRecordsQuery.lastname[a]#" />,
                            etc, for about 15 various fields
                        FROM
                            client_info CI
                        WHERE
                            CI.client_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#updatedRecordsQuery.client_id[a]#" />
                    </cfquery>
                    <cfcatch type="database">
                        <cfset local.updateErrorList = listappend(local.updateErrorList,updatedRecordsQuery.client_id[a]) />
                        <cfset local.error = true />
                    </cfcatch>
               </cftry>
    </cfloop>

    I would suggest to use select update instead of looping over query object and update each row one-by-one.
    Procedure:
    - Insert your CSV data into temp table.
    - Use a select update SQL query to update the changed data instead of looping over a select query.
    Example:
    UPDATE
       Table
    SET
       Table.col1 = other_table.col1,
       Table.col2 = other_table.col2
    FROM
       Table
    INNER JOIN
      other_table
    ON
       Table.id = other_table.id
    NOTE: You can put all your scripts in a Procedure.

  • Query update on each iteration problem (MS SQL Sever / ODBC / Native Driver

    Hello,
    I�ve been working to learn some Java and now JDBC over the past 10 or so months.
    I think I have a general understanding of how to perform queries and work with data using JDBC. However, I�ve run into a problem. I�m trying to do a query of a set of data in a database based on the value of a status column. I want to loop over the messages and perform various functions with the data then update their status in the database. It�s preferable to do these 250 to 1000 rows at a time, but no more and no less.
    I�m connecting to MS SQL Server 2000, currently with ODBC. I�ve also tried it with the Java SQL Server 2000 drivers provided by Microsoft with the same results.
    I�ve found that I can do a one table query and loop though it with a while (rs.next()) {�} and run an Update statement with executeUpdate on each iteration without any problems, no matter the number of rows returned in query.
    I have not been able to use the updateString and updateRow inside the while loop. I keep getting errors like this at the line with the updateRow():
    Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Row update failed.
    This occurs no mater how many rows I select, 1 or more.
    The real problem I�ve been having is that the query I need to loop though joins across several tables and returns some rows from some of those tables. This only seems to work when I query for 38 or less selected rows and I use an Update statement with executeUpdate on each iteration. The updateString and updateRow methods never work. Any number of rows selected greater than 38 causes a deadlock where the Update is waiting for the select to compete on the server and the Update can�t proceed until the Select is complete.
    As I stated above I�ve tried both ODBC and the native SQL Server driver with the same results. I have not tried any other databases, but that�s moot as my data is already in MS SQL.
    Questions:
    How can I avoid or get around this 38 row limit without selecting each row, one at a time?
    What am I doing wrong with the updateString and updateRow?
    Is there a better approach that anyone can suggest?
    Here�s some sample code with the problem:
    import java.sql.*;
    public class db1{
         public static void main(String[] args) throws Exception{
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              String url = "jdbc:odbc:eBrochure_live";
              Connection con = DriverManager.getConnection(url, "sa", "d3v3l0p");
              Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
              Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://dcm613u2\\dcm613u2_dev:1433", "sa", "d3v3l0p");
              Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
              Statement stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
              stmt.executeUpdate("USE [myDatabase]");
              stmt2.executeUpdate("USE [myDatabase]");
              String qGetMessages = "SELECT TOP 250 t1.messageUUID, t1.subjectHeader, t2.emailAddress as toAddress " +
              "FROM APP_Messages as t1 JOIN APP_addressBook_contacts as t2 " +
              "     On t1.toContactID = t2.contactID " +
              "WHERE t1.statusID = 'queued'";
              ResultSet rs = stmt.executeQuery(qGetMessages);
              while (rs.next()) {
                   String messageUUID = rs.getString("messageUUID");
                   String subjectHeader = rs.getString("subjectHeader");
                   System.out.println(messageUUID + " " + subjectHeader);
                   String updateString = "UPDATE APP_Messages " +
                        "SET statusID = 'sent' " +
                        "WHERE messageUUID = '" + messageUUID + "' ";
                   stmt2.executeUpdate(updateString);
              con.close();
    Thanks for the help,
    Doug Hughes

    // sorry, ps.close() should be outside of if condition
    String sql = "UPDATE APP_Messages SET statusID = 'sent' WHERE messageUUID = ?";
    Statement statement = con.createStatement();
    PreparedStatement ps = con.prepareStatement(sql);
    ResultSet rs = statement.executeQuery("your select SQL");
    if ( rs.next() )
    ps.clearParameters();
    ps.setString(1, rs.getString("your column name"));
    ps.executeUpdate();
    ps.close();
    rs.close();
    statement.close();

  • Splitting a list (loop and insert)

    I have a text file with about 65000 records to be looped and
    inserted into a
    database. I am using cfhttp to read the list and turn it into
    a query. I am
    then using that query to loop and insert the records into a
    database.
    However, its too large and the server is timing out. Is there
    a break the
    list into 2 pieces and do it in serial?
    I am using:
    <cffunction name="getResidential" access="private"
    returntype="void"
    output="false" hint="">
    <cfargument name="ResFile" type="string"
    required="yes">
    <cfhttp timeout="6600"
    url="
    http://www.mywebsite.com/assets/property/#ResFile#"
    method="GET"
    name="Property" delimiter="|" textqualifier=""
    firstrowasheaders="yes" />
    <cfloop query="Property">
    <cfquery name="loopProperty" datasource="bpopros">
    INSERT STATEMENT HERE
    </cfquery>
    </cfloop>
    </cffunction>
    Is it possible to do something like:
    Function 1
    <cfloop from="1" to="40000" index="i">
    </cfloop>
    Function 2
    <cfloop from="40001" to="#Query.RecordCount#"
    index="i">
    </cfloop>
    Any ideas? Thanks
    Wally Kolcz
    MyNextPet.org
    Founder / Developer
    586.871.4126

    I like your second solution, but wouldn't I need access to
    the actual web
    server? I need to do this on hosting. I am downloading the
    files from a Real
    Comp and then looping the data into my client's database for
    searching. I
    wanted to just use the files as a flat database and just
    query or query off
    of it, but there is a new file everyday. Only one update
    (Sunday) is the
    master list of 45-60k records. All the rest (Mon-Sat) are
    just small
    updates.
    "Dan Bracuk" <[email protected]> wrote in
    message
    news:fdrgde$6qu$[email protected]..
    > It's possible, but it's a better idea to look for ways
    to do it without
    > cold
    > fusion.
    >
    > Food for thought, I have a requirement to move data from
    one db to
    > another. I
    > use Cold Fusion to query the first db, output to text,
    and ftp the text
    > files
    > to another server. I also have a scheduled job that
    looks for these text
    > files
    > and loads them into db2.
    >

  • Nested loop vs Hash Join

    Hi,
    Both the querys are returning same results, but in my first query hash join and second query nested loop . How ? PLs explain
    select *
    from emp a,dept b
    where a.deptno=b.deptno and b.deptno>20;
    6 rows
    Plan hash value: 4102772462
    | Id  | Operation                    | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT             |         |     6 |   348 |     6  (17)| 00:00:01 |
    |*  1 |  HASH JOIN                   |         |     6 |   348 |     6  (17)| 00:00:01 |
    |   2 |   TABLE ACCESS BY INDEX ROWID| DEPT    |     3 |    60 |     2   (0)| 00:00:01 |
    |*  3 |    INDEX RANGE SCAN          | PK_DEPT |     3 |       |     1   (0)| 00:00:01 |
    |*  4 |   TABLE ACCESS FULL          | EMP     |     7 |   266 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("A"."DEPTNO"="B"."DEPTNO")
       3 - access("B"."DEPTNO">20)
       4 - filter("A"."DEPTNO">20)
    select *
    from emp a,dept b
    where a.deptno=b.deptno and b.deptno=30;  
    6 rows
    Plan hash value: 568005898
    | Id  | Operation                    | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT             |         |     5 |   290 |     4   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS                |         |     5 |   290 |     4   (0)| 00:00:01 |
    |   2 |   TABLE ACCESS BY INDEX ROWID| DEPT    |     1 |    20 |     1   (0)| 00:00:01 |
    |*  3 |    INDEX UNIQUE SCAN         | PK_DEPT |     1 |       |     0   (0)| 00:00:01 |
    |*  4 |   TABLE ACCESS FULL          | EMP     |     5 |   190 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - access("B"."DEPTNO"=30)
       4 - filter("A"."DEPTNO"=30)

    Hi,
    Unless specifically requested, Oracle picks the best execution plan based on estimates of table sizes, column selectivity and many other variables. Even though Oracle does its best to have the estimates as accurate as possible, they are frequently different, and in some cases quite different, from the actual values.
    In the first query, Oracle estimated that the predicate “ b.deptno>20” would limit the number of records to 6, and based on that it decided the use Hash Join.
    In the second query, Oracle estimated that the predicate “b.deptno=30” would limit the number of records to 5, and based on that it decided the use Nested Loops Join.
    The fact that the actual number of records is the same is irrelevant because Oracle used the estimate, rather the actual number of records to pick the best plan.
    HTH,
    Iordan
    Iotzov

  • Traversing in a loop weekly

    Hi,
    I have a loop in which I would like to Select query on weekly basis starting from the last date, essentially traversing backwards week-by-week.  For example the table below represents the sample data for the query within loop, without WHERE
    clause.  What I like to get from the first iteration, say 5 years length backwards from the last date, which is 16/05/2014.  In the second iteration the last date would be 08/05/2014, because that is the next backward week date and again for
    5 years period from that date.
    II am not proficient with SQL especially when it comes to dates and I am looking for the neat approach as I have thousands of iterations and performance is the important factor here.
    Thanks

    If you don't need a massive table (centuries and centuries of dates, just a few years), you could use master..spt_values, but keep in mind the table I used only goes up to 2048, and you'll have creates something with a built in limit that you might reach
    someday. 
    There's also nothing wrong with using this table to CREATE permanent versions of the tables either (so you use it once, at table creation time, rather than over and over).  You can also join it to itself a time or two and use row_number() for the numbering
    too.  There are 100 creative ways to achieve the same thing, as you've seen.  As long as they aren't giving wrong sequence numbers, pick whichever method you like best and that meets your needs.  (Most of the many articles you'll find are probably
    correct also).
    Most to the point though, I suggest making a permanent version of the calendar table (numbers table too), because once a person starts using a Numbers table and a Calendar table, they find lots of other reasons to use them that they hadn't thought of before
    (or that they were doing a different way), and since you now are in that category, make yours permanent too!
    EDIT: Also, there's a little paradigm shift taking place too: a natural reaction to creating a calendar table or numbers table with way more numbers than you need at the moment, is that it's wasteful.  Ok, don't create one so massive that it needs its
    own dedicated server (unless you really need it), but remember, as a relational database, handling data in sets is what it does best, so don't worry too much about creating one that seems too big.  The overall benefit to you and your organization (standardization),
    combined with the most likely outcome (no discernible performance difference, possibly even faster than create plus use on the fly) says just make the permanent table.

  • Access database dynamic query output...

    Dear CF Colleagues:
    I need to run a loop for 4 times, to access four seperate values out of a data row in a test results table (tbl_results), where all four are in the row of the student (WHERE studentid = etc).
    It looks like this...
      <cfset variables.TimeTotals = 0>
      <cfloop from="1" to="4" step="1" index="timrec">
         <cfquery datasource="mydsn" name="rs_time">
          SELECT Btime#timrec#
          FROM tbl_results
          WHERE studentid = 'jack';
         </cfquery>
    <cfset variables.TimeTotals = variables.TimeTotals + (????? rs_time.Btime#timrec# value ?????)>
    </cfloop>
    *** QUESTION: How do I address that Btime#timrec# value? Not in this way, I know, but how?
    Looking forward to your wisdom, with gratitude,
    Hans

    As Reed says, many ways to tackle this.
    I would also point out the ability to ready all the BTIme... columns with one query then loop through the columns to total that time.... OR total them in the database.
    These both have the advantage of only needing one network connection to the database, which is the slowest part of this process.
    A)
    <cfquery name rs_time ...>
       SELECT Btime1, Btime2, Btime3 Btime4
    </cfquery>
    <cfset variable.TimeTotals = 0>
    <cfloop list="#rs_time.columnList#" index="col">
         <cfif left(col,5) EQ "BTIME"><cfset variables.TimeTotals = variable.TimeTotals + rs_time[col][1]>
    </cfloop>
    B)
    <cfquery name="rs_time"...>
         SELECT Btime1 + Btime2 + Btime2 + Btime4 AS totalTime
    </cfquery>
    OF COURSE
    I would be remis if I did not point out that you would have a more expandable database design if you normalized this so that the test times where not columns in the tbl_resluts table but rather rows.

Maybe you are looking for

  • Track changes in opening / closing FI period

    Does SAP have a standard report to track the changes made by opening / closing FI periods in a given date range for a particular company code using T Code OB52 and also track who has made the changes. If there is no standard report what is the soluti

  • Mp3 and Memory

    Hi i need to put in the movie about 5 mp3 files each is 4mintues (150kb size) and the files should be in seprated playes i mean after finishing the first mp3 flash should unload it from memory and start the next one so i added eachone to frame but wh

  • SRM PO Adobe Form

    Hello Frn's. I  am creating a z Adobe by copying a exisitng PO Adobe form (bbp_po_adb) . Beacuse i need some more fileds calculation, so have to  create a Z interface as well by copying a existing interface (if_bbp_po_adb). But then i need to impleme

  • Value Contracts for Credit note

    Dear Friends, Can we create Value contracts for Credit note processing? Please refer to the below scenario: I have certain budget that needs to be distributed to some of the customers depending upon the claims (Credit Notes). This budget is included

  • COOLING FAN : REPLACEMENT PART

    Hi, My laptop just keep shutting down... notice that an alarm has been issued during startup stating than the CPU fan is no longer working properly. For this case, where can i buy a replacement part for this item only. Pls. advice asap, and probably