Indexes for group by query on table with 5million records

Hi,
Here is my query which is taking ages to run :
     SELECT approved.budgetReferenceno
               , approved.projects
               , approved.allocations
               , rptgen4
                     , financialyear
               , cashclass
               , SUM(nvl(approved.FullYear,0)) as FullYear
          FROM   approved
          JOIN   rpt_entity ON rpt_entity.level0 = approved.entity
          JOIN   cashclasses     ON accountcode    = approved.account
    where budgetreferenceno = refno    
    and
        entity in ( 
           (select Level0 from rpt_entity   where   
           (   entityparent in (select * from table(split(userid)))    or   rptgen5 in (select * from table(split(userid)))   )   ) 
     and
       ccs in (select level0 from rpt_ccs where rptgen4 in (select * from table(split(userid)))) or
       ccs in (select level0 from rpt_ccs where rptgen5 in (select * from table(split(userid)))) or
       ccs in (select level0 from rpt_ccs where rptgen6 in (select * from table(split(userid)))) or
       ccs in (select level0 from rpt_ccs where rptgen7 in (select * from table(split(userid))) ) or
       ccs in (select distinct(substr(column_value,2,length(column_value)-2)) from table(split_comma(userid)) )
          GROUP BY approved.budgetReferenceno
               , approved.projects
               , approved.allocations
               , rptgen4
                     , financialyear
               , cashclass
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 4074481161
| Id  | Operation                                | Name            | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT                         |                 | 31234 |  3660K|       | 86141   (1)| 00:17:14 |
|   1 |  HASH GROUP BY                           |                 | 31234 |  3660K|    17M| 86141   (1)| 00:17:14 |
|*  2 |   FILTER                                 |                 |       |       |       |            |          |
|*  3 |    HASH JOIN                             |                 |   138K|    15M|       | 82427   (1)| 00:16:30 |
|   4 |     TABLE ACCESS FULL                    | CASHCLASSES     |  2875 | 48875 |       |     5   (0)| 00:00:01 |
|*  5 |     HASH JOIN                            |                 |   138K|    13M|       | 82420   (1)| 00:16:30 |
PLAN_TABLE_OUTPUT
|   6 |      TABLE ACCESS FULL                   | RPT_entity  |   725 | 10875 |       |    11   (0)| 00:00:01 |
|*  7 |      HASH JOIN RIGHT SEMI                |                 |   138K|    11M|       | 82408   (1)| 00:16:29 |
|   8 |       VIEW                               | VW_NSO_1        |    71 |   568 |       |    11   (0)| 00:00:01 |
|*  9 |        FILTER                            |                 |       |       |       |            |          |
|  10 |         TABLE ACCESS FULL                | RPT_entity  |   725 | 17400 |       |    11   (0)| 00:00:01 |
|* 11 |         COLLECTION ITERATOR PICKLER FETCH| SPLIT           |       |       |       |            |          |
|* 12 |         COLLECTION ITERATOR PICKLER FETCH| SPLIT           |       |       |       |            |          |
|* 13 |       TABLE ACCESS FULL                  | approved        |  1170K|    89M|       | 82389   (1)| 00:16:29 |
|  14 |    NESTED LOOPS                          |                 |     1 |    18 |       |    46   (0)| 00:00:01 |
|  15 |     COLLECTION ITERATOR PICKLER FETCH    | SPLIT           |       |       |       |            |          |
|* 16 |     INDEX RANGE SCAN                     | CC_INDEX1       |     1 |    16 |       |     1   (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
|  17 |    NESTED LOOPS                          |                 |     2 |    46 |       |    51   (2)| 00:00:01 |
|* 18 |     INDEX FAST FULL SCAN                 | CC_INDEX2       |     1 |    21 |       |    46   (3)| 00:00:01 |
|* 19 |     COLLECTION ITERATOR PICKLER FETCH    | SPLIT           |       |       |       |            |          |
|  20 |    NESTED LOOPS                          |                 |     1 |    24 |       |    52   (0)| 00:00:01 |
|  21 |     TABLE ACCESS BY INDEX ROWID          | RPT_ccs |     1 |    22 |       |    46   (0)| 00:00:01 |
|* 22 |      INDEX SKIP SCAN                     | CC_INDEX1       |     1 |       |       |    45   (0)| 00:00:01 |
|* 23 |     COLLECTION ITERATOR PICKLER FETCH    | SPLIT           |       |       |       |            |          |
|  24 |    NESTED LOOPS                          |                 |     2 |    50 |       |    60   (0)| 00:00:01 |
|  25 |     TABLE ACCESS BY INDEX ROWID          | RPT_ccs |     1 |    23 |       |    46   (0)| 00:00:01 |
|* 26 |      INDEX SKIP SCAN                     | CC_INDEX1       |     1 |       |       |    45   (0)| 00:00:01 |
|* 27 |     COLLECTION ITERATOR PICKLER FETCH    | SPLIT           |       |       |       |            |          |
PLAN_TABLE_OUTPUT
|* 28 |    COLLECTION ITERATOR PICKLER FETCH     | SPLIT_COMMA     |       |       |       |            |          |
Predicate Information (identified by operation id):
   2 - filter( EXISTS (SELECT 0 FROM "RPT_ccs" "RPT_ccs",TABLE() "KOKBF$" WHERE
              "LEVEL0"=:B1 AND "RPTGEN4"=VALUE(KOKBF$)) OR  EXISTS (SELECT 0 FROM "RPT_ccs"
              "RPT_ccs",TABLE() "KOKBF$" WHERE "RPTGEN5"=VALUE(KOKBF$) AND "LEVEL0"=:B2) OR  EXISTS (SELECT 0
              FROM "RPT_ccs" "RPT_ccs",TABLE() "KOKBF$" WHERE "RPTGEN6"=VALUE(KOKBF$) AND "LEVEL0"=:B3)
              OR  EXISTS (SELECT 0 FROM "RPT_ccs" "RPT_ccs",TABLE() "KOKBF$" WHERE
PLAN_TABLE_OUTPUT
              "RPTGEN7"=VALUE(KOKBF$) AND "LEVEL0"=:B4) OR  EXISTS (SELECT 0 FROM TABLE() "KOKBF$" WHERE
              SUBSTR(VALUE(KOKBF$),2,LENGTH(VALUE(KOKBF$))-2)=:B5))
   3 - access("ACCOUNTCODE"="approved"."ACCOUNT")
   5 - access("RPT_entity"."LEVEL0"="approved"."entity")
   7 - access("approved"."entity"="LEVEL0")
   9 - filter( EXISTS (SELECT 0 FROM TABLE() "KOKBF$" WHERE VALUE(KOKBF$)=:B1) OR  EXISTS (SELECT 0 FROM
              TABLE() "KOKBF$" WHERE VALUE(KOKBF$)=:B2))
  11 - filter(VALUE(KOKBF$)=:B1)
  12 - filter(VALUE(KOKBF$)=:B1)
  13 - filter("approved"."BUDGETREFERENCENO"='BASE')
  16 - access("RPTGEN4"=VALUE(KOKBF$) AND "LEVEL0"=:B1)
PLAN_TABLE_OUTPUT
  18 - filter("LEVEL0"=:B1)
  19 - filter("RPTGEN5"=VALUE(KOKBF$))
  22 - access("LEVEL0"=:B1)
       filter("LEVEL0"=:B1)
  23 - filter("RPTGEN6"=VALUE(KOKBF$))
  26 - access("LEVEL0"=:B1)
       filter("LEVEL0"=:B1)
  27 - filter("RPTGEN7"=VALUE(KOKBF$))
  28 - filter(SUBSTR(VALUE(KOKBF$),2,LENGTH(VALUE(KOKBF$))-2)=:B1)
64 rows selected.
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE    11.1.0.7.0      Production
TNS for IBM/AIX RISC System/6000: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - ProductionThe table has 28 columns none indexed the columns mentioned here have non unique values.
The table approved has more than 10million records and the query is taking a huge time.
The query first tries to restrict the search to only valid entities and cc (already indexed and working fine).
The cardinality of allocations, projects is around 1000, entity is 3000, and cc is around 50,000, reference number = 2000, financialyear = 4
Please suggest which index would be best to use on these columns given that there will no updations but frequent insertions.
If nothing else works than I will need to change it to pre aggregated data for overnight run .
Thanks,
Neetesh
Edited by: user13312817 on Nov 16, 2011 11:05 AM
Edited by: user13312817 on Nov 16, 2011 11:36 AM
Edited by: user13312817 on Nov 16, 2011 11:38 AM
Edited by: user13312817 on Nov 16, 2011 12:02 PM

Hello Adam,
Tried this but still not much of a difference.
create index test_index on approved (budgetreferenceno,projects,allocations,financialyear,entity,ccs,FullYear) compress 6;
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 2463060356
| Id  | Operation                               | Name            | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT                        |                 | 25030 |  4644K|       | 70852   (1)| 00:14:11 |
|   1 |  TABLE ACCESS BY INDEX ROWID            | FEGEN4          |     1 |    13 |       |     2   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN                     | INDEX1          |     1 |       |       |     1   (0)| 00:00:01 |
|   3 |  TABLE ACCESS BY INDEX ROWID            | CASHCLASSES     |     1 |    17 |       |     2   (0)| 00:00:01 |
|*  4 |   INDEX UNIQUE SCAN                     | CASHCLASSES_PK  |     1 |       |       |     1   (0)| 00:00:01 |
|   5 |  HASH GROUP BY                          |                 | 25030 |  4644K|    21M| 70852   (1)| 00:14:11 |
PLAN_TABLE_OUTPUT
|   6 |   VIEW                                  |                 |   109K|    19M|       | 68578   (1)| 00:13:43 |
|*  7 |    FILTER                               |                 |       |       |       |            |          |
|*  8 |     HASH JOIN RIGHT SEMI                |                 |   484K|    99M|       | 68578   (1)| 00:13:43 |
|   9 |      VIEW                               | VW_NSO_1        |    71 |  7242 |       |    11   (0)| 00:00:01 |
|* 10 |       FILTER                            |                 |       |       |       |            |          |
|  11 |        TABLE ACCESS FULL                | RPT_entity  |   725 | 17400 |       |    11   (0)| 00:00:01 |
|* 12 |        COLLECTION ITERATOR PICKLER FETCH| SPLIT           |       |       |       |            |          |
|* 13 |        COLLECTION ITERATOR PICKLER FETCH| SPLIT           |       |       |       |            |          |
|* 14 |      TABLE ACCESS FULL                  | approved         |   982K|   106M|       | 68560   (1)| 00:13:43 |
|  15 |     NESTED LOOPS                        |                 |     1 |    18 |       |    46   (0)| 00:00:01 |
|  16 |      COLLECTION ITERATOR PICKLER FETCH  | SPLIT           |       |       |       |            |          |
PLAN_TABLE_OUTPUT
|* 17 |      INDEX RANGE SCAN                   | CC_INDEX1       |     1 |    16 |       |     1   (0)| 00:00:01 |
|  18 |     NESTED LOOPS                        |                 |     2 |    46 |       |    51   (2)| 00:00:01 |
|* 19 |      INDEX FAST FULL SCAN               | CC_INDEX2       |     1 |    21 |       |    46   (3)| 00:00:01 |
|* 20 |      COLLECTION ITERATOR PICKLER FETCH  | SPLIT           |       |       |       |            |          |
|  21 |     NESTED LOOPS                        |                 |     1 |    24 |       |    52   (0)| 00:00:01 |
|  22 |      TABLE ACCESS BY INDEX ROWID        | RPT_ccs |     1 |    22 |       |    46   (0)| 00:00:01 |
|* 23 |       INDEX SKIP SCAN                   | CC_INDEX1       |     1 |       |       |    45   (0)| 00:00:01 |
|* 24 |      COLLECTION ITERATOR PICKLER FETCH  | SPLIT           |       |       |       |            |          |
|  25 |     NESTED LOOPS                        |                 |     2 |    50 |       |    60   (0)| 00:00:01 |
|  26 |      TABLE ACCESS BY INDEX ROWID        | RPT_ccs |     1 |    23 |       |    46   (0)| 00:00:01 |
|* 27 |       INDEX SKIP SCAN                   | CC_INDEX1       |     1 |       |       |    45   (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
|* 28 |      COLLECTION ITERATOR PICKLER FETCH  | SPLIT           |       |       |       |            |          |
|* 29 |     COLLECTION ITERATOR PICKLER FETCH   | SPLIT_COMMA     |       |       |       |            |          |
Predicate Information (identified by operation id):
   2 - access("LEVEL0"=:B1)
   4 - access("ACCOUNTCODE"=:B1)
   7 - filter( EXISTS (SELECT 0 FROM "RPT_ccs" "RPT_ccs",TABLE() "KOKBF$" WHERE
              "LEVEL0"=:B1 AND "RPTGEN4"=VALUE(KOKBF$)) OR  EXISTS (SELECT 0 FROM "RPT_ccs"
PLAN_TABLE_OUTPUT
              "RPT_ccs",TABLE() "KOKBF$" WHERE "RPTGEN5"=VALUE(KOKBF$) AND "LEVEL0"=:B2) OR  EXISTS (SELECT 0
              FROM "RPT_ccs" "RPT_ccs",TABLE() "KOKBF$" WHERE "RPTGEN6"=VALUE(KOKBF$) AND "LEVEL0"=:B3)
              OR  EXISTS (SELECT 0 FROM "RPT_ccs" "RPT_ccs",TABLE() "KOKBF$" WHERE
              "RPTGEN7"=VALUE(KOKBF$) AND "LEVEL0"=:B4) OR  EXISTS (SELECT 0 FROM TABLE() "KOKBF$" WHERE
              SUBSTR(VALUE(KOKBF$),2,LENGTH(VALUE(KOKBF$))-2)=:B5))
   8 - access("entity"="LEVEL0")
  10 - filter( EXISTS (SELECT 0 FROM TABLE() "KOKBF$" WHERE VALUE(KOKBF$)=:B1) OR  EXISTS (SELECT 0 FROM
              TABLE() "KOKBF$" WHERE VALUE(KOKBF$)=:B2))
  12 - filter(VALUE(KOKBF$)=:B1)
  13 - filter(VALUE(KOKBF$)=:B1)
  14 - filter("BUDGETREFERENCENO"='BASE')
PLAN_TABLE_OUTPUT
  17 - access("RPTGEN4"=VALUE(KOKBF$) AND "LEVEL0"=:B1)
  19 - filter("LEVEL0"=:B1)
  20 - filter("RPTGEN5"=VALUE(KOKBF$))
  23 - access("LEVEL0"=:B1)
       filter("LEVEL0"=:B1)
  24 - filter("RPTGEN6"=VALUE(KOKBF$))
  27 - access("LEVEL0"=:B1)
       filter("LEVEL0"=:B1)
  28 - filter("RPTGEN7"=VALUE(KOKBF$))
  29 - filter(SUBSTR(VALUE(KOKBF$),2,LENGTH(VALUE(KOKBF$))-2)=:B1)
PLAN_TABLE_OUTPUT
Note
   - dynamic sampling used for this statement
69 rows selected.Thanks,
Neetesh
Edited by: user13312817 on Nov 17, 2011 7:04 AM

Similar Messages

  • ORA-00604 ORA-00904 When query partitioned table with partitioned indexes

    Got ORA-00604 ORA-00904 When query partitioned table with partitioned indexes in the data warehouse environment.
    Query runs fine when query the partitioned table without partitioned indexes.
    Here is the query.
    SELECT al2.vdc_name, al7.model_series_name, COUNT (DISTINCT (al1.vin)),
    al27.accessory_code
    FROM vlc.veh_vdc_accessorization_fact al1,
    vlc.vdc_dim al2,
    vlc.model_attribute_dim al7,
    vlc.ppo_list_dim al18,
    vlc.ppo_list_indiv_type_dim al23,
    vlc.accy_type_dim al27
    WHERE ( al2.vdc_id = al1.vdc_location_id
    AND al7.model_attribute_id = al1.model_attribute_id
    AND al18.mydppolist_id = al1.ppo_list_id
    AND al23.mydppolist_id = al18.mydppolist_id
    AND al23.mydaccytyp_id = al27.mydaccytyp_id
    AND ( al7.model_series_name IN ('SCION TC', 'SCION XA', 'SCION XB')
    AND al2.vdc_name IN
    ('PORT OF BALTIMORE',
    'PORT OF JACKSONVILLE - LEXUS',
    'PORT OF LONG BEACH',
    'PORT OF NEWARK',
    'PORT OF PORTLAND'
    AND al27.accessory_code IN ('42', '43', '44', '45')
    GROUP BY al2.vdc_name, al7.model_series_name, al27.accessory_code

    I would recommend that you post this at the following OTN forum:
    Database - General
    General Database Discussions
    and perhaps at:
    Oracle Warehouse Builder
    Warehouse Builder
    The Oracle OLAP forum typically does not cover general data warehousing topics.

  • Select max date from a table with multiple records

    I need help writing an SQL to select max date from a table with multiple records.
    Here's the scenario. There are multiple SA_IDs repeated with various EFFDT (dates). I want to retrieve the most recent effective date so that the SA_ID is unique. Looks simple, but I can't figure this out. Please help.
    SA_ID CHAR_TYPE_CD EFFDT CHAR_VAL
    0000651005 BASE 15-AUG-07 YES
    0000651005 BASE 13-NOV-09 NO
    0010973671 BASE 20-MAR-08 YES
    0010973671 BASE 18-JUN-10 NO

    Hi,
    Welcome to the forum!
    Whenever you have a question, post a little sample data in a form that people can use to re-create the problem and test their ideas.
    For example:
    CREATE TABLE     table_x
    (     sa_id          NUMBER (10)
    ,     char_type     VARCHAR2 (10)
    ,     effdt          DATE
    ,     char_val     VARCHAR2 (10)
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('15-AUG-2007', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('13-NOV-2009', 'DD-MON-YYYY'), 'NO');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('20-MAR-2008', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('18-JUN-2010', 'DD-MON-YYYY'), 'NO');
    COMMIT;Also, post the results that you want from that data. I'm not certain, but I think you want these results:
    `    SA_ID LAST_EFFD
        651005 13-NOV-09
      10973671 18-JUN-10That is, the latest effdt for each distinct sa_id.
    Here's how to get those results:
    SELECT    sa_id
    ,         MAX (effdt)    AS last_effdt
    FROM      table_x
    GROUP BY  sa_id
    ;

  • I HAVE A SOURCE TABLE WITH 10 RECORDS AND TARGET TABLE 15 RECORDS. MY WUESTION IS USING WITH THE TABLE COMPARISON TRANSFORM I WANT TO DELETE UNMATCHED RECORDS FROM THE TARGET TABLE ??

    I HAVE A SOURCE TABLE WITH 10 RECORDS AND TARGET TABLE 15 RECORDS. MY QUESTION IS USING WITH THE TABLE COMPARISON TRANSFORM .I WANT TO DELETE UNMATCHED RECORDS FROM THE TARGET TABLE ?? HOW IT IS ??

    Hi Kishore,
    First identify deleted records by selecting "Detect deleted rows from comparison table" feature in Table Comparison
    Then Use Map Operation with Input row type as "delete" and output row type as "delete" to delete records from target table.

  • How to spool in excel sheet of table with 1561828 records

    how to spool in excel sheet of table with 1561828 records
    i think excel got only 65l limit?
    COUNT(*)
    1561828
    i am using windows box...any suggestions?

    Raman wrote:
    means excel 2007 can hold 15,61,828 records ? can i give like spool filename.xls?You can name the spool file anything you want, but surely you realize that naming it 'filename.xls' doesn't make it an xls file. A name is just a name. There are industry standards on certain names indicating certain file formats, but the name doesn't make it that format.

  • Index for group by

    Oracle 10g:
    Does having index help when doing query by "group by"?
    For eg: select aa, count(*) from B group by aa

    ErickG wrote:
    Hello,
    as yo used count(*) a full table scan will be performed. If you use a col1 that was indexed,
    like col1 for a count, not group by, an index scan will be performed, but be carefull if there
    is no null in table col1, the amount will be incorrect.
    RegardsSo I didn't understand that null col will destroy the count. Also why wouldn't having index help when doing group by?

  • SQL query - 2 tables with no relationship

    I'm fairly new to SQL, but I'm trying to put together a query using 2 tables. They have no relationship. I'm using this information in a C# app and I'm trying to pull it as clean as possible to use in a class.
    For example, I have a table called Server where I am selecting 2 columns,
    ServerID and Type. The second table called
    App I am selecting the AppVersion column.
    Question is how can output the data without duplicate AppVersion values? I would rather see null or empty.
    I have tried below along with a CROSS JOIN and I get duplicates in the AppVersion. 
    SELECT ServerID, Type, AppVersion
    FROM Server, App;
    I know that is wrong as it outputs duplicates for AppVersion in the results.
    Thanks in advance. 
    A

    I didn't get your question. When you cross join two different tables the output is a Cartesian product of the two tables.
    The Record (A, 1, 1.1) is different from (B, 1, 1,1).
    You can use a distinct to eliminate if you have duplicates in data and you don't want to see them.
    SELECT DISTINCT ServerID, Type, AppVersion
    FROM Server, App;
    Please mark as answer, if this has helped you solve the issue.
    Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

  • 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.

  • Dynamic Table with Random Records

    What I am trying to do is select random records from a table
    and display them in a dynamic table with max columns set to 3 and
    the 4th record to be on a new row. Below is what I have right now
    and it works to randomly pick records but has no function to set
    columns in a table. If there is an easier way feel free to let me
    know. I have tried various ways to do this but none seem to work.
    <CFQUERY NAME="getItems" DATASOURCE="absi">
    SELECT catfit.*, modcats.*, prodmat.*, prod.* FROM catfit,
    modcats,
    prodmat, prod WHERE prodmat.prodid=catfit.prodid And
    catfit.catid=modcats.catid
    ORDER BY modl ASC </cfquery>
    <cfif getItems.recordCount>
    <cfset showNum = 3>
    <cfif showNum gt getItems.recordCount>
    <cfset showNum = getItems.recordCount>
    </cfif>
    <cfset itemList = "">
    <cfloop from="1" to="#getItems.recordCount#"
    index="i">
    <cfset itemList = ListAppend(itemList, i)>
    </cfloop>
    <cfset randomItems = "">
    <cfset itemCount = ListLen(itemList)>
    <cfloop from="1" to="#itemCount#" index="i">
    <cfset random = ListGetAt(itemList, RandRange(1,
    itemCount))>
    <cfset randomItems = ListAppend(randomItems, random)>
    <cfset itemList = ListDeleteAt(itemList,
    ListFind(itemList, random))>
    <cfset itemCount = ListLen(itemList)>
    </cfloop>
    <cfloop from="1" to="#showNum#" index="i">
    <cfoutput>
    <table width="205" border="0" align="left"
    cellpadding="0" cellspacing="0">
    <tr>
    <td width="235" height="116"> <div
    align="center"><img
    src="../Products/ProductPictures/#getitems.pic[ListGetAt(randomItems,
    i)]#" width="100"></div></td>
    </tr>
    <tr>
    <td
    class="ProdTitle">#getitems.brand[ListGetAt(randomItems,
    i)]# #getitems.modl[ListGetAt(randomItems, i)]#</td>
    </tr>
    <tr>
    <td
    class="paragraph">$#getitems.prc[ListGetAt(randomItems,
    i)]#</td>
    </tr>
    <tr>
    <td><A
    href="../Products/details.cfm?prodid=#getItems.prodid[ListGetAt(randomItems,
    i)]#" class="linkcontact">more
    info</a></td>
    </tr>
    <tr>
    <td> </td>
    </tr>
    </table>
    </cfoutput>
    </cfloop>
    </cfif>

    To start a new row after 3 records, do something like this.
    <table>
    <tr>
    <cfoutput query="something">
    <td>#data#<td>
    <cfif currentrow mod 3 is 0>
    </tr><tr>
    </cfoutput>
    </tr>
    </table>
    You should also know that your approach is very inefficient
    in that you are bringing in to cold fusion more data than you need.
    First of all you are selecting every field from 3 tables when you
    don't appear to be using all of them. Second, you are selecting
    every record and you only want to use 3. There are better ways out
    there, but they are db specific and you did not say what you are
    using.

  • CFParam link to a table with no record

    Guys, I'm a newb feeling my way a long with CF, and have made
    some good headway. Here's my challenge de jour:
    I have a main table, `customers`. I have two other tables,
    `products` and `customers_products`. The latter has four fields:
    its own primary key, a customer_id, a product_id, and the
    product_name.
    For the sake of my question, I've loaded `customers_products`
    with dummy data that relates perfectly with some `customer`s and
    their `products`, using their respective keys. I can easily insert
    new records to this table, `customer_products`, for any customer by
    using an INSERT form, as long as there is already at least one
    customer record in the `customer_product` table. But, if I attempt
    to go to
    add_product.cfm?customer_id= from that customer form for a
    customer who has yet to have any products entered in
    `customer_products`, I get the error, "Invalid data '' for
    CFSQLTYPE CF_SQL_NUMERIC". This, I presume, due to the null value,
    as the CRParam URL is the customer_id - and there is no customer_id
    in that table, yet.
    I want to be able to go from the customer record form to the
    add_products.cfm form, specifically for that customer, even though
    there are no current records for that customer in the
    `customer_products` table.
    I'd add code, but I have a feeling that this is not so much a
    problem with code, but lack of knowledge of how to do a common
    practice: add a new record to a table and applying the correct
    customer key to the customer_id field.
    If you know of a site or tutorial that I can use, that would
    be great.
    Thank you!

    If your SQL query is looking at the URL for an ID in order to
    query the table and it doesn't exist you'll get a query.recordcount
    of 0. You can then use this to direct the user to another
    page...like an add page or something. At the same time you could
    also check the ID is right before querying the database (my syntax
    may be a little incorrect as I am doing this from memory at 8am!)
    e.g.
    <cfif isDefined("url.customer_id") and
    len(url.customer_id)>
    <!---Do your query here.--->
    <cfif my_query.recordcount eq 0>
    <!--- the URL existed but the query returned 0 so let's
    redirect them to the add page or something --->
    <cflocation url="my_add_page.cfm" addtoken="no" />
    <cfabort />
    </cfif>
    <cfelse>
    <!---URL looks bad.--->
    <p>Nothing was found because the URL looks
    wrong.</p>
    </cfif>

  • Populating a temp table with multiple records.

    I want to populate a temp table with a a set of recs. This table will be used for
    crossing/joining with my other tables to pull out data.
    ie:
    Main table (loc)contains these fields -> county,permit,utme,utmn
    Temp table ( tmpid) contains these fields -> countytemp, permittemp
    So I will be doing a statement like this once my temp table is populated.
    Select l.county,l.permit,l.utme,l.utmn from loc l,tmpid t where l.county=t.countytemp and l.permit=t.permittemp;
    So this temp table will basically be a list of ids that can range from a few recs to several hundred.
    I want to know is there is way I can poplulate/repopulate it easily using sqlPlus/other by reading in a Ascii file
    from client PCs. (besides SQL loader).

    HI
    let me explain my requirement first,
    i need to populate my block with the results from the following sql
    SELECT * from contactdet where
    (Month=12 and TrType='MTM' and FinYr='04-05' and Userid='SA009' and Clcode='SB001')
    UNION
    SELECT * from contactdetSUM where (Clcode='SB001' AND CSCODE='AB001')
    Pease note. the where clauses i have put are different in each table and my requirement is
    the constants values i have put in where clause should be variable (ie. i should be able to put variables like :clcode or so)
    I tried us using Query data source type as 'FROM clause query' but it does not allow me to put variables in where clause.
    Is there any way out i can do this ? Please help me
    Regards
    Uday

  • Value Set whose Data come from customize table with distinct record

    Dear All,
    I am new in Oracle EBS, currently i am creating value set whose data come from customize table which have 40 duplicate record in which distinct column return 27 record .
    Table XX_ROUND_SET
    Columns (Transactions_id,set_record)
    Total Record (40)
    Distinct Record (Set_Record --> 27)
    I just want to show only 27 record in it.
    Thanks
    Rehan

    Hi Rehan,
    PL.IGNORE MY EARLIER UPDATE AND TREAT THIS UPDATE AS YOUR SOLUTION.
    Method 1
    Create the VIEW based on DISTINCT values; use the VIEW for creates the VALUESET.
    Method 2
    Paste the QUERY in TABLE field with alias name, and give the column name (with alias name).
    (in your case )
    TABLE NAME : ( select distinct transactions_id, set_record from XX_ROUND_SET ) Y
    VALUE : Y.transactions_id
    HTH
    Sanjay

  • Program times out while looping at internal table with huge records - Needs fine tuning suggestions

    Hi,
    I am trying to execute a report. It times out while looping at vbap internal table. This internal table has 140000  records and does the validation within this loop and geenrates data for the output. Due to this huge volume, the program times out when executed foreground.
    There are no nested loops, so I cannot apply 'Parallel Cursor' here.
    Is there any way I can fine tune the program so that it doesn't timeout? Is it possible to apply 'Parallel Processing' . If yes, how?
    Thanks,
    Pavan

    Hi Pavan ,
                  ->sort your internal table by all primary key for vbap.
                  ->Read a Record from the table (use your condition here)
                  ->if record satisfys your where condition ,get that record index .
                  ->loop the table from the index (without condition) .
                  its like parallel cursor only but for single loop .;-)
                  ->use field symbols ,wherever possible .
               if still dump is coming ,contact your basis team .
    regards,
    Krishna.

  • Database Adapter: cannot access table with complex record type as columns

    Hi all,
    I cannot perform any operations on a table that has columns with complex record type.
    I have created a table to store purchase order details.
    Sample script:
    CREATE type XX_CUST_INFO_TYP as object
    ssn VARCHAR2(20),
    rating NUMBER(15)
    CREATE type XX_ITEM_TYP as object
    item_name VARCHAR2(20),
    unit_price NUMBER(15),
    quantity NUMBER(15)
    CREATE table XX_PORDER (cust XX_CUST_INFO_TYP, porder XX_ITEM_TYP);
    When i try to access the table X_PORDER in jdev through a database Adapter, i receive the error as
    "some tables contains columns that are not recognized by the database adpter"
    1.) so in this case, how to include such tables that have complex types?
    Also, check out this scenario also..
    1. add a table through a database adapter
    2. drop the table in backend
    3. i can still see the table and its structure in the database adapter wizard even after restarting Jdeveloper.. How is it possible?
    These are some really interesting scenarios to experiment. Please suggest your ideas on this..
    Thanks All!

    Hi Hem,
    for a select you could select against a view. And for inserts you could create a stored procedure. They support complex types since 10.1.2. Complex types support in tables/views was added for 11 (next major release).
    You might be able to use PureSQL as a workaround too, i.e.
    insert into XX_PORDER values (XX_CUST_INFO_TYP(?,?), XX_ITEM_TYP(?, ?, ?))
    As for your other problem, in 10.1.2/10.1.3 the DBAdapter wizard sits on top of the Jdev Offline Tables and TopLink Mapping Workbench components. When you remove a table in the wizard it won't delete the Offline DB component. It was added by the wizard, but afterwards it is public to the entire Jdev project. You must remove it from Jdev yourself. This has been improved for the next major release too, no artifacts from underlying components are created.
    To remove it select:
    Offline DB Objects -> <schema> -> <table> and try File.. Erase From Disk.
    Thanks
    Steve

  • Comparing Two tables with 300k records and update one table

    Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
    Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
    Column B has same data in both the tables.
    I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
    I m trying to do using PLSQL Tables.
    Any suggestion?
    Thanks.

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results  will be the contents of the changed table(s) when everything is finished.
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    ef2019c7-080c-4475-9cf4-2cf1b1057a41 wrote:
    Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
    Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
    Column B has same data in both the tables.
    I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
    I m trying to do using PLSQL Tables.
    Any suggestion?
    Thanks.
    Why are you trying to use PL/SQL tables?  If tabl_1 and tabl_2 are regular database tables, it will be much simpler and faster just to use them.
    Depending on your requirements, you can do an UPDATE or MERGE, either in SQL or in PL/SQL.

Maybe you are looking for