SQL Statement Tunning Request

Please help to tune the below query. I have provided following information
1. Query To be tuned
2. Parameter Relevant to Optimizer
3. Explain Plan and AutoTrace Ouput
4. Query traced at Level 8 and Its Tkprof Ouput
5. EXPLAIN PLAN output of DBMS_XPLAN.DISPLAY
INFORMATION 1. SQL QUERY TO BE TUNED
SELECT DISTINCT C.MAN_WIP_T_IN_TS,
C.RCP_NO,
C.WRK_CTR_ID,
C.WTR_FREE_TST_FLG,
A.COMPANY_ID,
A.PROD_ORDER,
A.PART_NO,
A.CARRIER_QTY,
B.PHY_CARID,
C.WIP_SEQ,
A.RCP_NO "CARRIER_RCP"
FROM dbadmintest.PF2_PROD_ORDER_CARRIER A,
PF2_PHYSICAL_CARRIER B,
WORK_IN_PROCESS C
WHERE C.UNIT_TYPE_CD = RTRIM('TL7')
AND C.UNIT_NM = RTRIM('T41')
AND C.WIP_TYPE_CD = 'HANDHELD'
AND C.PHY_CARRIER_SEQ = A.PHY_CARRIER_SEQ
AND A.PHY_CARRIER_SEQ = B.PHY_CARRIER_SEQ
AND ((A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS
AND A.CARRIER_UNLD_TS >= C.MAN_WIP_T_IN_TS)
OR ( A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS
AND A.CARRIER_UNLD_TS IS NULL))
AND ((A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_UNLD_TS <= TO_DATE('2012-01-12 10:03:00', 'YYYY-MM-DD HH24:MI:SS'))
OR (A.CARRIER_LD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS'))
OR (A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_UNLD_TS IS NULL)
OR (A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')))
ORDER BY 6,5,1
INFORMATION 2. PARAMETER RELEVANT TO 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      TRUE
db_file_multiblock_read_count      integer      16
cursor_sharing           string      EXACT
SQL> column sname format a20          
column pname format a20          
column pval2 format a20          
select          
sname          
, pname          
, pval1          
, pval2          
from sys.aux_stats$;SQL>      
SNAME      PNAME      PVAL1      PVAL2
SYSSTATS_INFO      STATUS           COMPLETED
SYSSTATS_INFO      DSTART           08-25-2009 07:27
SYSSTATS_INFO      DSTOP           08-25-2009 07:27
SYSSTATS_INFO      FLAGS      1
SYSSTATS_MAIN      CPUSPEEDNW      1592.87183
SYSSTATS_MAIN      IOSEEKTIM      10
SYSSTATS_MAIN      IOTFRSPEED      4096
SYSSTATS_MAIN      SREADTIM
SYSSTATS_MAIN      MREADTIM
SYSSTATS_MAIN      CPUSPEED
SYSSTATS_MAIN      MBRC
SYSSTATS_MAIN      MAXTHR
SYSSTATS_MAIN      SLAVETHR
INFORMATION 3. EXPLAIN PLAN AND AUTOTRACE OUTPUT
Execution Plan
Plan hash value: 850402268
| Id | Operation                | Name                | Rows      | Bytes      | Cost (%CPU)     | Time      |
| 0 | SELECT STATEMENT           |                | 11      | 1100      | 1568      (1)     | 00:00:19      |
| 1 | SORT UNIQUE                |                | 11      | 1100      | 1567      (1)     | 00:00:19      |
|* 2 | HASH JOIN                |                | 11      | 1100      | 1566      (1)     | 00:00:19      |
|* 3 | TABLE ACCESS BY INDEX ROWID      | PF2_PROD_ORDER_CARRIER      | 5      | 270      | 763      (0)     | 00:00:10      |
| 4 | NESTED LOOPS           |                | 11      | 1001      | 1562      (1)     | 00:00:19      |
|* 5 | TABLE ACCESS BY INDEX ROWID     | WORK_IN_PROCESS           | 2      | 74      | 35      (0)     | 00:00:01      |
|* 6 | INDEX RANGE SCAN           | WORK_IN_PROCESS_IX2           | 56      |      | 3      (0)     | 00:00:01      |
|* 7 | INDEX RANGE SCAN           | PF2_PROD_ORDER_CARRIER_IX3      | 2361      |      | 6      (0)     | 00:00:01      |
| 8 | TABLE ACCESS FULL           | PF2_PHYSICAL_CARRIER           | 1736      | 15624      | 4      (0)     | 00:00:01 |
Predicate Information (identified by operation id):
2 - access("A"."PHY_CARRIER_SEQ"="B"."PHY_CARRIER_SEQ")
3 - filter(("A"."CARRIER_UNLD_TS" IS NULL AND "A"."CARRIER_LD_TS"<=TO_DATE(' 2012-01-12 08:03:00',
'syyyy-mm-dd hh24:mi:ss') OR "A"."CARRIER_UNLD_TS">=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd
hh24:mi:ss') AND "A"."CARRIER_LD_TS"<=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss') OR
"A"."CARRIER_UNLD_TS">=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss') AND
"A"."CARRIER_UNLD_TS"<=TO_DATE(' 2012-01-12 10:03:00', 'syyyy-mm-dd hh24:mi:ss') OR
"A"."CARRIER_LD_TS"=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss')) AND
("A"."CARRIER_LD_TS"<="C"."MAN_WIP_T_IN_TS" AND "A"."CARRIER_UNLD_TS">="C"."MAN_WIP_T_IN_TS" OR
"A"."CARRIER_UNLD_TS" IS NULL AND "A"."CARRIER_LD_TS"<="C"."MAN_WIP_T_IN_TS"))
5 - filter("C"."WIP_TYPE_CD"='HANDHELD' AND "C"."PHY_CARRIER_SEQ" IS NOT NULL)
6 - access("C"."UNIT_TYPE_CD"='TL7' AND "C"."UNIT_NM"='T41')
7 - access("C"."PHY_CARRIER_SEQ"="A"."PHY_CARRIER_SEQ")
filter("A"."PHY_CARRIER_SEQ" IS NOT NULL)
Statistics
1           recursive calls
0           db block gets
13525998      consistent gets
7024           physical reads
0           redo size
1758           bytes sent via SQL*Net to client
492           bytes received via SQL*Net from client
2           SQL*Net roundtrips to/from client
1           sorts (memory)
0           sorts (disk)
14           rows processed
INFORMATION 4. QUERY TRACES AT LEVEL 8 AND TKPROF OUTPUT
TKPROF: Release 10.2.0.4.0 - Production on Wed Jan 18 01:48:53 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Trace file: ././ppf2_ora_5439924.trc
Sort options: default
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
SELECT DISTINCT C.MAN_WIP_T_IN_TS,
C.RCP_NO,
C.WRK_CTR_ID,
C.WTR_FREE_TST_FLG,
A.COMPANY_ID,
A.PROD_ORDER,
A.PART_NO,
A.CARRIER_QTY,
B.PHY_CARID,
C.WIP_SEQ,
A.RCP_NO "CARRIER_RCP"
FROM PF2_PROD_ORDER_CARRIER A,
PF2_PHYSICAL_CARRIER B,
WORK_IN_PROCESS C
WHERE C.UNIT_TYPE_CD = RTRIM('TL7')
AND C.UNIT_NM = RTRIM('T41')
AND C.WIP_TYPE_CD = 'HANDHELD'
AND C.PHY_CARRIER_SEQ = A.PHY_CARRIER_SEQ
AND A.PHY_CARRIER_SEQ = B.PHY_CARRIER_SEQ
AND ((A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS
AND A.CARRIER_UNLD_TS >= C.MAN_WIP_T_IN_TS)
OR ( A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS
AND A.CARRIER_UNLD_TS IS NULL))
AND ((A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_UNLD_TS <= TO_DATE('2012-01-12 10:03:00', 'YYYY-MM-DD HH24:MI:SS'))
OR (A.CARRIER_LD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS'))
OR (A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_UNLD_TS IS NULL)
OR (A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')))
ORDER BY 6,5,1
call      count      cpu      elapsed disk      query      current rows
Parse      1      0.00      0.00      0      0      0      0
Execute 1      0.00      0.00      0      0      0      0
Fetch      2      219.55      294.41      14030      13523455 0      14
total      4      219.55      294.41      14030      13523455 0      14
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: SYS
Rows           Row Source Operation
14           SORT UNIQUE (cr=13523455 pr=14030 pw=0 time=294417731 us)
14           HASH JOIN (cr=13523455 pr=14030 pw=0 time=294416444 us)
14           TABLE ACCESS BY INDEX ROWID PF2_PROD_ORDER_CARRIER (cr=13523440 pr=14030 pw=0 time=292675360 us)
98184018      NESTED LOOPS (cr=270067 pr=9028 pw=0 time=294901120 us)
12128           TABLE ACCESS BY INDEX ROWID WORK_IN_PROCESS (cr=9842 pr=8788 pw=0 time=20479883 us)
15241      INDEX RANGE SCAN WORK_IN_PROCESS_IX2 (cr=49 pr=48 pw=0 time=54577 us)(object id 65980)
98171889      INDEX RANGE SCAN PF2_PROD_ORDER_CARRIER_IX3 (cr=260225 pr=240 pw=0 time=808956 us)(object id 65990)
1736           TABLE ACCESS FULL PF2_PHYSICAL_CARRIER (cr=15 pr=0 pw=0 time=83 us)
Elapsed times include waiting on following events:
Event waited on      Times      Max. Wait      Total Waited
----------------------------------------      Waited      ----------           ------------
SQL*Net message to client          3      0.00           0.00
SQL*Net message from client      3      0.00           0.00
db file sequential read      14030      0.47           43.56
call      count      cpu      elapsed     disk     query     current     rows
Parse      1      0.00      0.00      0      0      0      0
Execute 1      0.00      0.00      0      0      0      0
Fetch      0      0.00      0.00      0      0      0      0
total      2      0.00      0.00      0      0      0      0
Misses in library cache during parse: 0
Parsing user id: SYS
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call      count      cpu      elapsed     disk      query      current      rows
Parse      2      0.00      0.00      0      0      0      0
Execute 2      0.00      0.00      0      0      0      0
Fetch      2      219.55      294.41      14030      13523455 0      14
total      6      219.55      294.41      14030      13523455 0 14
Misses in library cache during parse: 0
Elapsed times include waiting on following events:
Event waited on      Times      Max. Wait      Total Waited
----------------------------------------      Waited      ----------           ------------     
SQL*Net message to client      3      0.00           0.00
SQL*Net message from client      3      0.00           0.00
db file sequential read      14030      0.47           43.56
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call      count cpu      elapsed      disk      query      current      rows
Parse      0      0.00      0.00      0      0      0      0
Execute 0      0.00      0.00      0      0      0      0
Fetch      0      0.00      0.00      0      0      0      0
total      0      0.00      0.00      0      0      0      0
Misses in library cache during parse: 0
2 user SQL statements in session.
0 internal SQL statements in session.
2 SQL statements in session.
Trace file: ././ppf2_ora_5439924.trc
Trace file compatibility: 10.01.00
Sort options: default
1      session in tracefile.
2      user SQL statements in trace file.
0      internal SQL statements in trace file.
2      SQL statements in trace file.
2      unique SQL statements in trace file.
14137      lines in trace file.
294      elapsed seconds in trace file.
INFORMATION 5. EXPLAIN PLAN OUTPUT OF DBMS_XPLAN.DISPLAY
SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID 1z1cccq5kxt11, child number 0
SELECT /*+ gather_plan_statistics */ DISTINCT C.MAN_WIP_T_IN_TS, C.RCP_NO, C.WRK_CTR_ID, C.WTR_FREE_TST_FLG,
A.COMPANY_ID, A.PROD_ORDER, A.PART_NO, A.CARRIER_QTY, B.PHY_CARID, C.WIP_SEQ, A.RCP_NO "CARRIER_RCP"
FROM PF2_PROD_ORDER_CARRIER A, PF2_PHYSICAL_CARRIER B, WORK_IN_PROCESS C
WHERE C.UNIT_TYPE_CD = RTRIM('TL7') AND C.UNIT_NM = RTRIM('T41') AND C.WIP_TYPE_CD ='HANDHELD'
AND C.PHY_CARRIER_SEQ = A.PHY_CARRIER_SEQ AND A.PHY_CARRIER_SEQ = B.PHY_CARRIER_SEQ
AND ((A.CARRIER_LD_TS <=C.MAN_WIP_T_IN_TS AND A.CARRIER_UNLD_TS >= C.MAN_WIP_T_IN_TS) OR
( A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS AND A.CARRIER_UNLD_TS IS NULL)) AND ((A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12
08:03:00', 'YYYY-MM-DD HH24:MI:SS') AND A.CARRIER_UNLD_TS<= TO
Plan hash value: 850402268
| Id | Operation                     | Name                    | Starts      |E-Rows      | A-Rows      |A-Time           | Buffers      | Reads      |OMem      |1Mem      | Used-Mem      |
| 1 | SORT UNIQUE                     |                | 1      | 11      | 14      |00:05:41.48      | 13M     | 6571      | 2048      | 2048      | 2048 (0)          |
|* 2 | HASH JOIN                     |                | 1      | 11      | 14      |00:05:41.48      | 13M     | 6571      | 807K     | 807K     | 614K (0)          |
|* 3 | TABLE ACCESS BY INDEX ROWID           | PF2_PROD_ORDER_CARRIER      | 1      | 5      | 14      |00:05:39.89      | 13M     | 6571      |      |      |           |
| 4 | NESTED LOOPS                |                | 1      | 11      | 98M     |00:04:55.08      | 270K     | 6569      |      |      |           |
|* 5 | TABLE ACCESS BY INDEX ROWID          | WORK_IN_PROCESS           | 1      | 2      | 12130      |00:00:13.15      | 9845      | 6569      |      |      |           |
|* 6 | INDEX RANGE SCAN                | WORK_IN_PROCESS_IX2           | 1      | 56      | 15244      |00:00:00.06      | 49      | 45      |      |      |           |
|* 7 | INDEX RANGE SCAN                | PF2_PROD_ORDER_CARRIER_IX3      | 12130      | 2361      | 98M     |00:00:00.92      | 260K     | 0      |      |      |           |
| 8 | TABLE ACCESS FULL                | PF2_PHYSICAL_CARRIER           | 1      | 1736      | 1736      |00:00:00.01      | 15      | 0      |      |      |           |
Predicate Information (identified by operation id):
2 - access("A"."PHY_CARRIER_SEQ"="B"."PHY_CARRIER_SEQ")
3 - filter(((("A"."CARRIER_UNLD_TS" IS NULL AND "A"."CARRIER_LD_TS"<=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss')) OR
("A"."CARRIER_UNLD_TS">=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss') AND "A"."CARRIER_LD_TS"<=TO_DATE(' 2012-01-12 08:03:00',
'syyyy-mm-dd hh24:mi:ss')) OR ("A"."CARRIER_UNLD_TS">=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss') AND
"A"."CARRIER_UNLD_TS"<=TO_DATE(' 2012-01-12 10:03:00', 'syyyy-mm-dd hh24:mi:ss')) OR "A"."CARRIER_LD_TS"=TO_DATE(' 2012-01-12 08:03:00',
'syyyy-mm-dd hh24:mi:ss')) AND (("A"."CARRIER_LD_TS"<="C"."MAN_WIP_T_IN_TS" AND "A"."CARRIER_UNLD_TS">="C"."MAN_WIP_T_IN_TS") OR
("A"."CARRIER_UNLD_TS" IS NULL AND "A"."CARRIER_LD_TS"<="C"."MAN_WIP_T_IN_TS"))))
5 - filter(("C"."WIP_TYPE_CD"='HANDHELD' AND "C"."PHY_CARRIER_SEQ" IS NOT NULL))
6 - access("C"."UNIT_TYPE_CD"='TL7' AND "C"."UNIT_NM"='T41')
7 - access("C"."PHY_CARRIER_SEQ"="A"."PHY_CARRIER_SEQ")
filter("A"."PHY_CARRIER_SEQ" IS NOT NULL)
41 rows selected.
Regards
Rahul

Rahul, post your question on the SQL and PL/SQL forum PL/SQL. This forum is for Oracle Berkeley DB not Oracle Database.
Thanks,
Andrei

Similar Messages

  • HOW TO: Post a SQL statement tuning request - template posting

    This post is not a question, but similar to Rob van Wijk's "When your query takes too long ..." post should help to improve the quality of the requests for SQL statement tuning here on OTN.
    On the OTN forum very often tuning requests about single SQL statements are posted, but the information provided is rather limited, and therefore it's not that simple to provide a meaningful advice. Instead of writing the same requests for additional information over and over again I thought I put together a post that describes how a "useful" post for such a request should look like and what information it should cover.
    I've also prepared very detailed step-by-step instructions how to obtain that information on my blog, which can be used to easily gather the required information. It also covers again the details how to post the information properly here, in particular how to use the \ tag to preserve formatting and get a fixed font output:
    http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
    So again: This post here describes how a "useful" post should look like and what information it ideally covers. The blog post explains in detail how to obtain that information.
    In the future, rather than requesting the same additional information and explaining how to obtain it, I'll simply refer to this HOW TO post and the corresponding blog post which describes in detail how to get that information.
    *Very important:*
    Use the \ tag to enclose any output that should have its formatting preserved as shown below.
    So if you want to use fixed font formatting that preserves the spaces etc., do the following:
    \   This preserves formatting
    \And it will look like this:
       This preserves formatting
       . . .Your post should cover the following information:
    1. The SQL and a short description of its purpose
    2. The version of your database with 4-digits (e.g. 10.2.0.4)
    3. Optimizer related parameters
    4. The TIMING and AUTOTRACE output
    5. The EXPLAIN PLAN output
    6. The TKPROF output snippet that corresponds to your statement
    7. If you're on 10g or later, the DBMS_XPLAN.DISPLAY_CURSOR output
    The above mentioned blog post describes in detail how to obtain that information.
    Your post should have a meaningful subject, e.g. "SQL statement tuning request", and the message body should look similar to the following:
    *-- Start of template body --*
    The following SQL statement has been identified to perform poorly. It currently takes up to 10 seconds to execute, but it's supposed to take a second at most.
    This is the statement:
    select
    from
             t_demo
    where
             type = 'VIEW'
    order by
             id;It should return data from a table in a specific order.
    The version of the database is 11.1.0.7.
    These are the parameters relevant to the optimizer:
    SQL>
    SQL> show parameter optimizer
    NAME                                 TYPE        VALUE
    optimizer_capture_sql_plan_baselines boolean     FALSE
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      11.1.0.7
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     100
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    optimizer_use_invisible_indexes      boolean     FALSE
    optimizer_use_pending_statistics     boolean     FALSE
    optimizer_use_sql_plan_baselines     boolean     TRUE
    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> show parameter cursor_sharing
    NAME                                 TYPE        VALUE
    cursor_sharing                       string      EXACT
    SQL>
    SQL> column sname format a20
    SQL> column pname format a20
    SQL> column pval2 format a20
    SQL>
    SQL> select
      2             sname
      3           , pname
      4           , pval1
      5           , pval2
      6  from
      7           sys.aux_stats$;
    SNAME                PNAME                     PVAL1 PVAL2
    SYSSTATS_INFO        STATUS                          COMPLETED
    SYSSTATS_INFO        DSTART                          01-30-2009 16:25
    SYSSTATS_INFO        DSTOP                           01-30-2009 16:25
    SYSSTATS_INFO        FLAGS                         0
    SYSSTATS_MAIN        CPUSPEEDNW              494,397
    SYSSTATS_MAIN        IOSEEKTIM                    10
    SYSSTATS_MAIN        IOTFRSPEED                 4096
    SYSSTATS_MAIN        SREADTIM
    SYSSTATS_MAIN        MREADTIM
    SYSSTATS_MAIN        CPUSPEED
    SYSSTATS_MAIN        MBRC
    SYSSTATS_MAIN        MAXTHR
    SYSSTATS_MAIN        SLAVETHR
    13 rows selected.Here is the output of EXPLAIN PLAN:
    SQL> explain plan for
      2  -- put your statement here
      3  select
      4             *
      5  from
      6             t_demo
      7  where
      8             type = 'VIEW'
      9  order by
    10             id;
    Explained.
    Elapsed: 00:00:00.01
    SQL>
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1390505571
    | Id  | Operation                   | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |          |     1 |    60 |     0   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T_DEMO   |     1 |    60 |     0   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | IDX_DEMO |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("TYPE"='VIEW')
    14 rows selected.Here is the output of SQL*Plus AUTOTRACE including the TIMING information:
    SQL> rem Set the ARRAYSIZE according to your application
    SQL> set autotrace traceonly arraysize 100
    SQL> select
      2             *
      3  from
      4             t_demo
      5  where
      6             type = 'VIEW'
      7  order by
      8             id;
    149938 rows selected.
    Elapsed: 00:00:02.21
    Execution Plan
    Plan hash value: 1390505571
    | Id  | Operation                   | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |          |     1 |    60 |     0   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T_DEMO   |     1 |    60 |     0   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | IDX_DEMO |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("TYPE"='VIEW')
    Statistics
              0  recursive calls
              0  db block gets
         149101  consistent gets
            800  physical reads
            196  redo size
        1077830  bytes sent via SQL*Net to client
          16905  bytes received via SQL*Net from client
           1501  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
         149938  rows processed
    SQL>
    SQL> disconnect
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing optionsThe TKPROF output for this statement looks like the following:
    TKPROF: Release 11.1.0.7.0 - Production on Mo Feb 23 10:23:08 2009
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    Trace file: orcl11_ora_3376_mytrace1.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    select
    from
             t_demo
    where
             type = 'VIEW'
    order by
             id
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch     1501      0.53       1.36        800     149101          0      149938
    total     1503      0.53       1.36        800     149101          0      149938
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 88 
    Rows     Row Source Operation
    149938  TABLE ACCESS BY INDEX ROWID T_DEMO (cr=149101 pr=800 pw=0 time=60042 us cost=0 size=60 card=1)
    149938   INDEX RANGE SCAN IDX_DEMO (cr=1881 pr=1 pw=0 time=0 us cost=0 size=0 card=1)(object id 74895)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                    1501        0.00          0.00
      db file sequential read                       800        0.05          0.80
      SQL*Net message from client                  1501        0.00          0.69
    ********************************************************************************The DBMS_XPLAN.DISPLAY_CURSOR output:
    SQL> -- put your statement here
    SQL> -- use the GATHER_PLAN_STATISTICS hint
    SQL> -- if you're not using STATISTICS_LEVEL = ALL
    SQL> select /*+ gather_plan_statistics */
      2  *
      3  from
      4  t_demo
      5  where
      6  type = 'VIEW'
      7  order by
      8  id;
    149938 rows selected.
    Elapsed: 00:00:02.21
    SQL>
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    PLAN_TABLE_OUTPUT
    SQL_ID  d4k5acu783vu8, child number 0
    select   /*+ gather_plan_statistics */          * from          t_demo
    where          type = 'VIEW' order by          id
    Plan hash value: 1390505571
    | Id  | Operation                   | Name     | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |
    |   0 | SELECT STATEMENT            |          |      1 |        |    149K|00:00:00.02 |     149K|   1183 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T_DEMO   |      1 |      1 |    149K|00:00:00.02 |     149K|   1183 |
    |*  2 |   INDEX RANGE SCAN          | IDX_DEMO |      1 |      1 |    149K|00:00:00.02 |    1880 |    383 |
    Predicate Information (identified by operation id):
       2 - access("TYPE"='VIEW')
    20 rows selected.I'm looking forward for suggestions how to improve the performance of this statement.
    *-- End of template body --*
    I'm sure that if you follow these instructions and obtain the information described, post them using a proper formatting (don't forget about the \ tag) you'll receive meaningful advice very soon.
    So, just to make sure you didn't miss this point:Use proper formatting!
    If you think I missed something important in this sample post let me know so that I can improve it.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Alex Nuijten wrote:
    ...you missed the proper formatting of the Autotrace section ;-)Alex,
    can't reproduce, does it still look unformatted? Or are you simply kidding? :-)
    Randolf
    PS: Just noticed that it actually sometimes doesn't show the proper formatting although the code tags are there. Changing to the \ tag helped in this case, but it seems to be odd.
    Edited by: Randolf Geist on Feb 23, 2009 11:28 AM
    Odd behaviour of forum software                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • SQL query tunning help

    Hi All,
    Could you please help me out the below SQL query tuning .
    Temp table is having 1 Million records
    Master table is having 60 Million records
    Query :
    SELECT B.*,U.ID, SD, LE, LAE
    FROM client.Temp B, client.Master
    U WHERE U.policyno = B.policyno
    AND B.UPFLAG = 0
    1.     Indexes are created on both email columns and Upflag for both tables.
    2.     Gathered DBMS Stats for MASTER Table
    Data is loading 100k/hour on production .

    When your query takes too long ...
    When your query takes too long ...
    HOW TO: Post a SQL statement tuning request - template posting
    HOW TO: Post a SQL statement tuning request - template posting

  • Need SQl Query tune

    Hi,
    This is a part of the procedure which is veryyy slow.. Need some suggestions for the below Query to improve performance. The explain plan and all will be correct in PRODUCTION DB.. In that system, I cant have the explain plan to be copied here. So need suggestions by the Query.
    Here PB,PBD and PBD1 are very huge tables..
    I am unable to paste the Query.. Please help me
    Thanks in advance..

    My car is broken, but I cannot produce it for repairs.
    Not sure of your expectations, but this isn't a way where volunteers have been provided any tiny piece of information to suggest any tuning advice.
    Please read the linked thread HOW TO: Post a SQL statement tuning request - template posting and post with mentioned information.

  • Pass ORG_ID as sql statement for parameter in request set

    We are in a multi-org environment. We are running the request PRC: Generate Draft Revenue for a Single Project as part of the request set. We want the request to automatically fill in the open pa period as the accrue through date. We have been using the SQL Statement below as the value for the accrue through date parameter.
    select end_date
    from pa_periods_all
    where status = 'O'
    and current_pa_period_flag = 'Y'
    Unfortunately that does not limit to a specific company. We a company that still have DEC-05 while another has an open period of JAN-06. This is causing the program fits. How do I pass the org_id to the request? [in beginners terms please]
    Thanks.
    Anne

    No idea what might be wroong without more info...
    Do some output. Test the ${params.id} variable passed to the second jsp. If that is correct, then error is in the select statement or display of jsp2. If it is correct the error comes from jsp1.
    If I have to guess, then I would say the error comes from JSP1, and the ${row.vac_id} should only be called once. In which case I would do something like this:
    //in jsp 1
                <c:forEach var="row" items="${results.rows}"  varStatus="counter"  >
                    <c:set var="vac_id" value="${row.vac_id}" scope="page"/>
                    <tr>
                        <td>${vac_id}</td>
                        <td><a href="vacancydetails.jsp?id=${vac_id}">More</a></td>But that is a guess only...
    Errr... Hold on to that as reference, but the it is entirely likely that I misspelled ${params.id} It may be ${param.id} I forget and away from my machine right now...

  • Trying to tune a SQL statement

    Please nee your help
    The sql statement below works perfectly and speed fast
    SELECT     0,
         :"gloSpaFolioID",
         SPA_ITEM_ID,
         :"Text Box 2",
         :"gloLogin",
         :"gloLogin"
    FROM     SPA_ITEM
    WHERE     UPC_CODE=:"Text Box 1"
    AND     LOCATION=:"gloLocation"
    But when append with the insert statement below, it slow down.
    Does anyone have an idea on how I could tune this statement?
    INSERT     INTO SPA_FOLIO_ITEM
         SPA_FOLIO_ITEM_ID,
         SPA_FOLIO_ID,
         SPA_ITEM_ID,
         QTY,
         CREATE_STAFF_ID,
         CHANGE_STAFF_ID
    SELECT     0,
         :"gloSpaFolioID",
         SPA_ITEM_ID,
         :"Text Box 2",
         :"gloLogin",
         :"gloLogin"
    FROM     SPA_ITEM
    WHERE     UPC_CODE=:"Text Box 1"
    AND     LOCATION=:"gloLocation"
    Thanks,

    The sql statement below works perfectly and speed fastIf the query starts returning rows quickly (like from sql plus) that doesn't mean the entire query is fast.
    If I have a 300 million row table and do: select * from huge_table, I will start seeing rows in an instant, but the full table scan takes far longer.

  • OBIEE direct DB request query sql statement cannot be edited after saved

    I have created direct DB request with long complex query, validated sql and Results appears ok. After I save this request and go back to edit the SQL statement, the original statement is only partially visible. Basically I can not do edit.
    Is there any Query related buffer or other configuration parms I have to set up?

    I'm not sure what the deal is between Flex/AIR and Visusal Studios, but i descided to publish my webservices and point the wsdl there instead of using the visual studio generated one.
    AND BEHOLD
    I't worked and worked much much faster than i was anticipating.
    So i'll just chalk it up to poor communication between FLEX and VS.  But if anybody knows a more complete answer I would still love to hear it.

  • How to tune the following sql statements which has two unions in oracle 10g

    It takes a long time to run the following sql statement in 10g. Each select brings back about 4 million rows and there will be about 12 million rows. When I run each select statements seprately in sqlplus I can see the data immedaitely but when I run it as whole with two unions in the select it just takes very very long time? I want to know how to make this run faster? Can we add hints? or is it because of any table space? Any help is appreciated.
    select
    D.EMPLID
    ,D.COMPANY
    ,'CY'
    ,D.CALENDAR_YEAR
    ,D.QTRCD
    ,D.ERNCD
    ,D.MONTHCD
    ,D.MONTHCD
    ,D.GRS_MTD
    ,D.GRS_QTD
    ,D.GRS_YTD
    ,D.HRS_MTD
    ,D.HRS_QTD
    ,D.HRS_YTD
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'
    union
    select
    D.EMPLID
    ,D.COMPANY
    ,'FY'
    ,(case when D.MONTHCD > '06' then D.CALENDAR_YEAR + 1 else D.CALENDAR_YEAR end)
    ,ltrim(to_char(to_number(D.QTRCD) + decode(sign(3-to_number(D.QTRCD)),1,2,-2),'9'))
    ,D.ERNCD
    ,ltrim(to_char(to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6),'09'))
    ,D.MONTHCD
    ,D.GRS_MTD
    ,D.GRS_QTD
    ,(select sum(F.GRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '07' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '07' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD) + decode(sign(7-to_number(F.MONTHCD)),1,6,-6)
    <= to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6))
    ,D.HRS_MTD
    ,D.HRS_QTD
    ,(select sum(F.HRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '07' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '07' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD) + decode(sign(7-to_number(F.MONTHCD)),1,6,-6)
    <= to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6))
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'
    union
    select
    D.EMPLID
    ,D.COMPANY
    ,'FF'
    ,(case when D.MONTHCD > '09' then D.CALENDAR_YEAR + 1 else D.CALENDAR_YEAR end)
    ,ltrim(to_char(to_number(D.QTRCD)+decode(sign(4-to_number(D.QTRCD)),1,1,-3),'9'))
    ,D.ERNCD
    ,ltrim(to_char(to_number(D.MONTHCD)+decode(sign(10-to_number(D.MONTHCD)),1,3,-9),'09'))
    ,D.MONTHCD
    ,D.GRS_MTD
    ,D.GRS_QTD
    ,(select sum(F.GRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '10' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '10' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD)+decode(sign(4-to_number(F.MONTHCD)),1,9,-3)
    <= to_number(D.MONTHCD)+decode(sign(4-to_number(D.MONTHCD)),1,9,-3))
    ,D.HRS_MTD
    ,D.HRS_QTD
    ,(select sum(F.HRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '10' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '10' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD)+decode(sign(4-to_number(F.MONTHCD)),1,9,-3)
    <= to_number(D.MONTHCD)+decode(sign(4-to_number(D.MONTHCD)),1,9,-3))
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'
    Edited by: user5846372 on Mar 11, 2009 8:55 AM

    Hi,
    What i observed is that your table name and where clause is same in all the thress SELECTs whereas columns having some manipulations that is not going to be unique. I guess you can easily replace UNION with UNION ALL.
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'Note: I am not aware of your data and business requirement. Please test the result before removing. It is just a suggetion
    Cheers,
    Avinash

  • Capture all SQL statements and archive to file in real time

    Want to Capture all SQL statements and archive to file in real time?
    Oracle Session Manager is the tool just you need.
    Get it at http://www.wangz.net
    This tools monitor how connected sessions use database instance resources in real time. You can obtain an overview of session activity sorted by a statistic of your choosing. For any given session, you can then drill down for more detail. You can further customize the information you display by specifying manual or automatic data refresh, the rate of automatic refresh.
    In addition to these useful monitoring capabilities, OSM allows you to send LAN pop-up message to users of Oracle sessions.
    Features:
    --Capture all SQL statement text and archive to files in real time
    --Pinpoints problematic database sessions and displays detailed performance and resource consumption data.
    --Dynamically list sessions holding locks and other sessions who are waiting for.
    --Support to kill several selected sessions
    --Send LAN pop-up message to users of Oracle sessions
    --Gives hit/miss ratio for library cache,dictionary cache and buffer cache periodically,helps to tune memory
    --Export necessary data into file
    --Modify the dynamic system parameters on the fly
    --Syntax highlight for SQL statements
    --An overview of your current connected instance informaiton,such as Version, SGA,License,etc
    --Find out object according to File Id and Block Id
    Gudu Software
    http://www.wangz.net

    AnkitV wrote:
    Hi All
    I have 3 statements and I am writing some thing to a file using UTL_FILE.PUT_LINE after each statement is over. Each statement takes mentioned time to complete.
    I am opening file in append mode.
    statement1 (takes 2 mins)
    UTL_FILE.PUT_LINE
    statement2 (takes 5 mins)
    UTL_FILE.PUT_LINE
    statement3 (takes 10 mins)
    UTL_FILE.PUT_LINE
    I noticed that I am able to see contents written by UTL_FILE.PUT_LINE only after statement3 is over, not IMMEDIATELY after statement1 and statement2 are done ?
    Can anybody tell me if this is correct behavior or am I missing something here ?Calling procedure must terminate before data is actually written to the file.
    It is expected & correct behavior.

  • How to use presentaion variable in the SQL statement

    Is there any special syntax to use a presentation variable in the SQL Statement?
    I am setting a presentation variable (Fscl_Qtr_Var)in the dashboard prompt.
    If i set the filter as ADD->VARIABLE->PRESENTATION, it shows the statement as 'Contract Request Fiscal Quarter is equal to / is in @{Fscl_Qtr_Var} '.
    And this works fine but when i convert this to SQL, it returns
    "Contract Request Date"."Contract Request Fiscal Quarter" = 'Fscl_Qtr_Var'
    And this does not work.It is not being set to the value in the prompt.
    I need to combine this condition with other conditions in the SQL Statement. Any help is appreciated. Thanks

    Try this: '@{Fscl_Qtr_Var}'

  • Adding a field to an sql statement in Oracle Reports error ORA-00933

    We have been requested to add a field that already exists in the table referred to by the sql statement in Oracle Reports Builder. The report was set up by a consultant about 3 yrs ago and we don't really have much skill in this area. What is happening when I try to modify the SQL statement, either adding a field or deleting a field to the SELECT statement, causes an error message preventing the statement from being saved. The only way out of the error message is to click Cancel. The error message is
    ORA-00933:SQL command not properly ended
    ORDER BY Program ==> NAME
    Even adding or deleting a space anywhere in the SQL statement causes the error (not adding any new fields). A coworker found that if we comment out the ORDER BY, the statement will accept the new field in the SELECT section, however then we lose the order by functionality. I would like to add one additional field before the FROM. Not sure if any additional data are needed. Thank you.
    SELECT p.person_uid PIDM_KEY, p.id_number ID,
                   p.full_name_lfmi name,            
                    p.BIRTH_DATE, p.GENDER Sex,
                    Decode(a.residency,'D',p.Primary_ethnicity,'F')  Ethn,
                    a.academic_period TERM,        
                    CASE WHEN :p_group_by = 'PROGRAM' THEN a.program
                                 ELSE ' '
                    END AS Program,
                    a.COLLEGE, a.degree, a.major, ' ' rule,
                    a.STUDENT_POPULATION,a.STUDENT_LEVEL,    a.application_status Status,  a.application_status_date app_sts_dte,
                    ad.decision_date1 Last_Dec_Date,
                    ad.decision1||' '||ad.decision2||' '|| ad.decision3||' '|| ad.decision4||' '|| ad.decision5 Decisions,
                    /*  Deposit Date uses the last term entered in :p_term parameter string */
                    (SELECT MAX(deposit_effective_date) FROM usf_as_deposit WHERE account_uid = a.person_uid &term_clause group by account_uid)   AS "DEPOSIT DATE",     
                    ph.phone as PHONE,
                    CASE WHEN PS.FIRST_CONTACT IN ('NET','PAP','COM','COP') THEN PS.First_Contact
                     ELSE CASE WHEN ps.latest_contact IN ('NET','PAP','COM','COP') THEN PS.Latest_Contact
                                ELSE '  '
                                END
                    END AS FIRST_CONTACT,
                    DECODE(:p_address,'Y',REPLACE(adr.street1||' '||adr.street2||' '||adr.street3||' '||adr.city||','||adr.state||' '||adr.nation||' '||adr.zip,'  ',' '),' ') as  address, adr.nation, adr.state,
                    goremal_email_address email, a.residency, a.application_date, p.primary_ethnicity, c.cohort
    FROM MST_ADMISSIONS_APPLICATION A,
               MST_PERSON p,mst_pre_student PS,  Admissions_Cohort c, usf_v_phone_pr_ma ph,
               MST_admissions_decision_slot AD, usf_v_email, usf_v_address_dr_lr_ma_pr adr
    WHERE a.PERSON_UID = p.person_uid
            AND a.curriculum_priority  = 1
            AND a.person_uid = ps.person_uid
           AND a.person_uid = ad.person_Uid(+)
           AND a.person_uid = goremal_pidm(+)
           AND a.person_uid = adr.pidm(+)
           AND a.person_uid = ph.pidm(+)
           AND ph.rnum(+) = 1
           AND a.person_uid = c.person_uid(+)
           AND a.academic_period = c.academic_period(+)
      &Where_Clause
           /*    TAKE OUT FOLLOWING LINE AFTER DATA IS CLEANED UP  */
            AND NOT(p.id_number = '00000000'   OR SUBSTR(p.id_number,1,1) = 'B'  OR UPPER(p.full_name_lfmi)  LIKE '%TESTING%')
           AND  a.application_status_date >= NVL(:p_as_of_date,sysdate-8000)
           AND a.academic_period = ad.academic_period(+)
            AND a.application_number = ad.application_number(+)
            AND a.degree <> 'ND'    /*   AND a.college <> 'LW'                         --  Does not need non-degree and law students    */
           &Cohort_Clause 
    ORDER BY Program  &ORDER_CLAUSE

    Hi Denis,
    I tried your suggestion. The good thing is that adding the comma allowed me to be able to add a.campus to the select statement, unfortunately, another error message happened.
    ORA-00936: missing expression SELECT p . person_uid PIDM_KEY ,
    p . id_number , p . full_name_lfmi name , p . BIRTH_DATE , p . GENDER Sex ,
    Decode ( a . residency , 'D' , p . Primary_Ethnicity , 'F' ) Ethn , a . academic_period TERM ,
    CASE WHEN : P_group_by = 'PROGRAM THEN a I started over and tried only putting in the comma and get the same message even though I didn't add campus. After that, removed the comma which led to the ORA-00933 error message. So once again, I had to close the file without saving, in order for the report to run at all.

  • How to use alternative sql statements in ejb 2.0

    hi
    i have written the alternative sql statement in persistence.xml like  "select max(modifieddate) from tmp_dlv_mgmt".
    i am getting the error
    java.rmi.RemoteException: com.sap.engine.services.ejb.exceptions.BaseRemoteException: Exception in method in.kgs.bean.Dlv_EntityHomeImpl0.findMaxModifiedByUserID(java.lang.String).
         at in.kgs.bean.Dlv_EntityHomeImpl0.findMaxModifiedByUserID(Dlv_EntityHomeImpl0.java:1477)
         at in.kgs.bean.Dlv_EntityHomeImpl0p4_Skel.dispatch(Dlv_EntityHomeImpl0p4_Skel.java:387)
         at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:320)
         at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:198)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:129)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    Caused by: com.sap.engine.services.ejb.exceptions.BaseEJBException: Exception in method Dlv_EntityBean0.FindMaxModifiedByUserID(java.lang.String).
         at in.kgs.bean.Dlv_EntityBean0PM.ejbFindMaxModifiedByUserID(Dlv_EntityBean0PM.java:900)
         at in.kgs.bean.Dlv_EntityHomeImpl0.findMaxModifiedByUserID(Dlv_EntityHomeImpl0.java:1449)
         ... 10 more
    Caused by: com.sap.sql.log.OpenSQLException: A column with name DLVNO is unknown.
         at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:85)
         at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:124)
         at com.sap.sql.jdbc.common.CommonResultSet.findColumn(CommonResultSet.java:643)
         at com.sap.sql.jdbc.common.CommonResultSet.getLong(CommonResultSet.java:382)
         at in.kgs.bean.Dlv_EntityBean0Persistent.extractPK(Dlv_EntityBean0Persistent.java:213)
         at in.kgs.bean.Dlv_EntityBean0Persistent.extractPrimaryKey(Dlv_EntityBean0Persistent.java:206)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.extractSinglePK(FindPKCollection.java:152)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.extractAndAddSinglePK(FindPKCollection.java:167)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.onlyLoadAllElementsFromRS(FindPKCollection.java:146)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.forceLoadingOfAllElementsFromRS(FindPKCollection.java:128)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.<init>(FindPKCollection.java:99)
         at in.kgs.bean.Dlv_EntityBean0PM.ejbFindMaxModifiedByUserID(Dlv_EntityBean0PM.java:896)
         ... 11 more
    ; nested exception is:
         javax.ejb.EJBException: com.sap.engine.services.ejb.exceptions.BaseEJBException: Exception in method Dlv_EntityBean0.FindMaxModifiedByUserID(java.lang.String).
         at in.kgs.bean.Dlv_EntityBean0PM.ejbFindMaxModifiedByUserID(Dlv_EntityBean0PM.java:900)
         at in.kgs.bean.Dlv_EntityHomeImpl0.findMaxModifiedByUserID(Dlv_EntityHomeImpl0.java:1449)
         at in.kgs.bean.Dlv_EntityHomeImpl0p4_Skel.dispatch(Dlv_EntityHomeImpl0p4_Skel.java:387)
         at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:320)
         at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:198)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:129)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    Caused by: com.sap.sql.log.OpenSQLException: A column with name DLVNO is unknown.
         at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:85)
         at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:124)
         at com.sap.sql.jdbc.common.CommonResultSet.findColumn(CommonResultSet.java:643)
         at com.sap.sql.jdbc.common.CommonResultSet.getLong(CommonResultSet.java:382)
         at in.kgs.bean.Dlv_EntityBean0Persistent.extractPK(Dlv_EntityBean0Persistent.java:213)
         at in.kgs.bean.Dlv_EntityBean0Persistent.extractPrimaryKey(Dlv_EntityBean0Persistent.java:206)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.extractSinglePK(FindPKCollection.java:152)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.extractAndAddSinglePK(FindPKCollection.java:167)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.onlyLoadAllElementsFromRS(FindPKCollection.java:146)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.forceLoadingOfAllElementsFromRS(FindPKCollection.java:128)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.<init>(FindPKCollection.java:99)
         at in.kgs.bean.Dlv_EntityBean0PM.ejbFindMaxModifiedByUserID(Dlv_EntityBean0PM.java:896)
         ... 11 more
    com.sap.sql.log.OpenSQLException: A column with name DLVNO is unknown.
         at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:85)
         at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:124)
         at com.sap.sql.jdbc.common.CommonResultSet.findColumn(CommonResultSet.java:643)
         at com.sap.sql.jdbc.common.CommonResultSet.getLong(CommonResultSet.java:382)
         at in.kgs.bean.Dlv_EntityBean0Persistent.extractPK(Dlv_EntityBean0Persistent.java:213)
         at in.kgs.bean.Dlv_EntityBean0Persistent.extractPrimaryKey(Dlv_EntityBean0Persistent.java:206)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.extractSinglePK(FindPKCollection.java:152)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.extractAndAddSinglePK(FindPKCollection.java:167)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.onlyLoadAllElementsFromRS(FindPKCollection.java:146)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.forceLoadingOfAllElementsFromRS(FindPKCollection.java:128)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.<init>(FindPKCollection.java:99)
         at in.kgs.bean.Dlv_EntityBean0PM.ejbFindMaxModifiedByUserID(Dlv_EntityBean0PM.java:896)
         at in.kgs.bean.Dlv_EntityHomeImpl0.findMaxModifiedByUserID(Dlv_EntityHomeImpl0.java:1449)
         at in.kgs.bean.Dlv_EntityHomeImpl0p4_Skel.dispatch(Dlv_EntityHomeImpl0p4_Skel.java:387)
         at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:320)
         at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:198)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:129)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
         at com.sap.engine.services.ejb.exceptions.BaseRemoteException.writeReplace(BaseRemoteException.java:276)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at java.io.ObjectStreamClass.invokeWriteReplace(ObjectStreamClass.java:896)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1011)
         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
         at com.sap.engine.services.rmi_p4.DispatchImpl.throwException(DispatchImpl.java:144)
         at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:322)
         at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:198)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:129)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    Caused by: javax.ejb.EJBException: com.sap.engine.services.ejb.exceptions.BaseEJBException: Exception in method Dlv_EntityBean0.FindMaxModifiedByUserID(java.lang.String).
         at in.kgs.bean.Dlv_EntityBean0PM.ejbFindMaxModifiedByUserID(Dlv_EntityBean0PM.java:900)
         at in.kgs.bean.Dlv_EntityHomeImpl0.findMaxModifiedByUserID(Dlv_EntityHomeImpl0.java:1449)
         at in.kgs.bean.Dlv_EntityHomeImpl0p4_Skel.dispatch(Dlv_EntityHomeImpl0p4_Skel.java:387)
         at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:320)
         at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:198)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:129)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    Caused by: com.sap.sql.log.OpenSQLException: A column with name DLVNO is unknown.
         at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:85)
         at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:124)
         at com.sap.sql.jdbc.common.CommonResultSet.findColumn(CommonResultSet.java:643)
         at com.sap.sql.jdbc.common.CommonResultSet.getLong(CommonResultSet.java:382)
         at in.kgs.bean.Dlv_EntityBean0Persistent.extractPK(Dlv_EntityBean0Persistent.java:213)
         at in.kgs.bean.Dlv_EntityBean0Persistent.extractPrimaryKey(Dlv_EntityBean0Persistent.java:206)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.extractSinglePK(FindPKCollection.java:152)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.extractAndAddSinglePK(FindPKCollection.java:167)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.onlyLoadAllElementsFromRS(FindPKCollection.java:146)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.forceLoadingOfAllElementsFromRS(FindPKCollection.java:128)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.<init>(FindPKCollection.java:99)
         at in.kgs.bean.Dlv_EntityBean0PM.ejbFindMaxModifiedByUserID(Dlv_EntityBean0PM.java:896)
         ... 11 more
    com.sap.sql.log.OpenSQLException: A column with name DLVNO is unknown.
         at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:85)
         at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:124)
         at com.sap.sql.jdbc.common.CommonResultSet.findColumn(CommonResultSet.java:643)
         at com.sap.sql.jdbc.common.CommonResultSet.getLong(CommonResultSet.java:382)
         at in.kgs.bean.Dlv_EntityBean0Persistent.extractPK(Dlv_EntityBean0Persistent.java:213)
         at in.kgs.bean.Dlv_EntityBean0Persistent.extractPrimaryKey(Dlv_EntityBean0Persistent.java:206)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.extractSinglePK(FindPKCollection.java:152)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.extractAndAddSinglePK(FindPKCollection.java:167)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.onlyLoadAllElementsFromRS(FindPKCollection.java:146)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.forceLoadingOfAllElementsFromRS(FindPKCollection.java:128)
         at com.sap.engine.services.ejb.entity.finder.FindPKCollection.<init>(FindPKCollection.java:99)
         at in.kgs.bean.Dlv_EntityBean0PM.ejbFindMaxModifiedByUserID(Dlv_EntityBean0PM.java:896)
         at in.kgs.bean.Dlv_EntityHomeImpl0.findMaxModifiedByUserID(Dlv_EntityHomeImpl0.java:1449)
         at in.kgs.bean.Dlv_EntityHomeImpl0p4_Skel.dispatch(Dlv_EntityHomeImpl0p4_Skel.java:387)
         at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:320)
         at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:198)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:129)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
         at com.sap.engine.services.ejb.exceptions.BaseEJBException.writeReplace(BaseEJBException.java:274)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at java.io.ObjectStreamClass.invokeWriteReplace(ObjectStreamClass.java:896)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1011)
         at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
         at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
         ... 11 more

    Hi Guruvulu,
    >
    Guruvulu Bojja wrote:
    > i have written the alternative sql statement in persistence.xml like  "select max(modifieddate) from tmp_dlv_mgmt".
    Could you please explain in detail - what you have done and what you want to achieve? You can also post the code of your persistence.xml for reference...
    Regards,
    Yordan

  • What's wrong with this SQL Statement?

    I hope somebody can help explain to me what is wrong wiht the
    following SQL statement in my Recordest. It does not return an
    error, but it will only filter records from the first variable
    listed, 'varFirstName%'. If I try to use any other variables on my
    search form,for example LastName, it returns all records. Why is it
    doing this?
    Here is the SQL statement:
    SELECT *
    FROM [Sysco Food Show Contacts]
    WHERE FirstName LIKE 'varFirstName%' AND LastName LIKE
    'varLastName%' AND OrganizationName LIKE 'varOrganizationName%' AND
    Address LIKE 'varAddress%' AND City LIKE 'varCity%' AND State LIKE
    'varState' AND PostalCode LIKE 'varPostalCode%'
    The variables are defined as below:
    Name Default Value Run-Time Value
    varFirstName % Request.Form("FirstName")
    varLastName % Request.Form("LastName")
    ...and such with all variables defined the same way.
    Any help would be much appreciated. I am pulling my hair out
    trying to make this Search Form work.
    Thanks, mparsons2000

    PLEASE IGONRE THIS QUESTION!
    There was nothing wrong with the statement. I had made
    another STUDIP mistake!

  • Odd results from SQL statement in JSP

    Hi.
    Getting very strange results from my SQL statement housed in my JSP.
    the last part of it is like so:
    "SELECT DISTINCT AID, ACTIVE, REQUESTOR_NAME, ..." +
    "REQUESTOR_EMAIL" +
    " FROM CHANGE_CONTROL_ADMIN a INNER JOIN CHANGE_CONTROL_USER b " +
    "ON a.CHANGE_CTRL_ID = b.CHANGE_CTRL_ID " +
      " WHERE UPPER(REQUESTOR_NAME) LIKE ? ";   I've set the following variables and statements:
    String reqName = request.getParameter("requestor_name");
    PreparedStatement prepstmt = connection.prepareStatement(preparedQuery);
    prepstmt.setString(1, "%" + reqName.trim().toUpperCase() + "%");
    ResultSet rslts = prepstmt.executeQuery();
    rslts.next();
    int aidn = rslts.getInt(1);          
    int actbox = rslts.getInt(2);     String reqname = rslts.getString(3).toUpperCase();
    String reqemails = rslts.getString(4);
    String bizct = rslts.getString(5);
    String dept = rslts.getString(6);
    String loc = rslts.getString(7);
    Date datereq = rslts.getDate(8);
    String busvp = rslts.getString(9);
    AND SO ONSo then I loop it, or try to with the following:
    <%
      try {
      while ((rslts).next()) { %>
      <tr class="style17">
        <td><%=reqname%></td><td><%=reqemails %></td><td><%=bizct %></td>td><%=dept %></td>
       <td><%=aidn %></td>
      </tr>
      <%
    rslts.close();
    selstmt.close();
    catch(Exception ex){
         ex.printStackTrace();
         log("Exception", ex);
    %>AND so on, setting 13 getXXX methods of the 16 cols in the SQL statement.
    Trouble is I'm getting wildly inconsistent results.
    For example, typing 'H' (w/o quotes) will spit out 20 duplicate records of a guy named Herman, with the rest of his corresponding info correct, just repeated for some reason.
    Typing in 'He' will bring back the record twice (2 rows of the complete result set being queried).
    However, typing in 'Her' returns nothing. I could type in 'ell' (last 3 letters of his name, Winchell) and it will again return two duplicate records, but typing in 'hell' would return nothing.
    Am I omitting something crucial from the while statement that's needed to accurately print out the results set without duplicating it and that will ensure returning it?
    There's also records in the DB that I know are there but aren't being returned. Different names (i.e. Jennifer, Jesse, Jeremy) won't be returned by typing in partial name strings like Je.
    Any insight would be largely appreciated.
    One sidenote: I can go to SQL Plus and accurately return a results set through the above query. Having said that, is it possible the JDBC driver has some kind of issue?
    Message was edited by:
    bpropes20
    Message was edited by:
    bpropes20

    Am I omitting something crucial from the while
    statement that's needed to accurately print out the
    results set without duplicating it and that will
    ensure returning it?Yes.
    In this code, nothing ever changes the value of reqname or any of the other variables.
      while ((rslts).next()) { %>
      <tr class="style17">
        <td><%=reqname%></td><td><%=reqemails %></td><td><%=bizct %></td>td><%=dept %></td>
       <td><%=aidn %></td>
      </tr>
      <%
    } You code needs to be like this:while (rslts.next()) {
      reqname = rslts.getString(3).toUpperCase();
      reqemails = rslts.getString(4);
      bizct = rslts.getString(5);
      dept = rslts.getString(6);
      loc = rslts.getString(7);
      datereq = rslts.getDate(8);
      busvp = rslts.getString(9);
    %>
      <tr class="style17">
        <td><%=reqname%></td><td><%=reqemails %></td><td><%=bizct %></td>td><%=dept %></td>
       <td><%=aidn %></td>
      </tr>
      <%
    There's also records in the DB that I know are there
    but aren't being returned. Different names (i.e.
    Jennifer, Jesse, Jeremy) won't be returned by typing
    in partial name strings like Je.Well, you're half-right, your loop won't display all the rows in the result set, because you call rslts.next(); once immediately after executing the query. That advance the result set to the first row; when the loop is entered, it starts displaying at the 2nd row (or later if there are more next() calls in the code you omitted).

  • ABAP Standards for a SQL statement

    Hi,
    I have a Native SQL statement in my ABAP user exit, pls. edit into a Open SQL,
    SELECT v1~tknum v1~tsnum
          INTO TABLE t_vtts
          FROM vtts AS v1
          FOR ALL ENTRIES IN t_shipment_del
          WHERE v1~tknum = t_shipment_del-tknum AND
                v1~vstel = rv_shppt          AND
                v1~kunnz = rv_shipto         AND
                v1~tsrfo = c_one             AND
                EXISTS ( SELECT addrnumber
                           FROM adrc CLIENT SPECIFIED
                           WHERE client     =  v1~mandt AND
                                 addrnumber =  v1~adrnz AND
                                 date_from  <= sy-datum AND
                                 date_to    >= sy-datum AND
                                 post_code1 =  rv_post_code1 ).
    Thank you

    Hhmm, for proper performance analysis we'd need some further details. Looking at your query I doubt that the following alternative helps, but you can give it a try, because subqueries are not always optimal:
      SELECT tknum tsnum INTO TABLE t_vtts
             FROM vtts INNER JOIN adrc ON
                  vtts~adrnz = adrc~addrnumber
             FOR ALL entries IN t_shipment_del
             WHERE tknum      = t_shipment_del-tknum AND
                   vstel      = rv_shppt             AND
                   kunnz      = rv_shipto            AND
                   tsrfo      = c_one                AND
                   post_code1 = rv_post_code1.
    You might need to add the condition on the address dates, but in any system I've checked so far, the ADRC-FROM date was always 00010101 and there was only one entry per address number (so if required, add it back).
    For performance tuning requests you should try to provide some background information, like:
    <ol>
    <li>How many entries are you your table T_SHIPMENT_DEL</li>
    <li>How many entries match your conditions on VTTS</li>
    <li>How many entries get dropped because of the condition on postal code</li>
    <li>Do a SQL trace and provide information about the execution plan chosen by the database</li>
    </ol>
    Also, you might want to consider moving your question to the forum.
    Cheers, harald

Maybe you are looking for