Possible to further enhance this SQL query?

Hi Experts,
I have this query running with 23min in development server, but report took 1hr to execute in production server. Hoping to get idea of to improve on the performance.
I have attached necessary information as below. When i try to ftp my trace file, noticed that hit to 10MB of file size, and having error when running tkprof.
I opened the trace file, i saw these lines and printed until filesize up to 10mb.
my oracle db is
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
END OF STMT
PARSE #3:c=10000,e=3256,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=2,tim=1071649075322
EXEC #3:c=0,e=593,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=2,tim=1071649078646
WAIT #3: nam='SQL*Net message to client' ela= 3 driver id=1952673792 #bytes=1 p3=0 obj#=270 tim=1071649078817
WAIT #3: nam='db file sequential read' ela= 1240 file#=766 block#=547660 blocks=1 obj#=37006875 tim=1071649080664
WAIT #3: nam='gc cr grant 2-way' ela= 364 p1=747 p2=753505 p3=1 obj#=37006875 tim=1071649081460
WAIT #3: nam='db file sequential read' ela= 1168 file#=747 block#=753505 blocks=1 obj#=37006875 tim=1071649082750
WAIT #3: nam='gc cr grant 2-way' ela= 592 p1=767 p2=127180 p3=1 obj#=37006875 tim=1071649083720My query:
SELECT
msi.description "ST Model",
oel.ordered_item "Product Part Number",
hp.party_name "Bill To Cust Name",
shc.location"Ship To Cust Num",
oeh.order_number "Order Num",
oel.line_number || '.' || oel.shipment_number "Order Line Num",
ft.nls_territory "Ship To Country",
ccm.designapplication "Design Application",
ccm.formattedcapacity||'GB' "Capacity",
oel.attribute1 "Order Category",
oel.Subinventory "Subinventory",
to_char(wnd.confirm_date,'MM/DD/YYYY DY') "Shipment Date",
NVL(oel.shipped_quantity,0) "Net Units"
FROM
apps.oe_order_headers_all oeh,  
apps.oe_order_lines_all  oel,  
apps.seaeng_ccfamilymodelinfo ccm,
  HZ_CUST_SITE_USES_ALL        SHC,  
  HZ_CUST_ACCT_SITES_ALL       SHAC, 
  HZ_PARTY_SITES               SHPS, 
  HZ_LOCATIONS                 SHLC, 
  apps.fnd_territories         ft, 
  apps.hz_cust_accounts        hca,
  apps.hz_parties              hp,
  apps.mtl_system_items_b      msi
  ,wsh_delivery_assignments wda
,wsh_new_deliveries       wnd
,wsh_delivery_details     wdd
WHERE
      oeh.header_id = oel.header_id
AND   oeh.SHIP_TO_ORG_ID     = SHC.SITE_USE_ID
AND   SHC.SITE_USE_CODE      = 'SHIP_TO'
and   hp.party_id = shps.party_id
AND   SHC.CUST_ACCT_SITE_ID  = SHAC.CUST_ACCT_SITE_ID      
AND   SHAC.PARTY_SITE_ID     = SHPS.PARTY_SITE_ID        
AND   SHPS.LOCATION_ID       = SHLC.LOCATION_ID          
AND   SHLC.COUNTRY           = ft.territory_code
AND   hca.cust_account_id    = SHAC.cust_account_id       
AND   msi.description = ccm.stmodelnumber
  AND oel.inventory_item_id = msi.inventory_item_id
  and msi.organization_id = 65
and wda.delivery_id = wnd.delivery_id      
AND wdd.delivery_detail_id = wda.delivery_detail_id
AND oel.line_id            = wdd.source_line_id
AND wnd.status_code = 'CL'
AND ccm.designapplication IN ('PSG','ESG','NSG')
AND hca.sales_channel_code NOT IN ('RTL','AD-RTL','EU')
AND oel.attribute1 IN ('NB','NBEOL','NBSEA')
AND oel.subinventory IN ('KFGI','AFGI','SFGIF','FGIF')
AND trunc(WND.CONFIRM_DATE) >= TO_DATE('01-Jan-2009','DD-MON-YYYY')
AND trunc(WND.CONFIRM_DATE) < TO_DATE('31-JAN-2009','DD-MON-YYYY') + 1
AND oel.org_id = 189
--AND oel.header_id = 7233926
GROUP BY msi.description,
         oel.ordered_item,
         hp.party_name,
         shc.LOCATION,
         oeh.order_number,
         oel.line_number || '.' || oel.shipment_number,
         ft.nls_territory,
         ccm.designapplication,
         ccm.formattedcapacity || 'GB',
         oel.attribute1,
         oel.subinventory,
         to_char(wnd.confirm_date,'MM/DD/YYYY DY'),
         NVL (oel.shipped_quantity, 0)
HAVING COUNT (*) >= 1
SQL> show parameter user_dump_dest
NAME                                 TYPE        VALUE
user_dump_dest                       string      /u33/oracle/product/10gRAC/adm
                                                 in/dap12_okdev14/udump
SQL>
SQL> show parameter optimizer
NAME                                 TYPE        VALUE
optimizer_dynamic_sampling           integer     2
optimizer_features_enable            string      10.2.0.4
optimizer_index_caching              integer     0
optimizer_index_cost_adj             integer     100
optimizer_mode                       string      ALL_ROWS
optimizer_secure_view_merging        boolean     FALSE
SQL>
SQL> show parameter db_file_multi
NAME                                 TYPE        VALUE
db_file_multiblock_read_count        integer     8
SQL>
SQL> show parameter db_block_size
NAME                                 TYPE        VALUE
db_block_size                        integer     8192
SQL>
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 4058013364
| Id  | Operation                                   | Name                        | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT                            |                             |     1 |   286 | 13161   (1)| 00:02:38 |
|*  1 |  FILTER                                     |                             |       |       |            |          |
|   2 |   HASH GROUP BY                             |                             |     1 |   286 | 13161   (1)| 00:02:38 |
|   3 |    NESTED LOOPS                             |                             |     1 |   286 | 13160   (1)| 00:02:38 |
|   4 |     NESTED LOOPS                            |                             |     1 |   276 | 13159   (1)| 00:02:38 |
|   5 |      NESTED LOOPS                           |                             |     1 |   250 | 13158   (1)| 00:02:38 |
|   6 |       NESTED LOOPS                          |                             |     1 |   243 | 13157   (1)| 00:02:38 |
|   7 |        NESTED LOOPS                         |                             |     1 |   235 | 13156   (1)| 00:02:38 |
|   8 |         NESTED LOOPS                        |                             |     1 |   220 | 13155   (1)| 00:02:38 |
|   9 |          NESTED LOOPS                       |                             |     1 |   204 | 13153   (1)| 00:02:38 |
|  10 |           NESTED LOOPS                      |                             |     1 |   173 | 13151   (1)| 00:02:38 |
|  11 |            NESTED LOOPS                     |                             |     1 |   155 | 13149   (1)| 00:02:38 |
|  12 |             NESTED LOOPS                    |                             |    53 |  7420 | 13042   (1)| 00:02:37 |
|  13 |              NESTED LOOPS                   |                             |    53 |  6784 | 12883   (1)| 00:02:35 |
|  14 |               NESTED LOOPS                  |                             |    27 |  3132 | 12814   (1)| 00:02:34 |
|  15 |                NESTED LOOPS                 |                             |   375 | 36000 | 12805   (1)| 00:02:34 |
|  16 |                 INLIST ITERATOR             |                             |       |       |            |          |
|* 17 |                  TABLE ACCESS BY INDEX ROWID| OE_ORDER_LINES_ALL          |   359 | 20822 | 12086   (1)| 00:02:26 |
|* 18 |                   INDEX RANGE SCAN          | OE_ORDER_LINES_N21          | 45242 |       |   115   (1)| 00:00:02 |
|  19 |                 TABLE ACCESS BY INDEX ROWID | MTL_SYSTEM_ITEMS_B          |     1 |    38 |     2   (0)| 00:00:01 |
|* 20 |                  INDEX UNIQUE SCAN          | MTL_SYSTEM_ITEMS_B_U1       |     1 |       |     1   (0)| 00:00:01 |
|* 21 |                TABLE ACCESS BY INDEX ROWID  | SEAENG_CCFAMILYMODELINFO    |     1 |    20 |     1   (0)| 00:00:01 |
|* 22 |                 INDEX UNIQUE SCAN           | SEAENG_CCFAMILYMODELINFO_U1 |     1 |       |     0   (0)| 00:00:01 |
|  23 |               TABLE ACCESS BY INDEX ROWID   | WSH_DELIVERY_DETAILS        |     2 |    24 |     3   (0)| 00:00:01 |
|* 24 |                INDEX RANGE SCAN             | WSH_DELIVERY_DETAILS_N3     |     2 |       |     2   (0)| 00:00:01 |
|  25 |              TABLE ACCESS BY INDEX ROWID    | WSH_DELIVERY_ASSIGNMENTS    |     1 |    12 |     3   (0)| 00:00:01 |
|* 26 |               INDEX RANGE SCAN              | WSH_DELIVERY_ASSIGNMENTS_N3 |     1 |       |     2   (0)| 00:00:01 |
|* 27 |             TABLE ACCESS BY INDEX ROWID     | WSH_NEW_DELIVERIES          |     1 |    15 |     2   (0)| 00:00:01 |
|* 28 |              INDEX UNIQUE SCAN              | WSH_NEW_DELIVERIES_U1       |     1 |       |     1   (0)| 00:00:01 |
|  29 |            TABLE ACCESS BY INDEX ROWID      | OE_ORDER_HEADERS_ALL        |     1 |    18 |     2   (0)| 00:00:01 |
|* 30 |             INDEX UNIQUE SCAN               | OE_ORDER_HEADERS_U1         |     1 |       |     1   (0)| 00:00:01 |
|* 31 |           TABLE ACCESS BY INDEX ROWID       | HZ_CUST_SITE_USES_ALL       |     1 |    31 |     2   (0)| 00:00:01 |
|* 32 |            INDEX UNIQUE SCAN                | HZ_CUST_SITE_USES_U1        |     1 |       |     1   (0)| 00:00:01 |
|  33 |          TABLE ACCESS BY INDEX ROWID        | HZ_CUST_ACCT_SITES_ALL      |     1 |    16 |     2   (0)| 00:00:01 |
|* 34 |           INDEX UNIQUE SCAN                 | HZ_CUST_ACCT_SITES_U1       |     1 |       |     1   (0)| 00:00:01 |
|  35 |         TABLE ACCESS BY INDEX ROWID         | HZ_PARTY_SITES              |     1 |    15 |     1   (0)| 00:00:01 |
|* 36 |          INDEX UNIQUE SCAN                  | HZ_PARTY_SITES_U1           |     1 |       |     0   (0)| 00:00:01 |
|  37 |        TABLE ACCESS BY INDEX ROWID          | HZ_LOCATIONS                |     1 |     8 |     1   (0)| 00:00:01 |
|* 38 |         INDEX UNIQUE SCAN                   | HZ_LOCATIONS_U1             |     1 |       |     0   (0)| 00:00:01 |
|  39 |       TABLE ACCESS BY INDEX ROWID           | FND_TERRITORIES             |     1 |     7 |     1   (0)| 00:00:01 |
|* 40 |        INDEX UNIQUE SCAN                    | FND_TERRITORIES_U1          |     1 |       |     0   (0)| 00:00:01 |
|  41 |      TABLE ACCESS BY INDEX ROWID            | HZ_PARTIES                  |     1 |    26 |     1   (0)| 00:00:01 |
|* 42 |       INDEX UNIQUE SCAN                     | HZ_PARTIES_U1               |     1 |       |     0   (0)| 00:00:01 |
|* 43 |     TABLE ACCESS BY INDEX ROWID             | HZ_CUST_ACCOUNTS            |     1 |    10 |     1   (0)| 00:00:01 |
|* 44 |      INDEX UNIQUE SCAN                      | HZ_CUST_ACCOUNTS_U1         |     1 |       |     0   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   1 - filter(COUNT(*)>=1)
  17 - filter("OEL"."ORG_ID"=189 AND ("OEL"."ATTRIBUTE1"='NB' OR "OEL"."ATTRIBUTE1"='NBEOL' OR
              "OEL"."ATTRIBUTE1"='NBSEA'))
  18 - access("OEL"."SUBINVENTORY"='AFGI' OR "OEL"."SUBINVENTORY"='FGIF' OR "OEL"."SUBINVENTORY"='KFGI' OR
              "OEL"."SUBINVENTORY"='SFGIF')
  20 - access("OEL"."INVENTORY_ITEM_ID"="MSI"."INVENTORY_ITEM_ID" AND "MSI"."ORGANIZATION_ID"=65)
  21 - filter("CCM"."DESIGNAPPLICATION"='ESG' OR "CCM"."DESIGNAPPLICATION"='NSG' OR
              "CCM"."DESIGNAPPLICATION"='PSG')
  22 - access("MSI"."DESCRIPTION"="CCM"."STMODELNUMBER")
  24 - access("OEL"."LINE_ID"="WDD"."SOURCE_LINE_ID")
  26 - access("WDD"."DELIVERY_DETAIL_ID"="WDA"."DELIVERY_DETAIL_ID")
  27 - filter("WND"."STATUS_CODE"='CL' AND TRUNC(INTERNAL_FUNCTION("WND"."CONFIRM_DATE"))>=TO_DATE(' 2009-01-01
              00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND TRUNC(INTERNAL_FUNCTION("WND"."CONFIRM_DATE"))<TO_DATE(' 2009-02-01
              00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
  28 - access("WDA"."DELIVERY_ID"="WND"."DELIVERY_ID")
  30 - access("OEH"."HEADER_ID"="OEL"."HEADER_ID")
  31 - filter("SHC"."SITE_USE_CODE"='SHIP_TO')
  32 - access("OEH"."SHIP_TO_ORG_ID"="SHC"."SITE_USE_ID")
  34 - access("SHC"."CUST_ACCT_SITE_ID"="SHAC"."CUST_ACCT_SITE_ID")
  36 - access("SHAC"."PARTY_SITE_ID"="SHPS"."PARTY_SITE_ID")
  38 - access("SHPS"."LOCATION_ID"="SHLC"."LOCATION_ID")
  40 - access("SHLC"."COUNTRY"="FT"."TERRITORY_CODE")
  42 - access("HP"."PARTY_ID"="SHPS"."PARTY_ID")
  43 - filter("HCA"."SALES_CHANNEL_CODE"<>'RTL' AND "HCA"."SALES_CHANNEL_CODE"<>'AD-RTL' AND
              "HCA"."SALES_CHANNEL_CODE"<>'EU')
  44 - access("HCA"."CUST_ACCOUNT_ID"="SHAC"."CUST_ACCOUNT_ID")
81 rows selected.
Elapsed: 00:00:04.71
SQL>
SQL> alter session set events '10046 trace name context forever, level 8';
Session altered.
Elapsed: 00:00:00.54
SQL>
SQL> -- put your statement here
SQL> SELECT
  2   msi.description "ST Model",
  3   oel.ordered_item "Product Part Number",
  4   hp.party_name "Bill To Cust Name",
  5   shc.location"Ship To Cust Num",
  6   oeh.order_number "Order Num",
  7   oel.line_number || '.' || oel.shipment_number "Order Line Num",
  8   ft.nls_territory "Ship To Country",
  9   ccm.designapplication "Design Application",
10   ccm.formattedcapacity||'GB' "Capacity",
11   oel.attribute1 "Order Category",
12   oel.Subinventory "Subinventory",
13   to_char(wnd.confirm_date,'MM/DD/YYYY DY') "Shipment Date",
14   NVL(oel.shipped_quantity,0) "Net Units"
15  FROM
16   apps.oe_order_headers_all oeh,
17   apps.oe_order_lines_all  oel,
18   apps.seaeng_ccfamilymodelinfo ccm,
19    HZ_CUST_SITE_USES_ALL         SHC,
20    HZ_CUST_ACCT_SITES_ALL         SHAC,
21    HZ_PARTY_SITES              SHPS,
22    HZ_LOCATIONS              SHLC,
23    apps.fnd_territories         ft,
24    apps.hz_cust_accounts         hca,
25    apps.hz_parties              hp,
26    --
27    apps.mtl_system_items_b         msi
28    --
29    ,wsh_delivery_assignments wda
30   ,wsh_new_deliveries     wnd
31   ,wsh_delivery_details     wdd
32  WHERE
33          oeh.header_id = oel.header_id
34  --
35  AND   oeh.SHIP_TO_ORG_ID       = SHC.SITE_USE_ID
36  AND   SHC.SITE_USE_CODE       = 'SHIP_TO'
37  and   hp.party_id = shps.party_id
38  AND   SHC.CUST_ACCT_SITE_ID  = SHAC.CUST_ACCT_SITE_ID
39  AND   SHAC.PARTY_SITE_ID       = SHPS.PARTY_SITE_ID
40  AND   SHPS.LOCATION_ID       = SHLC.LOCATION_ID
41  AND   SHLC.COUNTRY        = ft.territory_code
42  AND   hca.cust_account_id       = SHAC.cust_account_id
43  --
44  AND   msi.description = ccm.stmodelnumber
45  --
46    AND oel.inventory_item_id = msi.inventory_item_id
47    and msi.organization_id = 65
48    --
49   and wda.delivery_id = wnd.delivery_id
50   AND wdd.delivery_detail_id = wda.delivery_detail_id
51   AND oel.line_id           = wdd.source_line_id
52   AND wnd.status_code = 'CL'
53  AND ccm.designapplication IN ('PSG','ESG','NSG')
54  AND hca.sales_channel_code NOT IN ('RTL','AD-RTL','EU')
55  AND oel.attribute1 IN ('NB','NBEOL','NBSEA')
56  AND oel.subinventory IN ('KFGI','AFGI','SFGIF','FGIF')
57  AND trunc(WND.CONFIRM_DATE) >= TO_DATE('01-Jan-2009','DD-MON-YYYY')
58  AND trunc(WND.CONFIRM_DATE) < TO_DATE('31-JAN-2009','DD-MON-YYYY') + 1
59  AND oel.org_id = 189
60  --AND oel.header_id = 7233926
61  GROUP BY msi.description,
62             oel.ordered_item,
63             hp.party_name,
64             shc.LOCATION,
65             oeh.order_number,
66             oel.line_number || '.' || oel.shipment_number,
67             ft.nls_territory,
68             ccm.designapplication,
69             ccm.formattedcapacity || 'GB',
70             oel.attribute1,
71             oel.subinventory,
72             to_char(wnd.confirm_date,'MM/DD/YYYY DY'),
73             NVL (oel.shipped_quantity, 0)
74  HAVING COUNT (*) >= 1
75  /
592 rows selected.
Elapsed: 00:39:37.34
Execution Plan
Plan hash value: 4058013364
| Id  | Operation                                   | Name                        | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT                            |                             |     1 |   286 | 13161   (1)| 00:02:38 |
|*  1 |  FILTER                                     |                             |       |       |            |          |
|   2 |   HASH GROUP BY                             |                             |     1 |   286 | 13161   (1)| 00:02:38 |
|   3 |    NESTED LOOPS                             |                             |     1 |   286 | 13160   (1)| 00:02:38 |
|   4 |     NESTED LOOPS                            |                             |     1 |   276 | 13159   (1)| 00:02:38 |
|   5 |      NESTED LOOPS                           |                             |     1 |   250 | 13158   (1)| 00:02:38 |
|   6 |       NESTED LOOPS                          |                             |     1 |   243 | 13157   (1)| 00:02:38 |
|   7 |        NESTED LOOPS                         |                             |     1 |   235 | 13156   (1)| 00:02:38 |
|   8 |         NESTED LOOPS                        |                             |     1 |   220 | 13155   (1)| 00:02:38 |
|   9 |          NESTED LOOPS                       |                             |     1 |   204 | 13153   (1)| 00:02:38 |
|  10 |           NESTED LOOPS                      |                             |     1 |   173 | 13151   (1)| 00:02:38 |
|  11 |            NESTED LOOPS                     |                             |     1 |   155 | 13149   (1)| 00:02:38 |
|  12 |             NESTED LOOPS                    |                             |    53 |  7420 | 13042   (1)| 00:02:37 |
|  13 |              NESTED LOOPS                   |                             |    53 |  6784 | 12883   (1)| 00:02:35 |
|  14 |               NESTED LOOPS                  |                             |    27 |  3132 | 12814   (1)| 00:02:34 |
|  15 |                NESTED LOOPS                 |                             |   375 | 36000 | 12805   (1)| 00:02:34 |
|  16 |                 INLIST ITERATOR             |                             |       |       |            |          |
|* 17 |                  TABLE ACCESS BY INDEX ROWID| OE_ORDER_LINES_ALL          |   359 | 20822 | 12086   (1)| 00:02:26 |
|* 18 |                   INDEX RANGE SCAN          | OE_ORDER_LINES_N21          | 45242 |       |   115   (1)| 00:00:02 |
|  19 |                 TABLE ACCESS BY INDEX ROWID | MTL_SYSTEM_ITEMS_B          |     1 |    38 |     2   (0)| 00:00:01 |
|* 20 |                  INDEX UNIQUE SCAN          | MTL_SYSTEM_ITEMS_B_U1       |     1 |       |     1   (0)| 00:00:01 |
|* 21 |                TABLE ACCESS BY INDEX ROWID  | SEAENG_CCFAMILYMODELINFO    |     1 |    20 |     1   (0)| 00:00:01 |
|* 22 |                 INDEX UNIQUE SCAN           | SEAENG_CCFAMILYMODELINFO_U1 |     1 |       |     0   (0)| 00:00:01 |
|  23 |               TABLE ACCESS BY INDEX ROWID   | WSH_DELIVERY_DETAILS        |     2 |    24 |     3   (0)| 00:00:01 |
|* 24 |                INDEX RANGE SCAN             | WSH_DELIVERY_DETAILS_N3     |     2 |       |     2   (0)| 00:00:01 |
|  25 |              TABLE ACCESS BY INDEX ROWID    | WSH_DELIVERY_ASSIGNMENTS    |     1 |    12 |     3   (0)| 00:00:01 |
|* 26 |               INDEX RANGE SCAN              | WSH_DELIVERY_ASSIGNMENTS_N3 |     1 |       |     2   (0)| 00:00:01 |
|* 27 |             TABLE ACCESS BY INDEX ROWID     | WSH_NEW_DELIVERIES          |     1 |    15 |     2   (0)| 00:00:01 |
|* 28 |              INDEX UNIQUE SCAN              | WSH_NEW_DELIVERIES_U1       |     1 |       |     1   (0)| 00:00:01 |
|  29 |            TABLE ACCESS BY INDEX ROWID      | OE_ORDER_HEADERS_ALL        |     1 |    18 |     2   (0)| 00:00:01 |
|* 30 |             INDEX UNIQUE SCAN               | OE_ORDER_HEADERS_U1         |     1 |       |     1   (0)| 00:00:01 |
|* 31 |           TABLE ACCESS BY INDEX ROWID       | HZ_CUST_SITE_USES_ALL       |     1 |    31 |     2   (0)| 00:00:01 |
|* 32 |            INDEX UNIQUE SCAN                | HZ_CUST_SITE_USES_U1        |     1 |       |     1   (0)| 00:00:01 |
|  33 |          TABLE ACCESS BY INDEX ROWID        | HZ_CUST_ACCT_SITES_ALL      |     1 |    16 |     2   (0)| 00:00:01 |
|* 34 |           INDEX UNIQUE SCAN                 | HZ_CUST_ACCT_SITES_U1       |     1 |       |     1   (0)| 00:00:01 |
|  35 |         TABLE ACCESS BY INDEX ROWID         | HZ_PARTY_SITES              |     1 |    15 |     1   (0)| 00:00:01 |
|* 36 |          INDEX UNIQUE SCAN                  | HZ_PARTY_SITES_U1           |     1 |       |     0   (0)| 00:00:01 |
|  37 |        TABLE ACCESS BY INDEX ROWID          | HZ_LOCATIONS                |     1 |     8 |     1   (0)| 00:00:01 |
|* 38 |         INDEX UNIQUE SCAN                   | HZ_LOCATIONS_U1             |     1 |       |     0   (0)| 00:00:01 |
|  39 |       TABLE ACCESS BY INDEX ROWID           | FND_TERRITORIES             |     1 |     7 |     1   (0)| 00:00:01 |
|* 40 |        INDEX UNIQUE SCAN                    | FND_TERRITORIES_U1          |     1 |       |     0   (0)| 00:00:01 |
|  41 |      TABLE ACCESS BY INDEX ROWID            | HZ_PARTIES                  |     1 |    26 |     1   (0)| 00:00:01 |
|* 42 |       INDEX UNIQUE SCAN                     | HZ_PARTIES_U1               |     1 |       |     0   (0)| 00:00:01 |
|* 43 |     TABLE ACCESS BY INDEX ROWID             | HZ_CUST_ACCOUNTS            |     1 |    10 |     1   (0)| 00:00:01 |
|* 44 |      INDEX UNIQUE SCAN                      | HZ_CUST_ACCOUNTS_U1         |     1 |       |     0   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   1 - filter(COUNT(*)>=1)
  17 - filter("OEL"."ORG_ID"=189 AND ("OEL"."ATTRIBUTE1"='NB' OR "OEL"."ATTRIBUTE1"='NBEOL' OR
              "OEL"."ATTRIBUTE1"='NBSEA'))
  18 - access("OEL"."SUBINVENTORY"='AFGI' OR "OEL"."SUBINVENTORY"='FGIF' OR "OEL"."SUBINVENTORY"='KFGI' OR
              "OEL"."SUBINVENTORY"='SFGIF')
  20 - access("OEL"."INVENTORY_ITEM_ID"="MSI"."INVENTORY_ITEM_ID" AND "MSI"."ORGANIZATION_ID"=65)
  21 - filter("CCM"."DESIGNAPPLICATION"='ESG' OR "CCM"."DESIGNAPPLICATION"='NSG' OR
              "CCM"."DESIGNAPPLICATION"='PSG')
  22 - access("MSI"."DESCRIPTION"="CCM"."STMODELNUMBER")
  24 - access("OEL"."LINE_ID"="WDD"."SOURCE_LINE_ID")
  26 - access("WDD"."DELIVERY_DETAIL_ID"="WDA"."DELIVERY_DETAIL_ID")
  27 - filter("WND"."STATUS_CODE"='CL' AND TRUNC(INTERNAL_FUNCTION("WND"."CONFIRM_DATE"))>=TO_DATE(' 2009-01-01
              00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND TRUNC(INTERNAL_FUNCTION("WND"."CONFIRM_DATE"))<TO_DATE(' 2009-02-01
              00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
  28 - access("WDA"."DELIVERY_ID"="WND"."DELIVERY_ID")
  30 - access("OEH"."HEADER_ID"="OEL"."HEADER_ID")
  31 - filter("SHC"."SITE_USE_CODE"='SHIP_TO')
  32 - access("OEH"."SHIP_TO_ORG_ID"="SHC"."SITE_USE_ID")
  34 - access("SHC"."CUST_ACCT_SITE_ID"="SHAC"."CUST_ACCT_SITE_ID")
  36 - access("SHAC"."PARTY_SITE_ID"="SHPS"."PARTY_SITE_ID")
  38 - access("SHPS"."LOCATION_ID"="SHLC"."LOCATION_ID")
  40 - access("SHLC"."COUNTRY"="FT"."TERRITORY_CODE")
  42 - access("HP"."PARTY_ID"="SHPS"."PARTY_ID")
  43 - filter("HCA"."SALES_CHANNEL_CODE"<>'RTL' AND "HCA"."SALES_CHANNEL_CODE"<>'AD-RTL' AND
              "HCA"."SALES_CHANNEL_CODE"<>'EU')
  44 - access("HCA"."CUST_ACCOUNT_ID"="SHAC"."CUST_ACCOUNT_ID")
Statistics
          8  recursive calls
          0  db block gets
    1915554  consistent gets
     467079  physical reads
        232  redo size
      51846  bytes sent via SQL*Net to client
        971  bytes received via SQL*Net from client
          7  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
        592  rows processedEdited by: Lygine on Jun 11, 2010 12:38 AM

SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID  0q3dmq9s9f5qh, child number 0
SELECT /*+ gather_plan_statistics */  msi.description "ST Model",  oel.ordered_item "Product Part Number",  hp.party_name "Bill To Cust Name",
shc.location"Ship To Cust Num",  oeh.order_number "Order Num",  oel.line_number || '.' || oel.shipment_number "Order Line Num",  ft.nls_territory "Ship To
Country",  ccm.designapplication "Design Application",  ccm.formattedcapacity||'GB' "Capacity",  oel.attribute1 "Order Category",  oel.Subinventory
"Subinventory",  to_char(wnd.confirm_date,'MM/DD/YYYY DY') "Shipment Date",  NVL(oel.shipped_quantity,0) "Net Units" FROM  apps.oe_order_headers_all oeh,
apps.oe_order_lines_all  oel,  apps.seaeng_ccfamilymodelinfo ccm,   HZ_CUST_SITE_USES_ALL        SHC,   HZ_CUST_ACCT_SITES_ALL       SHAC,   HZ_PARTY_SITES
         SHPS,   HZ_LOCATIONS                 SHLC,   apps.fnd_territories         ft,   apps.hz_cust_accounts        hca,   apps.hz_parties              hp,
--   apps.mtl_system_items_b      msi   --   ,wsh_delivery_assignments wda  ,
Plan hash value: 4058013364
| Id  | Operation                                   | Name                        | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |  OMem |  1Mem | Used-Mem |
|*  1 |  FILTER                                     |                             |      1 |        |    592 |00:13:52.78 |    1892K|    470K|       |       |          |
|   2 |   HASH GROUP BY                             |                             |      1 |      1 |    592 |00:13:52.78 |    1892K|    470K|   723K|   723K| 1233K (0)|
|   3 |    NESTED LOOPS                             |                             |      1 |      1 |    749 |00:25:10.44 |    1892K|    470K|       |       |          |
|   4 |     NESTED LOOPS                            |                             |      1 |      1 |    751 |00:25:10.13 |    1890K|    470K|       |       |          |
|   5 |      NESTED LOOPS                           |                             |      1 |      1 |    751 |00:25:09.49 |    1889K|    470K|       |       |          |
|   6 |       NESTED LOOPS                          |                             |      1 |      1 |    751 |00:25:09.48 |    1888K|    470K|       |       |          |
|   7 |        NESTED LOOPS                         |                             |      1 |      1 |    751 |00:25:08.74 |    1886K|    469K|       |       |          |
|   8 |         NESTED LOOPS                        |                             |      1 |      1 |    751 |00:25:08.01 |    1885K|    469K|       |       |          |
|   9 |          NESTED LOOPS                       |                             |      1 |      1 |    751 |00:25:07.13 |    1882K|    469K|       |       |          |
|  10 |           NESTED LOOPS                      |                             |      1 |      1 |    751 |00:25:05.93 |    1880K|    469K|       |       |          |
|  11 |            NESTED LOOPS                     |                             |      1 |      1 |    751 |00:25:02.93 |    1878K|    469K|       |       |          |
|  12 |             NESTED LOOPS                    |                             |      1 |     53 |    101K|00:21:18.75 |    1612K|    424K|       |       |          |
|  13 |              NESTED LOOPS                   |                             |      1 |     53 |    101K|00:17:15.59 |    1305K|    355K|       |       |          |
|  14 |               NESTED LOOPS                  |                             |      1 |     27 |  86268 |00:10:21.90 |    1043K|    279K|       |       |          |
|  15 |                NESTED LOOPS                 |                             |      1 |    375 |  86762 |00:10:18.86 |     860K|    279K|       |       |          |
|  16 |                 INLIST ITERATOR             |                             |      1 |        |  86762 |00:10:10.00 |     600K|    277K|       |       |          |
|* 17 |                  TABLE ACCESS BY INDEX ROWID| OE_ORDER_LINES_ALL          |      4 |    359 |  86762 |00:10:09.94 |     600K|    277K|       |       |          |
|* 18 |                   INDEX RANGE SCAN          | OE_ORDER_LINES_N21          |      4 |  45242 |    587K|00:00:03.04 |    1387 |   1231 |       |       |          |
|  19 |                 TABLE ACCESS BY INDEX ROWID | MTL_SYSTEM_ITEMS_B          |  86762 |      1 |  86762 |00:00:08.64 |     260K|   1418 |       |       |          |
|* 20 |                  INDEX UNIQUE SCAN          | MTL_SYSTEM_ITEMS_B_U1       |  86762 |      1 |  86762 |00:00:05.02 |     173K|    609 |       |       |          |
|* 21 |                TABLE ACCESS BY INDEX ROWID  | SEAENG_CCFAMILYMODELINFO    |  86762 |      1 |  86268 |00:00:02.84 |     182K|     95 |       |       |          |
|* 22 |                 INDEX UNIQUE SCAN           | SEAENG_CCFAMILYMODELINFO_U1 |  86762 |      1 |  86604 |00:00:01.04 |   86790 |      9 |       |       |          |
|  23 |               TABLE ACCESS BY INDEX ROWID   | WSH_DELIVERY_DETAILS        |  86268 |      2 |    101K|00:06:53.45 |     262K|  76591 |       |       |          |
|* 24 |                INDEX RANGE SCAN             | WSH_DELIVERY_DETAILS_N3     |  86268 |      2 |    101K|00:01:17.90 |     172K|  21055 |       |       |          |
|  25 |              TABLE ACCESS BY INDEX ROWID    | WSH_DELIVERY_ASSIGNMENTS    |    101K|      1 |    101K|00:04:02.87 |     306K|  68499 |       |       |          |
|* 26 |               INDEX RANGE SCAN              | WSH_DELIVERY_ASSIGNMENTS_N3 |    101K|      1 |    101K|00:01:42.88 |     204K|  27799 |       |       |          |
|* 27 |             TABLE ACCESS BY INDEX ROWID     | WSH_NEW_DELIVERIES          |    101K|      1 |    751 |00:03:44.19 |     266K|  44828 |       |       |          |
|* 28 |              INDEX UNIQUE SCAN              | WSH_NEW_DELIVERIES_U1       |    101K|      1 |  87104 |00:00:43.17 |     174K|  13273 |       |       |          |
|  29 |            TABLE ACCESS BY INDEX ROWID      | OE_ORDER_HEADERS_ALL        |    751 |      1 |    751 |00:00:03.00 |    2255 |    452 |       |       |          |
|* 30 |             INDEX UNIQUE SCAN               | OE_ORDER_HEADERS_U1         |    751 |      1 |    751 |00:00:01.22 |    1504 |    207 |       |       |          |
|* 31 |           TABLE ACCESS BY INDEX ROWID       | HZ_CUST_SITE_USES_ALL       |    751 |      1 |    751 |00:00:01.20 |    2255 |    178 |       |       |          |
|* 32 |            INDEX UNIQUE SCAN                | HZ_CUST_SITE_USES_U1        |    751 |      1 |    751 |00:00:00.59 |    1504 |     81 |       |       |          |
|  33 |          TABLE ACCESS BY INDEX ROWID        | HZ_CUST_ACCT_SITES_ALL      |    751 |      1 |    751 |00:00:00.88 |    2255 |    156 |       |       |          |
|* 34 |           INDEX UNIQUE SCAN                 | HZ_CUST_ACCT_SITES_U1       |    751 |      1 |    751 |00:00:00.41 |    1504 |     76 |       |       |          |
|  35 |         TABLE ACCESS BY INDEX ROWID         | HZ_PARTY_SITES              |    751 |      1 |    751 |00:00:00.73 |    1504 |    149 |       |       |          |
|* 36 |          INDEX UNIQUE SCAN                  | HZ_PARTY_SITES_U1           |    751 |      1 |    751 |00:00:00.33 |     753 |     74 |       |       |          |
|  37 |        TABLE ACCESS BY INDEX ROWID          | HZ_LOCATIONS                |    751 |      1 |    751 |00:00:00.73 |    1504 |    137 |       |       |          |
|* 38 |         INDEX UNIQUE SCAN                   | HZ_LOCATIONS_U1             |    751 |      1 |    751 |00:00:00.17 |     753 |     47 |       |       |          |
|  39 |       TABLE ACCESS BY INDEX ROWID           | FND_TERRITORIES             |    751 |      1 |    751 |00:00:00.01 |     753 |      1 |       |       |          |
|* 40 |        INDEX UNIQUE SCAN                    | FND_TERRITORIES_U1          |    751 |      1 |    751 |00:00:00.01 |       2 |      1 |       |       |          |
|  41 |      TABLE ACCESS BY INDEX ROWID            | HZ_PARTIES                  |    751 |      1 |    751 |00:00:00.64 |    1504 |     98 |       |       |          |
|* 42 |       INDEX UNIQUE SCAN                     | HZ_PARTIES_U1               |    751 |      1 |    751 |00:00:00.26 |     753 |     44 |       |       |          |
|* 43 |     TABLE ACCESS BY INDEX ROWID             | HZ_CUST_ACCOUNTS            |    751 |      1 |    749 |00:00:00.31 |    1504 |     69 |       |       |          |
|* 44 |      INDEX UNIQUE SCAN                      | HZ_CUST_ACCOUNTS_U1         |    751 |      1 |    751 |00:00:00.05 |     753 |     16 |       |       |          |
Predicate Information (identified by operation id):
   1 - filter(COUNT(*)>=1)
  17 - filter(("OEL"."ORG_ID"=189 AND INTERNAL_FUNCTION("OEL"."ATTRIBUTE1")))
  18 - access(("OEL"."SUBINVENTORY"='AFGI' OR "OEL"."SUBINVENTORY"='FGIF' OR "OEL"."SUBINVENTORY"='KFGI' OR "OEL"."SUBINVENTORY"='SFGIF'))
  20 - access("OEL"."INVENTORY_ITEM_ID"="MSI"."INVENTORY_ITEM_ID" AND "MSI"."ORGANIZATION_ID"=65)
  21 - filter(("CCM"."DESIGNAPPLICATION"='ESG' OR "CCM"."DESIGNAPPLICATION"='NSG' OR "CCM"."DESIGNAPPLICATION"='PSG'))
  22 - access("MSI"."DESCRIPTION"="CCM"."STMODELNUMBER")
  24 - access("OEL"."LINE_ID"="WDD"."SOURCE_LINE_ID")
  26 - access("WDD"."DELIVERY_DETAIL_ID"="WDA"."DELIVERY_DETAIL_ID")
  27 - filter(("WND"."STATUS_CODE"='CL' AND TRUNC(INTERNAL_FUNCTION("WND"."CONFIRM_DATE"))>=TO_DATE(' 2009-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
              TRUNC(INTERNAL_FUNCTION("WND"."CONFIRM_DATE"))<TO_DATE(' 2009-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss')))
  28 - access("WDA"."DELIVERY_ID"="WND"."DELIVERY_ID")
  30 - access("OEH"."HEADER_ID"="OEL"."HEADER_ID")
  31 - filter("SHC"."SITE_USE_CODE"='SHIP_TO')
  32 - access("OEH"."SHIP_TO_ORG_ID"="SHC"."SITE_USE_ID")
  34 - access("SHC"."CUST_ACCT_SITE_ID"="SHAC"."CUST_ACCT_SITE_ID")
  36 - access("SHAC"."PARTY_SITE_ID"="SHPS"."PARTY_SITE_ID")
  38 - access("SHPS"."LOCATION_ID"="SHLC"."LOCATION_ID")
  40 - access("SHLC"."COUNTRY"="FT"."TERRITORY_CODE")
  42 - access("HP"."PARTY_ID"="SHPS"."PARTY_ID")
  43 - filter(("HCA"."SALES_CHANNEL_CODE"<>'RTL' AND "HCA"."SALES_CHANNEL_CODE"<>'AD-RTL' AND "HCA"."SALES_CHANNEL_CODE"<>'EU'))
  44 - access("HCA"."CUST_ACCOUNT_ID"="SHAC"."CUST_ACCOUNT_ID")
86 rows selected.

Similar Messages

  • How to execute this SQL Query in ABAP Program.

    Hi,
    I have a string which is the SQL Query.
    How to execute this sql Query (SQL_STR) in ABAP Program.
    Code:-
    DATA: SQL_STR type string.
    SQL_STR = 'select * from spfli.'.
    Thanks in Advance,
    Vinay

    Hi Vinay
    Here is a sample to dynamically generate a subroutine-pool having your SQL and calling it.
    REPORT dynamic_sql_example .
    DATA: BEGIN OF gt_itab OCCURS 1 ,
    line(80) TYPE c ,
    END OF gt_itab .
    DATA gt_restab TYPE .... .
    DATA gv_name(30) TYPE c .
    DATA gv_err(120) TYPE c .
    START-OF-SELECTION .
    gt_itab-line = 'REPORT generated_sql .' .
    APPEND gt_itab .
    gt_itab-line = 'FORM exec_sql CHANGING et_table . ' .
    APPEND gt_itab .
    gt_itab-line = SQL_STR .
    APPEND gt_itab .
    gt_itab-line = 'ENDFORM.' .
    APPEND gt_itab .
    GENERATE SUBROUTINE POOL gt_itab NAME gv_name MESSAGE gv_err .
    PERFORM exec_sql IN PROGRAM (gv_name) CHANGING gt_restab
    IF FOUND .
    WRITE:/ gv_err .
    LOOP AT gt_result .
    WRITE:/ .... .
    ENDLOOP .
    *--Serdar

  • Is it possible in PLD to add sql query ?

    Hi
    In Order report in PLD , i need to add the total amount of down payment . it doesn't exists in Order , so i need to do a sql query to display this amount .
    is it possible to add sql query in pld formula ?
    thanks ,
    regards
    laurent

    Hi,
    You cannot add sql query in PLD.If you need SQL query use Crystal report or on the document add UDF and try by adding FMS and then selecting UDF in pld
    Thanks,
    Neetu

  • How to convert this SQL query to PL/SQL

    I basically need to create an anonymous block that will display each student's first name, last name and the count of students who scored less on test 1 than the student.
    So basically we need to find the count of students who have scored less than that particular student and we do it for all students in the table.
    So for this particular query i designed my code in SQL
    select g1.gr_fname, g1.gr_lname, count(*)
    from grade g1, grade g2
    where g1.gr_t1 > g2.gr_t1 and
    g1.std_code = g2.std_code
    group by g1.gr_fname, g1.gr_lname;
    But i am unable to get the logic as to how to execute it in PL/SQL,I am missing something a minor detail to execute the same in PL/SQL
    could someone please help me with the logic.
    Thanks

    Hi welcome to the forum try some thing below
    SQL> DECLARE
      2     CURSOR c1
      3     IS
      4        SELECT   ename, sal, d.deptno
      5            FROM scott.emp e, scott.dept d
      6           WHERE e.deptno = d.deptno
      7        GROUP BY ename, sal, d.deptno;
      8  BEGIN
      9     FOR c2 IN c1
    10     LOOP
    11        DBMS_OUTPUT.put_line ('name is  ' || c2.ename);
    12     END LOOP;
    13  END;
    14  /
    name is  CLARK
    name is  KING
    name is  JONES
    name is  MARTIN
    name is  FORD
    name is  SCOTT
    name is  ALLEN
    name is  TURNER
    name is  WARD
    name is  MILLER
    name is  ADAMS
    name is  BLAKE
    name is  JAMES
    name is  SMITH
    PL/SQL procedure successfully completed.This is just to demonstrate the use of PL/SQL block

  • Please help me with this SQL query

    I am practicing SQL queries and have come across one involving fetching data from 3 different tables.
    The three tables are as below
    <pre>
    Country
    location_id          country
    loc1          Spain
    loc2          England
    loc3          Spain
    loc4          USA
    loc5          Italy
    loc6          USA
    loc7          USA
    </pre>
    <pre>
    User
    user_id location_id
    u1 loc1
    u2 loc1
    u3 loc2
    u4 loc2
    u5 loc1
    u6 loc3
    </pre>
    <pre>
    Post
    post_id user_id
    p1 u1
    p2 u1
    p3 u2
    p4 u3
    p5 u1
    p6 u2
    </pre>
    I am trying to write an SQL query - for each country of users, display the average number of posts
    I understand the logic behind this that we first need to group together all the locations and then the users belonging to one country and then find the average of their posts.
    But, i'm having a difficulty in putting this in SQL form. Could someone please help me with this query.
    Thanks.

    select
    country.country,
    count(*) Totalpostspercountry,
    count(distinct post.user_id) Totaldistincuserspercountry,
    count(*)/count(distinct post.user_id) Avgpostsperuserbycountry
    from
    country, muser, post
    where country.location_id = muser.location_id
    and muser.user_id = post.user_id
    group by country.country
    The output is like this for your sample data - hope this is what you were looking for :)
    COUNTRY,TOTALPOSTSPERCOUNTRY,TOTALDISTINCUSERSPERCOUNTRY,AVGPOSTSPERUSERBYCOUNTRY
    England,1,1,1,
    Spain,5,2,2.5,

  • How to use this sql query in oracle?

    Hi all,
    i am using one sql query that is
    SELECT @ToDate = '2012-10-03 00:00:00.000'
    select @BetweenDate = DATEADD(MM,-1,@ToDate)
    select @FromDate = DATEADD(m,DATEDIFF(m,0,@BetweenDate),0)
    SELECT @ToDate = DATEADD(month, ((YEAR(@BetweenDate) - 1900) * 12) + MONTH(@BetweenDate), -1)
    so @todate value is = '2012-10-03 00:00:00.000'
    so in @betweendate value will come 1 month before like '2012-09-03 00:00:00.000'
    again in @fromdate value will come like that '2012-09-01 00:00:00.000' means first date of @betweendate
    and again @todate value will come like that '2012-09-30 00:00:00.000' means last date of @betweendate
    it's happening in sql and i have to use same logic in oracle also.
    how to use it??
    thanks

    declare
    todate date:= to_date('2012-10-03 00:00:00','yyyy-mm-dd hh:mi:ss');
    betwendate date := add_months(todate,-1);
    for datediff / additions you can direct subtract/add two different date variables
    like
    datediff = betweendate -todate
    dateadd := todate+1;

  • Enhance a SQL query with update of millions of rows

    Hi ,
    I have this query developed to updated around 200 million of rows on my production , I did my best but please need your recommendations\concerns to make it more enhanced
    DECLARE @ORIGINAL_ID AS BIGINT
    SELECT FID001 INTO #Temp001_
    FROM INBA004 WHERE RS_DATE>='1999-01-01'
    AND RS_DATE<'2014-01-01' AND CLR_f1st='SSLM'
    and FID001 >=12345671
    WHILE (SELECT COUNT(*) FROM #Temp001_ ) <>0
    BEGIN
    SELECT TOP 1 @ORIGINAL_ID=FID001 FROM #Temp001_ ORDER BY FID001
    PRINT CAST (@ORIGINAL_ID AS VARCHAR(100))+' STARTED'
    SELECT DISTINCT FID001
    INTO #OUT_FID001
    FROM OUTTR009 WHERE TRANSACTION_ID IN (SELECT TRANSACTION_ID FROM
    INTR00100 WHERE FID001 = @ORIGINAL_ID)
    UPDATE A SET RCV_Date=B.TIME_STAMP
    FROM OUTTR009 A INNER JOIN INTR00100 B
    ON A.TRANSACTION_ID=B.TRANSACTION_ID
    WHERE A.FID001 IN (SELECT FID001 FROM #OUT_FID001)
    AND B.FID001=@ORIGINAL_ID
    UPDATE A SET Sending_Date=B.TIME_STAMP
    FROM INTR00100 A INNER JOIN OUTTR009 B
    ON A.TRANSACTION_ID=B.TRANSACTION_ID
    WHERE A.FID001=@ORIGINAL_ID
    AND B.FID001 IN (SELECT FID001 FROM #OUT_FID001)
    DELETE FROM #Temp001_ WHERE FID001=@ORIGINAL_ID
    DROP TABLE #OUT_FID001
    PRINT CAST (@ORIGINAL_ID AS VARCHAR(100))+' FINISHED'
    END

    DECLARE @x INT
    SET @x = 1
    WHILE @x < 44,000,000  -- Set appropriately
    BEGIN
        UPDATE Table SET a = c+d where ID BETWEEN @x AND @x + 10000
        SET @x = @x + 10000
    END
    Make sure that ID column has a CI on.
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to tune this SQL Query?

    Hi all expert out there,
    I am using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, OLAP, Data Mining and Real Application Testing options.
    I have this ERP 11i query took 3-4hours to execute. can anyone help to have a look at the Query so make it more faster? I am already out of my idea of solving this. Kindly helpzzz...
    SELECT
    /*+ first_rows(1)*/
    hou.name "OU" ,-- e.g. Seagate Technology USOP1 ,
    mc.description,
    oel.ordered_item "Product Part Number",
    oeh.order_number "Order Num",
    hp.party_name "Bill To Cust Name",
    hcsu.location "Ship To Cust Num",
    oel.line_number || '.' || oel.shipment_number "Order Line Num",
    ft.nls_territory "Ship To Country",
    mc.segment7 "designapplication",
    ccm.formattedcapacity||'GB' "Capacity",
    oel.attribute1 "Order Category",
    oel.Subinventory "Subinventory",
    to_char(oel.actual_shipment_date,'MM/DD/YYYY DY') "Shipment Date",
    NVL(oel.shipped_quantity,0) "Net Units"
    FROM
    oe_order_headers_all oeh
    ,oe_order_lines_all oel
    ,apps.hz_parties hp
    ,apps.hz_cust_accounts hca
    ,apps.hz_cust_site_uses_all hcsu
    ,apps.hz_cust_acct_sites_all hcas
    , apps.seaeng_ccfamilymodelinfo ccm
    ,apps.hz_party_sites hps
    ,apps.fnd_territories ft
    ,apps.hz_locations hl
    ,apps.hr_organization_units hou
    ,apps.mtl_parameters mp
    ,apps.mtl_item_categories mic
    ,apps.mtl_categories_b mc
    ,apps.fnd_lookup_values flv
    WHERE
    oeh.header_id = oel.header_id
    AND oel.flow_status_code = 'CLOSED'
    AND oeh.invoice_to_org_id = hcsu.site_use_id
    AND hl.country = ft.territory_code
    AND hps.location_id = hl.location_id
    AND hcas.party_site_id = hps.party_site_id
    AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id
    AND hcas.cust_account_id = hca.cust_account_id
    AND hca.party_id = hp.party_id
    AND oeh.org_id = hou.organization_id
    AND oel.ship_from_org_id = mp.organization_id
    AND oel.inventory_item_id = mic.inventory_item_id
    AND mic.category_id = mc.category_id
    AND mic.category_set_id = 4
    AND mc.description = ccm.stmodelnumber
    AND flv.lookup_code = hca.sales_channel_code
    AND flv.lookup_type = 'SALES_CHANNEL'
    AND mc.segment7 IN ('PSG','ESG','NSG')
    AND flv.lookup_code NOT IN ('RTL','AD-RTL','EU')
    AND oel.attribute1 IN ('NB','NBEOL','NBSEA')
    AND oel.subinventory IN ('KFGI','AFGI','SFGIF','FGIF')
    AND hou.organization_id = 189
    AND trunc(oel.actual_shipment_date) between TO_DATE('01-Jan-2009','DD-MON-YYYY') and TO_DATE('31-JAN-2009','DD-MON-YYYY')
    regards,
    Lygine
    Edited by: user8989062 on Jun 7, 2010 6:39 PM

    5) The TKPROF output for this statement looks like the following:
    SELECT
    /*+ first_rows(1)*/
    hou.name "OU" ,-- e.g. Seagate Technology USOP1 ,
    mc.description,
    oel.ordered_item "Product Part Number",
    oeh.order_number "Order Num",
      hp.party_name  "Bill To Cust Name",
    hcsu.location "Ship To Cust Num",
    oel.line_number || '.' || oel.shipment_number "Order Line Num",
    ft.nls_territory  "Ship To Country",
    mc.segment7 "designapplication",
    ccm.formattedcapacity||'GB' "Capacity",
    oel.attribute1 "Order Category",
    oel.Subinventory "Subinventory",
    to_char(oel.actual_shipment_date,'MM/DD/YYYY DY') "Shipment Date",
    NVL(oel.shipped_quantity,0) "Net Units"
    FROM
          oe_order_headers_all oeh
         ,oe_order_lines_all   oel
         ,apps.hz_parties  hp
         ,apps.hz_cust_accounts  hca
         ,apps.hz_cust_site_uses_all   hcsu
         ,apps.hz_cust_acct_sites_all  hcas
        , apps.seaeng_ccfamilymodelinfo ccm
         ,apps.hz_party_sites hps
         ,apps.fnd_territories ft
         ,apps.hz_locations hl
         ,apps.hr_organization_units  hou
         ,apps.mtl_parameters  mp
         ,apps.mtl_item_categories mic
         ,apps.mtl_categories_b mc
         ,apps.fnd_lookup_values flv
    WHERE
               oeh.header_id = oel.header_id
    AND   oel.flow_status_code = 'CLOSED'
    AND   oeh.invoice_to_org_id = hcsu.site_use_id
    AND   hl.country = ft.territory_code
    AND   hps.location_id = hl.location_id
    AND   hcas.party_site_id = hps.party_site_id
    AND   hcsu.cust_acct_site_id = hcas.cust_acct_site_id
    AND   hcas.cust_account_id = hca.cust_account_id
    AND   hca.party_id   = hp.party_id
    AND   oeh.org_id = hou.organization_id
    AND   oel.ship_from_org_id = mp.organization_id
    AND   oel.inventory_item_id = mic.inventory_item_id
    AND   mic.category_id = mc.category_id
    AND   mic.category_set_id = 4
    AND   mc.description = ccm.stmodelnumber
    AND   flv.lookup_code = hca.sales_channel_code
    AND   flv.lookup_type = 'SALES_CHANNEL'
    AND mc.segment7 IN ('PSG','ESG','NSG')
    AND flv.lookup_code NOT IN ('RTL','AD-RTL','EU')
    AND oel.attribute1 IN ('NB','NBEOL','NBSEA')
    AND oel.subinventory IN ('KFGI','AFGI','SFGIF','FGIF')
    AND hou.organization_id = 189
    AND trunc(oel.actual_shipment_date) between TO_DATE('01-Jan-2009','DD-MON-YYYY') and TO_DATE('31-JAN-2009','DD-MON-YYYY')
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.79       0.79          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        7     22.23     240.85      19781     536082          0         592
    total        9     23.02     241.64      19781     536082          0         592
    Misses in library cache during parse: 1
    Optimizer mode: FIRST_ROWS
    Parsing user id: 173 
    Rows     Row Source Operation
        592  NESTED LOOPS  (cr=536082 pr=19781 pw=0 time=240822989 us)
        592   NESTED LOOPS  (cr=534885 pr=19776 pw=0 time=239960969 us)
        592    NESTED LOOPS  (cr=533688 pr=19776 pw=0 time=239902332 us)
        594     NESTED LOOPS  (cr=532493 pr=19776 pw=0 time=239811721 us)
        594      NESTED LOOPS  (cr=531892 pr=19776 pw=0 time=239794703 us)
        594       NESTED LOOPS  (cr=530693 pr=19772 pw=0 time=239325284 us)
        594        NESTED LOOPS  (cr=529498 pr=19770 pw=0 time=239152940 us)
        594         NESTED LOOPS  (cr=527709 pr=19766 pw=0 time=236850676 us)
        594          NESTED LOOPS  (cr=525920 pr=19764 pw=0 time=235640068 us)
       2990           NESTED LOOPS  (cr=516943 pr=19688 pw=0 time=195144282 us)
       2990            NESTED LOOPS  (cr=516936 pr=19688 pw=0 time=195120297 us)
       2990             NESTED LOOPS  (cr=510806 pr=19682 pw=0 time=194678671 us)
       3000              HASH JOIN  (cr=504799 pr=19669 pw=0 time=193829763 us)
       3000               NESTED LOOPS  (cr=472280 pr=360 pw=0 time=49218087 us)
          1                NESTED LOOPS  (cr=1029 pr=34 pw=0 time=1745829 us)
          1                 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS_TL (cr=424 pr=25 pw=0 time=1361442 us)
          1                  INDEX UNIQUE SCAN HR_ALL_ORGANIZATION_UNTS_TL_PK (cr=423 pr=25 pw=0 time=1361397 us)(object id 44637)
          1                 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS (cr=605 pr=9 pw=0 time=384370 us)
          1                  INDEX UNIQUE SCAN HR_ORGANIZATION_UNITS_PK (cr=1 pr=0 pw=0 time=27 us)(object id 43498)
       3000                TABLE ACCESS BY INDEX ROWID OE_ORDER_LINES_ALL (cr=471251 pr=326 pw=0 time=47466249 us)
    156922                 INDEX RANGE SCAN OE_ORDER_LINES_N20 (cr=420 pr=7 pw=0 time=787919 us)(object id 37005064)
    263469               TABLE ACCESS FULL MTL_ITEM_CATEGORIES (cr=32519 pr=19309 pw=0 time=144242743 us)
       2990              TABLE ACCESS BY INDEX ROWID MTL_CATEGORIES_B (cr=6007 pr=13 pw=0 time=843569 us)
       3000               INDEX UNIQUE SCAN MTL_CATEGORIES_B_U1 (cr=3007 pr=2 pw=0 time=162636 us)(object id 37199)
       2990             TABLE ACCESS BY INDEX ROWID SEAENG_CCFAMILYMODELINFO (cr=6130 pr=6 pw=0 time=437784 us)
       2990              INDEX UNIQUE SCAN SEAENG_CCFAMILYMODELINFO_U1 (cr=2997 pr=0 pw=0 time=52872 us)(object id 35838918)
       2990            INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=7 pr=0 pw=0 time=16332 us)(object id 37657)
        594           TABLE ACCESS BY INDEX ROWID OE_ORDER_HEADERS_ALL (cr=8977 pr=76 pw=0 time=40491633 us)
       2990            INDEX UNIQUE SCAN OE_ORDER_HEADERS_U1 (cr=5987 pr=45 pw=0 time=2504442 us)(object id 41952)
        594          TABLE ACCESS BY INDEX ROWID HZ_CUST_SITE_USES_ALL (cr=1789 pr=2 pw=0 time=1208576 us)
        594           INDEX UNIQUE SCAN HZ_CUST_SITE_USES_U1 (cr=1195 pr=1 pw=0 time=105934 us)(object id 25124976)
        594         TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCT_SITES_ALL (cr=1789 pr=4 pw=0 time=2300224 us)
        594          INDEX UNIQUE SCAN HZ_CUST_ACCT_SITES_U1 (cr=1195 pr=2 pw=0 time=152238 us)(object id 25124996)
        594        TABLE ACCESS BY INDEX ROWID HZ_PARTY_SITES (cr=1195 pr=2 pw=0 time=170875 us)
        594         INDEX UNIQUE SCAN HZ_PARTY_SITES_U1 (cr=601 pr=1 pw=0 time=104550 us)(object id 25124993)
        594       TABLE ACCESS BY INDEX ROWID HZ_LOCATIONS (cr=1199 pr=4 pw=0 time=467329 us)
        594        INDEX UNIQUE SCAN HZ_LOCATIONS_U1 (cr=601 pr=0 pw=0 time=57749 us)(object id 25124992)
        594      TABLE ACCESS BY INDEX ROWID FND_TERRITORIES (cr=601 pr=0 pw=0 time=15562 us)
        594       INDEX UNIQUE SCAN FND_TERRITORIES_U1 (cr=7 pr=0 pw=0 time=6492 us)(object id 33083)
        592     TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCOUNTS (cr=1195 pr=0 pw=0 time=88925 us)
        594      INDEX UNIQUE SCAN HZ_CUST_ACCOUNTS_U1 (cr=601 pr=0 pw=0 time=27607 us)(object id 81600)
        592    INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=1197 pr=0 pw=0 time=56714 us)(object id 32878)
        592   TABLE ACCESS BY INDEX ROWID HZ_PARTIES (cr=1197 pr=5 pw=0 time=860140 us)
        592    INDEX UNIQUE SCAN HZ_PARTIES_U1 (cr=599 pr=0 pw=0 time=51136 us)(object id 25126074)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       7        0.00          0.00
      row cache lock                                  1        0.00          0.00
      gc current block 2-way                      24112        0.00         19.28
      gc cr grant 2-way                             406        0.00          0.19
      db file sequential read                       441        0.09         14.11
      gc cr block 2-way                             284        0.00          0.23
      gc cr block busy                              147        0.19          9.59
      gc current block congested                      2        0.00          0.00
      gc cr multi block request                   13079        0.00          3.98
      SQL*Net message from client                     7        0.27          1.87
      gc cr failure                                  39        0.00          0.02
      cr request retry                               39        0.98         38.27
      SQL*Net more data to client                    12        0.00          0.00
      db file scattered read                       2446        0.13        132.58
      gc cr disk read                                 5        0.00          0.00
    ********************************************************************************6) The DBMS_XPLAN.DISPLAY_CURSOR output:
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    PLAN_TABLE_OUTPUT
    SQL_ID  b8pfhfxscqn1m, child number 0
    SELECT  /*+ gather_plan_statistics */  hou.name "OU" ,-- e.g. Seagate Technology USOP1 ,  mc.descript
    oeh.order_number "Order Num",   hp.party_name  "Bill To Cust Name",  hcsu.location "Ship To Cust Num",
    Num",  ft.nls_territory  "Ship To Country",  mc.segment7 "designapplication",  ccm.formattedcapacity
    oel.Subinventory "Subinventory",  to_char(oel.actual_shipment_date,'MM/DD/YYYY DY') "Shipment Date",
    oe_order_headers_all oeh      ,oe_order_lines_all   oel      ,apps.hz_parties  hp      ,apps.hz_cust
    ,apps.hz_cust_acct_sites_all  hcas     , apps.seaeng_ccfamilymodelinfo ccm      ,apps.hz_party_sites hps
        ,apps.hr_organization_units  hou      ,apps.mtl_paramete
    Plan hash value: 414863479
    | Id  | Operation                                  | Name                           | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |  O
    |   1 |  NESTED LOOPS                              |                                |      1 |      1 |    592 |00:02:25.13 |     535K|  57267 |       |
    |   2 |   NESTED LOOPS                             |                                |      1 |      1 |    592 |00:02:24.22 |     533K|  57185 |      
    |   3 |    NESTED LOOPS                            |                                |      1 |      1 |    592 |00:02:24.15 |     532K|  57183 |     
    |   4 |     NESTED LOOPS                           |                                |      1 |      1 |    594 |00:02:24.00 |     531K|  57171 |     
    |   5 |      NESTED LOOPS                          |                                |      1 |      1 |    594 |00:02:23.98 |     530K|  57170 |    
    |   6 |       NESTED LOOPS                         |                                |      1 |      1 |    594 |00:02:23.49 |     529K|  57129 |   
    |   7 |        NESTED LOOPS                        |                                |      1 |      1 |    594 |00:02:23.08 |     528K|  57096 |  
    |   8 |         NESTED LOOPS                       |                                |      1 |      1 |    594 |00:02:22.51 |     526K|  57031 |       |
    |   9 |          NESTED LOOPS                      |                                |      1 |      1 |    594 |00:02:21.79 |     524K|  56968 |       |
    |  10 |           NESTED LOOPS                     |                                |      1 |      1 |   2990 |00:02:09.65 |     515K|  55703 |      
    |  11 |            NESTED LOOPS                    |                                |      1 |      1 |   2990 |00:02:09.62 |     515K|  55703 |     
    |  12 |             NESTED LOOPS                   |                                |      1 |      1 |   2990 |00:02:08.47 |     509K|  55599 |     
    |* 13 |              HASH JOIN                     |                                |      1 |      2 |   3000 |00:02:07.88 |     503K|  55516 |   974K
    |  14 |               NESTED LOOPS                 |                                |      1 |      2 |   3000 |00:01:39.07 |     471K|  23025 |   
    |  15 |                NESTED LOOPS                |                                |      1 |      1 |      1 |00:00:00.01 |       4 |      0 |  
    |  16 |                 TABLE ACCESS BY INDEX ROWID| HR_ALL_ORGANIZATION_UNITS_TL   |      1 |      1 |      1 |00:00
    |* 17 |                  INDEX UNIQUE SCAN         | HR_ALL_ORGANIZATION_UNTS_TL_PK |      1 |      1 |      1 |00:00:00.0
    |* 18 |                 TABLE ACCESS BY INDEX ROWID| HR_ALL_ORGANIZATION_UNITS      |      1 |      1 |      1 |00:00:
    |* 19 |                  INDEX UNIQUE SCAN         | HR_ORGANIZATION_UNITS_PK       |      1 |      1 |      1 |00:00:00.01
    |* 20 |                TABLE ACCESS BY INDEX ROWID | OE_ORDER_LINES_ALL             |      1 |      2 |   3000 |00:01
    |* 21 |                 INDEX RANGE SCAN           | OE_ORDER_LINES_N20             |      1 |  47575 |    156K|00:00:01.76 |     420
    |* 22 |               TABLE ACCESS FULL            | MTL_ITEM_CATEGORIES            |      1 |  96977 |    263K|00:00:28.49
    |* 23 |              TABLE ACCESS BY INDEX ROWID   | MTL_CATEGORIES_B               |   3000 |      1 |   2990 |00:00:0
    |* 24 |               INDEX UNIQUE SCAN            | MTL_CATEGORIES_B_U1            |   3000 |      1 |   3000 |00:00:00.21
    |  25 |             TABLE ACCESS BY INDEX ROWID    | SEAENG_CCFAMILYMODELINFO       |   2990 |      1 |   2990 |
    |* 26 |              INDEX UNIQUE SCAN             | SEAENG_CCFAMILYMODELINFO_U1    |   2990 |      1 |   2990 |00:00:
    |* 27 |            INDEX UNIQUE SCAN               | MTL_PARAMETERS_U1              |   2990 |      1 |   2990 |00:00:00.02 |    
    |* 28 |           TABLE ACCESS BY INDEX ROWID      | OE_ORDER_HEADERS_ALL           |   2990 |      1 |    594 |00:00:
    |* 29 |            INDEX UNIQUE SCAN               | OE_ORDER_HEADERS_U1            |   2990 |      1 |   2990 |00:00:04.29 |   
    |  30 |          TABLE ACCESS BY INDEX ROWID       | HZ_CUST_SITE_USES_ALL          |    594 |      1 |    594 |00:00:
    |* 31 |           INDEX UNIQUE SCAN                | HZ_CUST_SITE_USES_U1           |    594 |      1 |    594 |00:00:00.31 |   
    |  32 |         TABLE ACCESS BY INDEX ROWID        | HZ_CUST_ACCT_SITES_ALL         |    594 |      1 |    594 |00:00:
    |* 33 |          INDEX UNIQUE SCAN                 | HZ_CUST_ACCT_SITES_U1          |    594 |      1 |    594 |00:00:00.23 |   
    |  34 |        TABLE ACCESS BY INDEX ROWID         | HZ_PARTY_SITES                 |    594 |      1 |    594 |00:00:0
    |* 35 |         INDEX UNIQUE SCAN                  | HZ_PARTY_SITES_U1              |    594 |      1 |    594 |00:00:00.17 |     601
    |  36 |       TABLE ACCESS BY INDEX ROWID          | HZ_LOCATIONS                   |    594 |      1 |    594 |00:00:00.4
    |* 37 |        INDEX UNIQUE SCAN                   | HZ_LOCATIONS_U1                |    594 |      1 |    594 |00:00:00.17 |   
    |  38 |      TABLE ACCESS BY INDEX ROWID           | FND_TERRITORIES                |    594 |      1 |    594 |00:00:00
    |* 39 |       INDEX UNIQUE SCAN                    | FND_TERRITORIES_U1             |    594 |      1 |    594 |00:00:00.02
    |* 40 |     TABLE ACCESS BY INDEX ROWID            | HZ_CUST_ACCOUNTS               |    594 |      1 |    592 |00:00:0
    |* 41 |      INDEX UNIQUE SCAN                     | HZ_CUST_ACCOUNTS_U1            |    594 |      1 |    594 |00:00:00.04 |
    |* 42 |    INDEX RANGE SCAN                        | FND_LOOKUP_VALUES_U1           |    592 |      1 |    592 |00:00:00.06 |   
    |  43 |   TABLE ACCESS BY INDEX ROWID              | HZ_PARTIES                     |    592 |      1 |    592 |00:00:00.91 |  
    |* 44 |    INDEX UNIQUE SCAN                       | HZ_PARTIES_U1                  |    592 |      1 |    592 |00:00:00.40 |     599
    Predicate Information (identified by operation id):
      13 - access("OEL"."INVENTORY_ITEM_ID"="MIC"."INVENTORY_ITEM_ID")
      17 - access("HAOTL"."ORGANIZATION_ID"=189 AND "HAOTL"."LANGUAGE"=USERENV('LANG'))
           filter(DECODE("HR_SECURITY"."VIEW_ALL"(),'Y','TRUE',"HR_SECURITY"."SHOW_RECORD"('HR_ALL_ORGAN
      18 - filter("HAO"."BUSINESS_GROUP_ID"=DECODE("HR_GENERAL"."GET_XBG_PROFILE"(),'Y',"HAO"."BUSINESS_
      19 - access("HAO"."ORGANIZATION_ID"=189)
      20 - filter(("OEL"."FLOW_STATUS_CODE"='CLOSED' AND INTERNAL_FUNCTION("OEL"."ATTRIBUTE1") AND INTER
      21 - access("OEL"."SYS_NC00342$">=TO_DATE(' 2009-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "O
                  'syyyy-mm-dd hh24:mi:ss'))
      22 - filter("MIC"."CATEGORY_SET_ID"=4)
      23 - filter(("MC"."DESCRIPTION" IS NOT NULL AND INTERNAL_FUNCTION("MC"."SEGMENT7")))
      24 - access("MIC"."CATEGORY_ID"="MC"."CATEGORY_ID")
      26 - access("MC"."DESCRIPTION"="CCM"."STMODELNUMBER")
      27 - access("OEL"."SHIP_FROM_ORG_ID"="MP"."ORGANIZATION_ID")
      28 - filter("OEH"."ORG_ID"=189)
      29 - access("OEH"."HEADER_ID"="OEL"."HEADER_ID")
      31 - access("OEH"."INVOICE_TO_ORG_ID"="HCSU"."SITE_USE_ID")
      33 - access("HCSU"."CUST_ACCT_SITE_ID"="HCAS"."CUST_ACCT_SITE_ID")
      35 - access("HCAS"."PARTY_SITE_ID"="HPS"."PARTY_SITE_ID")
      37 - access("HPS"."LOCATION_ID"="HL"."LOCATION_ID")
      39 - access("HL"."COUNTRY"="FT"."TERRITORY_CODE")
      40 - filter(("HCA"."SALES_CHANNEL_CODE"<>'RTL' AND "HCA"."SALES_CHANNEL_CODE"<>'AD-RTL' AND "HCA".
      41 - access("HCAS"."CUST_ACCOUNT_ID"="HCA"."CUST_ACCOUNT_ID")
      42 - access("FLV"."LOOKUP_TYPE"='SALES_CHANNEL' AND "FLV"."LOOKUP_CODE"="HCA"."SALES_CHANNEL_CODE"
           filter(("FLV"."LOOKUP_CODE"<>'RTL' AND "FLV"."LOOKUP_CODE"<>'AD-RTL' AND "FLV"."LOOKUP_CODE"<
      44 - access("HCA"."PARTY_ID"="HP"."PARTY_ID")
    90 rows selected.
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              &nbs

  • How to get this sql query value in oracle query?

    Hi all,
    i am using one query in sql that is
    select @EarlyLeaversMin = DATEDIFF(Minute,@OutTime,@nshiftmax)
    suppose first line query is getting 60 minutes.
    select @EarlyLeaversMin1=DATEDIFF(Minute,@temphrs,@ShiftTime)
    second line query is also getting 60 minutes
    set @EarlyLeaversMin=@EarlyLeaversMin+@EarlyLeaversMin1+1
    and now here it's calculating both variable minutes and storing in @earlyleaversmin that should store like 60+60+1=121 mintes
    select @EarlyLeaverstimeformat = CONVERT(char(8),Dateadd(n,@EarlyLeaversMin,0),108)
    so now it will store in this query that value in this format : 01:21:00
    can i use the same which it's happening here??
    thanks

    Oracle handles dates and time very differently from SQL Server (as I gather others on this forum have already tried to explain to you).
    Anyway, Oracle does not have a TIME datetype, but what it does have are INTERVALs. In this case you would use INTERVAL DAY TO SECOND. It's not completely clear what you mean by "store in this query that value" but we can use INTERVALS as both table columns and PL/SQL variables.
    So your first query would be something like this:
    declare
        interval_var  INTERVAL DAY TO SECOND;
    begin
         select (nshiftmax - outtime) day to second
         into interval_var
         from whatever;We can do arithmetic with interval variables.
         select (nshiftmax - outtime) day to second +  (shifttime - temphrs) day to second
         into interval_var
         from whatever;To add a hard-coded interval such as 1 minute you can use this functionality:
         interval_var := interval_var + to_dsinterval('0 0:1:0');There's loads of info in the Oracle documentation. [url http://docs.oracle.com/cd/B28359_01/server.111/b28286/sql_elements001.htm#sthref115]Find out more.
    Cheers, APC

  • How to write this sql query in php code ?

    for example:
    insert into temp
    select *
    from testtable;
    after this, i will query data from sql below:
    select *
    from temp;
    how to write this php code ?
    who can help me ?
    thanks!

    Have a look at the manual to find out how to issue queries.
    http://us3.php.net/oci8

  • How to write this sql  query to oracle

    Hi sir,
    i am using one query in my sql stored procedure that is:
    select @maxtime=CONVERT(Time,Out_Time+DATEADD(n,60,0)) from shift where Shift_Code = @ShiftCode
    so here i am getting this value 01/01/1900 12:00 AM
    the same i used in oracle my query is :
    to_char(Out_Time,'1900-01-01' + 0/(24*60),'DD/MM/YYYY HH:MI AM')
    INTO v_maxtime
    FROM shift
    WHERE Shift_Code = v_ShiftCode;
    but getting error that is: Encountered the symbol INTO when expecting one of the following :=(%;
    am i doing any thing wrong.
    thanks

    APC wrote:
    The error you're getting is a syntax error. In this case because you've mangled the TO_CHAR syntax. Alas I cannot give you the correct version because I cannot unpick what you're trying to do with that statement.
    It would be easier if you expalined what business logic you're trying to implement instead of asking us to interpret a piece of shonky SQL.It's yet another of the OP's questions about how to do DATEs in Oracle (so many threads it can get very confusing - even though the OP has been asked to stick to one thread!).
    The code looks like it's based on the answer I gave here:
    How to get exact query of sql in oracle?
    but clearly he doesn't understand the basic syntax of Oracle or the datatypes he's using. Sometimes you just have to give up... (I know I have)

  • Can You Explain This SQL Query - Inline View Included

    The query is taken from "Oracle Database 10g: SQL Fundamentals II" page 3-7 (chapter 3)
    I do not fully understand the following query:
    SELECT a.last_name, a.salary, a.department_id, b.salavg
    FROM   employees a, (SELECT   department_id,
    AVG(salary) salavg
    FROM     employees
    GROUP BY department_id) b
    WHERE  a.department_id = b.department_id
    AND    a.salary > b.salavg;
    The inline view can return several records. Can you please tell me in step by step how does this work. I understand the concept of join tables and aliases, etc. I just need to know the mechanism of this code.
    Thanks

    user11164565 wrote:
    The query is taken from "Oracle Database 10g: SQL Fundamentals II" page 3-7 (chapter 3)
    I do not fully understand the following query:
    SELECT a.last_name, a.salary, a.department_id, b.salavg
    FROM   employees a, (SELECT   department_id,
    AVG(salary) salavg
    FROM     employees
    GROUP BY department_id) b
    WHERE  a.department_id = b.department_id
    AND    a.salary > b.salavg;
    The inline view can return several records. Can you please tell me in step by step how does this work. I understand the concept of join tables and aliases, etc. I just need to know the mechanism of this code.
    The query is returning the last name, salary , department and average salary of all the departments where salary is greater than the average salary.
    HTH
    Aman....

  • Isn't This SQL Query Correct?

    Hi Everyone,
    I was reading some tutorials about removing jobs. And i found out the query to be something like:
    EXECUTE DBMS_JOB.REMOVE(2);
    where 2 is the job number. I executed the same command and i get the error as "Invalid SQL Statement". Does this mean the tutorial is wrong? :(
    The link to the tutorial is:
    http://www.dbasupport.com/oracle/ora9i/jobqueue2.shtml

    from where are you executing the job...??
    exec(ute) is a sql plus command....you can use it only from sql plus...
    All editors which allow sql plus commands will accept above command. Sql developer won't accept exec command. So you need to write a pl/sql block there like
    begin
    DBMS_JOB.REMOVE(12);
    end;But from sql plus
    EXECUTE DBMS_JOB.REMOVE(2); is enough.
    Ravi Kumar

  • How Can I Make This Sql Query To Load Data Correctly (sql server)?

    Hi guys
    I have a datagridview where the third column is a custom column with all days
    of a month. It takes data with a query who distinct the column Improve.
    Here is the code :
    Private Sub fill_impro()
    dgImprove.Rows.Clear()
    Try
    Dim i As Integer = 0
    Dim query As String = "SELECT Improve,Price,Active,Idate FROM (SELECT Improve,Price,Active,Idate, ROW_NUMBER() OVER (PARTITION BY Price ORDER BY Price) AS rn FROM tblImprove) tmp WHERE rn = 1"
    cmd = New SqlCommand(query, clsMSSQL.con)
    myDR = cmd.ExecuteReader
    If myDR.HasRows Then
    While myDR.Read
    dgImprove.Rows.Add()
    dgImprove.Rows(i).Cells(0).Value = myDR.GetDecimal(myDR.GetOrdinal("Price"))
    dgImprove.Rows(i).Cells(1).Value = myDR.GetString(myDR.GetOrdinal("Improve"))
    Dim myday As Integer = DatePart(DateInterval.Day, myDR.GetValue(myDR.GetOrdinal("Idate")))
    dgImprove.Rows(i).Cells(myday + 1).Value = myDR.GetInt32(myDR.GetOrdinal("Active"))
    i = i + 1
    End While
    End If
    myDR.Close()
    Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.Critical, "Σφάλμα")
    End Try
    End Sub
    And here is the result :
    http://i60.tinypic.com/28gwf83.jpg
    The column Active value is 1.
    The problem is that column Active values are missing (red values in image).
    How can i fix that ?
    Thanks in advance

    try like this
    Dim Price As Decimal
    Dim improve As String = String.Empty
    While myDR.Read
    Dim myday As Integer = DatePart(DateInterval.Day, myDR.GetValue(myDR.GetOrdinal("Idate")))
    If Not (myDR.GetDecimal(myDR.GetOrdinal("Price")) = Price And myDR.GetString(myDR.GetOrdinal("Improve")) = improve) Then
    i += 1
    dgimprove.Rows.Add()
    dgimprove.Rows(i).Cells(0).Value = myDR.GetDecimal(myDR.GetOrdinal("Price"))
    dgimprove.Rows(i).Cells(1).Value = myDR.GetString(myDR.GetOrdinal("Improve"))
    Price = myDR.GetDecimal(myDR.GetOrdinal("Price"))
    improve = myDR.GetString(myDR.GetOrdinal("Improve"))
    End If
    dgimprove.Rows(i).Cells(myday + 1).Value = myDR.GetInt32(myDR.GetOrdinal("Active"))
    End While
    and change your sql statement to just
    SELECT Improve,Price,Active,Idate FROM tblImprove WHERE Active = 1

  • Strange in this sql query , kindly help

    I have aqry with ed_eff_m as some value and ed_end_m as NULL. I am replaing the NULL with sysdate. BOTH columns are TIMESTAMP
    subquery :
    SELECT MAX(ED_EFF_M),MAX(NVL(ED_END_M,SYSDATE))
    FROM AUDIT_GRN ag2
    where ag2.grn_n=281421
    This is giving two dates.
    when i execute another sql on top of this with the same condition, its not giving any result. (the same table and the same condition is used)
    SELECT OPT_WA_FAIR_VAL_A
    FROM AUDIT_GRN ag
    WHERE ag.GRN_N = 281421
    AND (ag.ED_EFF_M,NVL(ag.ED_END_M,SYSDATE)) IN
    SELECT MAX(ED_EFF_M),MAX(NVL(ED_END_M,SYSDATE))
    FROM AUDIT_GRN ag2
    WHERE ag2.grn_n=ag.grn_n
    )

    Hello, thanks for your reply.
    There is only one record which ed_eff_m = 04-Aug-2006 and Ed_END_M AS NULL.
    I am replacing the null with sysdate. I am getting the result with the subquery
    SELECT to_char(MAX(ED_EFF_M)),to_char(MAX(NVL(ED_END_M,SYSDATE)))
    FROM AUDIT_GRN ag2
    WHERE ag2.grn_n=281421
    04-AUG-06 12.24.13.764450 PM 17-AUG-06 12.57.59.000000 PM
    when i run the same query on top of this using IN clause, i should get the same result but its not ginving it. I am not using any other condition.
    SELECT OPT_WA_FAIR_VAL_A, ag.ED_EFF_M,NVL(ag.ED_END_M,SYSDATE)
    FROM AUDIT_GRN ag WHERE ag.GRN_N = 281421
    AND (to_char(ag.ED_EFF_M),to_char(NVL(ag.ED_END_M,SYSDATE))) IN (
    SELECT to_char(MAX(ED_EFF_M)),to_char(MAX(NVL(ED_END_M,SYSDATE)))
    FROM AUDIT_GRN ag2
    WHERE ag2.grn_n=281421)
    It should give me the same row, since the first query and second query is giving output when i execute it seperatly

Maybe you are looking for

  • Have i just read right that ur mac needs to run 10.6.8 or more to beable to sync the new ipad to itunes

    have i just read right that ur mac needs to run 10.6.8 or more to beable to sync the new ipad to itunes

  • Default Authorization object P_ABAP for PA20

    Dear colleagues! After SP implementation roles werу adjusted and new authorization check for P_ABAP was added for transaction PA* (PA20, PA30...). Where is hr-reporting checks in these transactions? It's critical for personnel data maintenance or use

  • How to delete the serv. P.R ?

    Dear  All,                                  I have created a serv. p r, then created a servP.O wrt this P.R, now i have to del. this PR, so i have deleted the line item of p.o, & then trying to del.this P.R, but as i del.the line item in ME52N, & the

  • Programatically focusing an XY graph

    I am working on a GPS application where I am plotting positions found in an XY graph. I've come sofar that I can see my trail and a dot of my current position. I've been trying to readjust the xy graph such that my current position stays in the middl

  • I cannot find my CS5 upgrade online to install on a new pc

    I have CD's for CS4, but when I upgraded to CS5 I simply downloaded the version.  Now I have a new laptop and I can't find my upgrade online with my Adobe account.  Any suggestions?