Performace tuning required in queries having where clause on = or =

Hi,
I ahve query which is taking hell lot of time because of having filter condition on with >=.
Say:
select * from <tableA> where <column1> >= sysdate;
By any chance can we do something to avoid full scan on above table?

Hi,
The oracle version is :
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE     10.2.0.4.0     Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
the query is :
with temp as(
select sysdate as valuedate from dual
union
select sysdate+1 as valuedate from dual
Union
select sysdate+2 as valuedate from dual
Union
select sysdate+3 as valuedate from dual
select valuedate from temp where valuedate >= sysdate
Taking the above scenerio, is it possible to build any index which can be used to improve the performance.
The above query is just a example. the original query is fetching data from huge table with filter condition >=
I want my index to be used there.

Similar Messages

  • Queries involving where clause with timestamp data type

    I need to use milliseconds in my tables and do queries where I compare the time in the table to a specific time. I changed the column to the TIMESTAMP data type (from DATE) to accommodate the milliseconds.
    I am accessing the data via a C++ program using ODBC to access the Oracle 10g XE database and a SQLBindParameter statement to set up the comparisons.
    Below is a table that looks like mine but simplified to just a few fields:
    . DATA_ID NOT NULL NUMBER(10)
    . START_TIME NOT NULL TIMESTAMP(6)
    . STOP_TIME NOT NULL TIMESTAMP(6)
    My query is:
    . string sql("select "\
    . "to_Char(rv.start_time, 'YYYYMMDD HH24:MI:SS.FF3'), "\
    . "to_Char(rv.stop_time, 'YYYYMMDD HH24:MI:SS.FF3'), "\
    . "rv.data_id "\
    . "from "\
    . "Reservation rv "\
    . "where "\
    . "rv.data_id = ? and "\
    . "rv.stop_time >= to_timestamp(?, 'YYYYMMDD HH24:MI:SS.FF3') and "\
    . "rv.start_time <= to_timestamp(?, 'YYYYMMDD HH24:MI:SS.FF3');");
    MY C++ code (minus the usual statement preparation material) is:
    . string startTime("20090826 15:42:02.000");
    . string stopTime("20110828 02:04:52.000");
    . SQLRETURN rc = SQL_SUCCESS;
    . SQLINTEGER sqlRsrcInstanceId = resource->getResourceInstanceId();
    . SQLLEN sqlRsrcInstanceIdLI = 0;
    . rc |= SQLBindParameter( stmtHandle, 1, SQL_PARAM_INPUT,
    . SQL_C_LONG, SQL_INTEGER, 0, 0,
    . &sqlRsrcInstanceId, 0, &sqlRsrcInstanceIdLI );
    . SQLCHAR sqlStartTime[24];
    . memset(sqlStartTime, 0, 24);
    . SQLLEN sqlStartTimeLI = SQL_NTS;
    . strncpy( (char*)sqlStartTime, startTime, 23);
    . rc |= SQLBindParameter( stmtHandle, 2, SQL_PARAM_INPUT,
    . SQL_C_CHAR, SQL_CHAR,
    . sizeof(sqlStartTime)-1, 0,
    . &sqlStartTime, sizeof(sqlStartTime)-1,
    . &sqlStartTimeLI);
    . SQLCHAR sqlStopTime[24];
    . memset(sqlStopTime, 0, 24);
    . SQLLEN sqlStopTimeLI = SQL_NTS;
    . strncpy( (char*)sqlStopTime, stopTime, 23);
    . rc |= SQLBindParameter( stmtHandle, 3, SQL_PARAM_INPUT,
    . SQL_C_CHAR, SQL_CHAR,
    . sizeof(sqlStopTime)-1, 0,
    . &sqlStopTime, sizeof(sqlStopTime)-1,
    . &sqlStopTimeLI);
    When the statement is executed, I get the following error:
    . ODBC Return Code: SQL Error.
    . Native Error Code/Message:
    . 932/[Oracle][ODBC][Ora]ORA-00932: inconsistent datatypes: expected - got -
    Any suggestions on what is wrong or a better way to perform the query?

    The only way to test a query is to get out of your environment and fire up SQL*Plus (command line).
    I can not read all of what you wrote but the error you are generating should show up there along with sufficient information to quickly fix it.
    Once you have working statement put it back into your environment.

  • Where clause question

    Hi Experts,
    We have a typical requirement for including the where clause dynamically. Here is the Scenario:
    We will be getting the Where Clause as a string parameter value from reporting framework. This needs to be appended in Crystal Reports with Select Clause.
    Here is an example. We will be getting the Where parameter value as
    clnt_id=1001 and acct_no=232 and cust='XYZ'
    This will be passed as a single string to CR which needs to act as Where Clause while the CR query hits database.
    Not sure how to implement this. Any suggestions will be of great help.
    Thanks
    Naresh

    As far as I'm aware, there are no other solutions, unless you want to parse the Where clause string in Crystal and code the possibilities.  This might be reasonable if there are only a couple of fields that possibly would be used in the where clause of any given report, but tedious and slow if there are hundreds.  Report performance will suffer in any case because the database will not be performing the Where clause, so more data will be passed back to Crystal which it will have to determine needs to be dropped.
    I don't know how many existing reports you're dealing with, but it might not be overly time consuming to change the reports to be based on an SQL Command.  After all, Crystal can give you the SQL that it intends to use when a report is defined based on tables and views...  IMHO, I see the benefit of using an SQL Command and have the database do the Where clause worth while in this case...
    HTH,
    Carl

  • Populate list by executing query with where clause

    Hi,
    I m populating my list from database table using following command.
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("learning", new HashMap());
    EntityManager em = emf.createEntityManager();
    String query = "select d from Dept d";
    List list = em.createQuery(query).getResultList();
    My list is getting populated with all of rows in my database table(dept). The problem is, I cant use where clause in my query string.
    String query = "select d from Dept d where d.dept_name='ANYNAME'";
    Moreover I cant select even indivisual columns by using following line
    String query = "select d.dept_code,d.dept_name from Dept d";
    It looks like that my query is getting all rows from table as Object.
    What to do to
    1. put some where clause
    2. get some particular colums instead of all columns
    3. apply some table joins in query
    plz help.

    Hi Alex,
    I misunderstood your question. You had mentioned "My list is getting populated with all of rows in my database table(dept). The problem is, I cant use where clause in my query string. "
    I thought you might not have permissions to modify the code in the class, and that's why I suggested that you could write new classes.
    1) write new classes,? means if I need just two columns from a table >(instead of all columns), do I need to write new class with just two >columns (getters and setters)?You can write a SQL statement anyway you want , there are no restrictions in JDBC , so if you need just 2 columns you can write a custom query for that.
    "select column1 as a, column2 as be from table_name where column3 = xyz" etc.
    2) Is not anyway to write SQL statement like
    select dept_code,dept_name from dept where dept_name='anything'The above SQL is correct, it should work.
    3) Stored procedures? can I get some example(code) to get an idea >how to implement complex queries with where clause and joinings >using stored procedures?Stored procedures are specific to the database you are using, Oracle has a particular syntax for store procdures.
    You can call stored procedures from JDBC also, search on Google for
    "Calling stored procedures from JDBC"
    4) I m using hibernate. can I get any example of using hibernate own >query?Tutorial on Hibernate Query Language:
    http://www.hibernate.org/hib_docs/v3/reference/en/html/queryhql.html

  • Performance Tuning on a table where WHERE clause is having only PK columns

    Hi folks!!
    Here is the gotcha!!!!
    I am having a table, named X, with primary key columns A and B.
    I running a packaged procedure in which there is a SELECT statment to get the record from the table X with WHERE condition on A and B columns. Now the problem is, the package is taking too much amount of time to get executed.
    Eventually, I used TKPROF utility on the trace file of that package execution.
    The trace file is showing that huge amount of time is spent on the SELECT statement of table X, as I said above.
    I am baffled why it is taking that much of time eventhough the columns in the WHERE clause are Primary Key columns only and that too there are in the sequential order as that of in primary key contituent sequence.
    I would be very grateful to you guyz... plz help me out of this one....
    Cheers...........PCZ

    Also can you use preformatting as requested above, so
    that we can read it?
    [pre]Your preformatted
    text[/pre]
    Hi William,
    Plz find the requested:
    SELECT *
    FROM
    STTMS_CUST_ACCOUNT WHERE BRANCH_CODE=:B2 AND CUST_AC_NO=:B1
    call     count       cpu    elapsed       disk      query    current        rows
    Parse      180      0.00       0.04          0          0          0           0
    Execute  56538      0.96       4.02          0          0         26           0
    Fetch    56512   5581.98   19547.83         12 1134505869          6       56512
    total   113230   5582.94   19551.89         12 1134505869         32       56512
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 42  (FLEXMIG)   (recursive depth: 1)
    Rows     Row Source Operation
        325  TABLE ACCESS BY INDEX ROWID STTM_CUST_ACCOUNT (cr=6427406 pr=1 pw=0 time=327599336 us)
    10064925   INDEX RANGE SCAN IND_DORMANCY (cr=46475 pr=0 pw=0 time=15740976 us)(object id 512984)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
        325   TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                  'STTM_CUST_ACCOUNT' (TABLE)
    10064925    INDEX   MODE: ANALYZED (RANGE SCAN) OF 'IND_DORMANCY' (INDEX)
    ********************************************************************************This is what I can do. I apologize if it still does not come out in proper format. This is the first time I am trying it. :)
    Cheers.......PCZ

  • How to Get the required List Item values by using Where Clause

    I have two tables named "TAX_RULES","BILL"
    1. " Tax_Rules" (Sub_Head_Code,Tax_ID,Tax_Percentage)
    { While "Sub_Head_Code" field is unique,
    Tax_ID describes that there are two kinds of Tax_IDs based on Tax_percentage which is 6% for some Sub_Head_Codes and 3.5% for the remainng Sub_Head_Codes. I have given Tax_ID 1 for 6% and Tax_ID 2 for Sub_Head_codes having 3.5%. }
    2. "BILL" (Bill_ID,Sub_Head_Code,Tax_ID,Bill_Amount)
    {While "Bill_ID" describes unique Bill Identification Number,
    Sub_Head_Code and Tax_ID are behaving like composite foreign key from Tax_Rules table}
    I have design form for both tables.
    In BILL form i am trying to get values of Tax_ID from Tax_Rules table at run-time by using WHEN-NEW-FORM-INSTANCE.
    For this whenever i select a Sub_Head_Code in Bill Form, all the Tax_IDs that i have recorded against each Sub_Head_Code which is either 1 or 2 against 6% and 3.5% respectively.
    But I want that whenever i select a "Sub_Head_Code", Only that Tax_ID which is associated with that Sub_Head_Code ahould come in the LIST ITEM.
    I have used WHERE clause but that is useless.
    Following is the Code that i have applied in the WHE-NEW-ITEM-INSTANCE Trigger at FORM LEVEL
    <CODE>
    DECLARE
         rg_n1 VARCHAR2(40) :='TAX_ID';
         rg_idn1 RecordGroup;
         gc_idn1 GroupColumn;
         errcode NUMBER;
    BEGIN
         CLEAR_LIST('BILL.TAX_ID');
         rg_idn1 := Find_Group(rg_n1);
    IF      Id_Null(rg_idn1) then
              rg_idn1 := Create_Group(rg_n1);
         gc_idn1 := Add_Group_Column(rg_idn1,'EXPLAIN',CHAR_COLUMN,60);     
              gc_idn1 := Add_Group_Column(rg_idn1,'TAX_ID',CHAR_COLUMN,3);
         END IF;
         errcode := Populate_Group_With_Query(rg_idn1,'select TAX_ID,TAX_ID from TAX_RULES');
         POPULATE_LIST('BILL.TAX_ID',RG_IDn1);
    END;
    </CODE>

    In the Tax Rules table, you state:
    "Sub_Head_Code" field is unique
    In the Bill table, you state:
    Sub_Head_Code and Tax_ID are behaving like composite foreign key from Tax_Rules table
    If the Sub_Head_Code is unique, then it's acting as a primary key, so Sub_Head_Code and Tax_ID in the Bill table are not behaving like a composite foreign key. The Sub_Head_Code is a foreign key, and the Tax_ID is irrelevant as far as keys are concerned.
    It is not clear what it is you want to do.
    If you want to display the Tax_IDs from the Bill table when you select a Sub_Head_Code from the Tax_Rules table, then change your query to:
    select TAX_ID, TAX_ID from BILL where Sub_Head_Code = :Tax_Rules.Sub_Head_Code
    If you want to display the Tax_IDs from the Tax_Rules table when you select a Sub_Head_Code from the Bill table, then change your query to:
    select TAX_ID, TAX_ID from TAX_RULES where Sub_Head_Code = :Bill.Sub_Head_Code
    If this is not what you want, then clarify what it is you want to do. Don't say:
    "I want that whenever i select a "Sub_Head_Code", Only that Tax_ID which is associated with that Sub_Head_Code"
    because it is not clear what tables you are referring to.

  • Query Tuning - using CASE statement in the WHERE clause - Duplicate Post

    Duplicate Post by mistake.
    Please check
    Query Tuning - using CASE statement in the WHERE clause
    Edited by: Chaitanya on Jun 9, 2011 2:45 AM
    Edited by: Chaitanya on Jun 9, 2011 2:46 AM

    Duplicate Post by mistake.
    Please check
    Query Tuning - using CASE statement in the WHERE clause
    Edited by: Chaitanya on Jun 9, 2011 2:45 AM
    Edited by: Chaitanya on Jun 9, 2011 2:46 AM

  • Where clause requiring user input

    I am a complete beginner at using SQL for Oracle.
    I am using a program called Toad for Oracle to try and help;
    See I am used to using the very simple Microsoft Query to build queries.
    I am using Excel to use these queries for a bunch of reports, graphs and charts.
    However, when I try and use Microsoft Query to build these queries I get a bunch of errors. Biggest one I can't get past is ORA-00972: identifier is too long.
    Anyway, so I start trying to build my query in Toad for Oracle.
    Is there a way like there is in Microsoft Query to write the Where Clause for user input.
    Example:
    MICROSOFT QUERY sample: Where A_COMPL_SUMMARY.ENTRY_DATE>= ?)
    And (A_COMPL_SUMMARY.ENTRY_DATE<= ?)
    And (A_COMPL_SUMMARY.ENTRY_DATE>=[Date1] And A_COMPL_SUMMARY.ENTRY_DATE<=[Date2])
    Something like that.
    Basically I'm wanting at this point of the query for excel to pop up a window for user to input what dates they want
    So is there a way to do this in SQL. I can't seem to write it the "correct way". It doesn't like the ?'s or the "[ ]"'s
    Please help!!!
    Thank you,

    When I try and copy/paste the SQL that I generated in Toad into Excel's query tool, 1st it tells me it can't be represented graphically. I select OK and then it gives me the "Microsoft Query has encountered a problem and needs to close. We are sorry for the inconvenience." my only options at this point are to Debug, Send Error Report, or Don't Send.
    Maybe I'm going about this the wrong way. But I need to run this Sql in Excel so I can get the graphs and charts from the data it executes.

  • Reg: Where clause in Hier queries -

    Hi Experts,
    I'm trying to understand the way Oracle calls the 'where' clause in case of 'connect by level' queries.
    Is it first creating all the rows using connect-by-level and then filtering the rows using where clause?
    (This is with reference to the post - Dates in a month )
    SQL> with range as
      2  (
      3     select date '2013-02-01' as start_date, date '2013-02-28' as end_date
      4     from dual
      5  )
      6  select
      7             level lvl,
      8             start_date+level-1 curr_date,
      9             TO_CHAR(start_date+level-1,'fmDAY') curr_day,
    10             LENGTH(TO_CHAR(start_date+level-1,'DAY')) len_curr_day,
    11             LENGTH(TO_CHAR(start_date+level-1,'fmDAY')) fm_len_curr_day
    12     from range
    13     where TO_CHAR(start_date+level-1,'fmDAY') = 'TUESDAY'
    14     connect by level <= (end_date-start_date)+1
    15     --where TO_CHAR(start_date+level-1,'fmDAY') = 'TUESDAY'
    16  ;
    LVL CURR_DATE            CURR_DAY            LEN_CURR_DAY FM_LEN_CURR_DAY
       5 05-FEB-2013          TUESDAY                        9               7
      12 12-FEB-2013          TUESDAY                        9               7
      19 19-FEB-2013          TUESDAY                        9               7
      26 26-FEB-2013          TUESDAY                        9               7Please help me understand this.
    - Ranit

    Just if you take an execution plan it will tell you that the connect by is done without the filter and then the filter is applied.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                         
    Plan hash value: 2892478533                                                                                                                                                                                                                                                                                 
    | Id  | Operation                     | Name | Rows  | Cost (%CPU)| Time     |                                                                                                                                                                                                                              
    |   0 | SELECT STATEMENT              |      |     1 |     2   (0)| 00:00:01 |                                                                                                                                                                                                                              
    |*  1 |  FILTER                       |      |       |            |          |                                                                                                                                                                                                                              
    |*  2 |   CONNECT BY WITHOUT FILTERING|      |       |            |          |                                                                                                                                                                                                                              
    |   3 |    FAST DUAL                  |      |     1 |     2   (0)| 00:00:01 |                                                                                                                                                                                                                              
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       1 - filter(TO_CHAR(TO_DATE(' 2013-02-01 00:00:00', 'syyyy-mm-dd                                                                                                                                                                                                                                          
                  hh24:mi:ss')+LEVEL-1,'fmDAY')='TUESDAY')                                                                                                                                                                                                                                                      
       2 - filter(LEVEL<=28)                                                                                                                                                                                                                                                                                    
    17 rows selected

  • Query Tuning - using CASE statement in the WHERE clause

    Hi All,
    My query has been modified to use a CASE statement in the WHERE clause to consider data from certain columns based on a parameter value. This modified query is doing a full table scan and running endlessly. Please suggest what may be done to improve its performance:
    Query:
    SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
    os.acctnum,
    os.avieworigin_refid,
    COUNT(1) cnt_articleview,
    SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
    FROM TABLE1 os
    WHERE os.acctnum IS NOT NULL
    AND os.avieworigin_refid IS NOT NULL
    AND os.requestdatetime IS NOT NULL
    AND UPPER(os.success_ind) = 'S'
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND get_date_timestamp(os.requestdatetime)  BETWEEN
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' AND os.entry_createddate  BETWEEN
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    END = 1
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND os.entry_CreatedDate BETWEEN
    TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' THEN 1
    END = 1
    GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Table Description:
    (Number of rows : approx > 600,000,000)
    Name                           Null     Type      
    ARTICLEID                      NOT NULL NUMBER(20)
    USERKEY                                 NUMBER(10)
    AVIEWORIGIN_REFID                       VARCHAR2(10)
    SUCCESS_IND                             VARCHAR2(2)
    ENTRY_CREATEDDATE                       DATE      
    CREATED_BY                              VARCHAR2(10)
    FILENUMBER                              NUMBER(10)
    LINENUMBER                              NUMBER(10)
    ACCTNUM                                 VARCHAR2(10)
    AUTOCOMPLETEDTERM                       NUMBER(2) 
    REQUESTDATETIME                         VARCHAR2(19)Explain Plan
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 2224314832
    | Id  | Operation            | Name              | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT     |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   1 |  HASH GROUP BY       |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   2 |   PARTITION RANGE ALL|                   |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    |*  3 |    TABLE ACCESS FULL | TABLE1 |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE  WHEN ('FULL'='FULL' AND
                  "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN
                  'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE  WHEN ('FULL'='FULL'
                  AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE('
                  2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
    PLAN_TABLE_OUTPUT
                  2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND
                  "OS"."AVIEWORIGIN_REFID" IS NOT NULL)Edited by: Chaitanya on Jun 9, 2011 2:44 AM
    Edited by: Chaitanya on Jun 9, 2011 2:47 AM

    Hi Dom,
    Modified Query:
    SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
    os.acctnum,
    os.avieworigin_refid,
    COUNT(1) cnt_articleview,
    SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
    FROM TABLE1 os
    WHERE os.acctnum IS NOT NULL
    AND os.avieworigin_refid IS NOT NULL
    AND os.requestdatetime IS NOT NULL
    AND UPPER(os.success_ind) = 'S'
    AND (('FULL'  = 'FULL'
    AND  (get_date_timestamp(os.requestdatetime)  BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
                   AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    AND   os.entry_CreatedDate BETWEEN TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
                   AND TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    OR ('FULL'  = 'INCR'
    AND os.entry_createddate  BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
                   AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') ))
    GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Execute Plan:
    PLAN_TABLE_OUTPUT
    Plan hash value: 3615447714
    | Id  | Operation                 | Name              | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT          |                   | 25125 |  1374K|       |   407K  (1)| 01:21:36 |       |       |
    |   1 |  HASH GROUP BY            |                   | 25125 |  1374K|  3768K|   407K  (1)| 01:21:36 |       |       |
    |   2 |   PARTITION RANGE ITERATOR|                   | 25125 |  1374K|       |   407K  (1)| 01:21:32 |    29 |    31 |
    |*  3 |    TABLE ACCESS FULL      | TABLE1 | 25125 |  1374K|       |   407K  (1)| 01:21:32 |    29 |    31 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       3 - filter("OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  UPPER("OS"."SUCCESS_IND")='S' AND "OS"."REQUESTDATETIME" IS NOT NULL AND
                  "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "OS"."ACCTNUM" IS NOT NULL AND "OS"."AVIEWORIGIN_REFID" IS NOT NULL AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
                  2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))Edited by: Chaitanya on Jun 9, 2011 4:51 AM

  • Where clause problem with sub-queries in forms 6i

    where is the best place to put a sub query?? I have been using the set block property, however when running a sub query an alternative method must be used. what are some other options?? I have tried to have the query directly in the data block property palette but to no avail...
    There are 2 tables project and assignment
    maximum resources cannot be exceeded therefore a count of employees
    on the assignment table establishes that there are open spaces on the project.
    This code Here is my code for my where clause on the data block
    project.resources_maximum >
    (Select Count(assignment.employee_ID)
    From assignment
    Where assignment.project_ID = project.project_ID
    group by assignment.project_ID
    and project.end_date>sysdate;
    I was reading that the project table must be defined in the from clause
    to have the query go row by row, otherwise multiple rows are returned
    however I cannot define the project in the from,
    could this be why this doesn't work???
    original SQL that does work
    Need to migrate this to forms
    Select project.project_ID
    from project
    Where project.resources_maximum >
    (Select Count(assignment.employee_ID)
    From assignment
    Where assignment.project_ID = project.project_ID
    group by assignment.project_ID
    and project.end_date>sysdate;

    Looking at your query that works at the bottom, I do not see any reason that you would need to include the Assignment table in the From list. Just use the same where clause in the form:
      Where project.resources_maximum
        > (Select Count(assignment.employee_ID)
           From assignment
           Where assignment.project_ID = project.project_ID
           group by assignment.project_ID  )

  • Where clause on portal queries

    we'd like to apply a 'where clause' on the 'query' option of a portal form based on a table. Is there a generic procedure we can use in the pl/sql event handler block to do this? I've seen p_session.set_value used in the generated package with parameters '_block', '_WHERE_CLAUSE', and p_value - but not sure what syntax this is expecting and whether I can use it here.......
    any help appreciated.....

    Yes, it can be specified, exactly as it is set in the generated form package:
    p_session.set_value(
    p_block_name => "_block",
    p_attribute_name => '_WHERE_CLAUSE',
    p_value => <varchar2 string>,
    p_index => 1
    And syntax is the same as in the WHERE clause in a SELECT statement :
    .... WHERE empno=1234 and ename = 'BLAH' .... etc.....
    null

  • Generating HANA where clause for select options having CP as the operator

    Hi All
    I am trying to generate where clause in HANA sql from the select options range table .
    I tried using the function modules  RSDS_RANGE_TO_WHERE and  RH_DYNAMIC_WHERE_BUILD .
    They are working for most of the cases . But  , when the range table has entries like
    Fieldname   sign opt  low high
    VBELN        I/E    CP  *4*
    Both of them fail to generate the right result .
    Could you suggest any other function modules , which take care of all such cases like include single values , exclude single values , incluse and excluse ranges , patterns etc .
    Thanks and Best Regards
    Varsha

    Hi Karthik,
    this is the api, I have done,
    create or replace
    FUNCTION get_where_clause_for_emp_req (
       emp_id       IN   NUMBER,
       salary            IN   NUMBER,
       job         IN   VARCHAR2,
       dept IN NUMBER
       RETURN VARCHAR2
    IS
       l_where_clause   VARCHAR2 (2000);
    BEGIN
       IF (    (emp_id IS NULL)
           AND (salary IS NULL)
           AND (job IS NULL)
           AND (deptIS NULL)
       THEN
          RETURN NULL;
       ELSE
          l_where_clause := 'WHERE ';
       END IF;
       IF (emp_id IS NOT NULL)
       THEN
          l_where_clause :=
                        l_where_clause || ' emp_id =' || emp_id || '';
       END IF;
       IF ((emp_id IS NOT NULL) AND (salary IS NOT NULL))
       THEN
          l_where_clause :=
                          l_where_clause || ' AND salary= ' || salary;
       ELSIF (salary IS NOT NULL)
       THEN
          l_where_clause := l_where_clause || ' salary= ' || salary;
       END IF;
       IF (((salary IS NOT NULL) AND (dept IS NOT NULL)) OR ((emp_id IS NOT NULL) AND (salary IS NULL) AND (dept IS NOT NULL)))
       THEN
          l_where_clause := l_where_clause || ' AND dept= ' || dept;
       ELSIF (status_i IS NOT NULL)
       THEN
          l_where_clause := l_where_clause || ' dept= ' || dept;
       END IF;
    l_where_clause := l_where_clause || ' ;';
       RETURN l_where_clause;
    END;I have done for three parameters, i need to include two more input parameters for this function, so I see going forward my testing cases will increases,
    so am looking for the best solution
    Thanks
    Edited by: NSK2KSN on Jul 7, 2010 3:11 PM

  • Query tuning in WHERE clause

    Hi All,
    I have 2 tables.
    TABLE_A contains 10 miliion records.
    TABLE_B contains 100 Records.
    I am joining these 2 tables
    Here a.ID is in Left side
    SELECT A.*, B.*
    FROM TABLE_A a, TABLE_B b
    WHERE a.ID = b.ID;Here b.ID is in Left side
    SELECT A.*, B.*
    FROM TABLE_A a, TABLE_B b
    WHERE b.ID = a.ID;My question is which query will give better performance? I was thinking, that, if we put table column with less number of rows at Left side, then it will be faster than other.

    In current versions of Oracle, it doesn't matter in what order you sum-up your predicates in the WHERE-clause of a query: they will be optimized/executed in a same way.

  • Tuning Select Statement . field sequence and where clause

    Hi All
    Are there any general guidelines how to write select < field sequence >where clause < field sequence ? Is that shuld be in order of the field sequence in tables?
    And how to use this when we have a view or a inner - join . Is that separate from normal select statement that is using FOR ALL ENTRIES.
    Please let me know any general guidelines available on this,
    Amol

    Hello Amol,
    I have another hint:
    The statement FOR ALL ENTRIES will package the select statements for every five entries in the internal table. So in comparison to the following code sequence...
    LOOP AT itab.
       SELECT * FROM table WHERE key = itab-key.
    ENDLOOP
    the number of select statements is reduced to 20% with
    SELECT * FROM table INTO TABLE ...
         FOR ALL ENTRIES IN itab
         WHERE key = itab-key
    If I'm expecting a <i>huge</i>  amount of data a go a step further and create my own packages by building a range table with around 100-500 entries and execute a select there...
    LOOP AT itab.
       IF counter < 500.
          APPEND itab-key TO range-tab.   " just code example
       ENDIF.
       IF count >= 500.
          SELECT * FROM table APPENDING TABLE ...
             WHERE key IN range_tab
       ENDIF.
       " adjust and calculate counter
    ENDLOOP.
    * Don't forget last select statement after loop
    Best wishes,
    Florin

Maybe you are looking for

  • IE 11 security settings / Server 2012 domain joined server

    Can someone clarify how the Security settings are automatically managed on domain jointed computers in IE 11 / Server 2012 R2: There seem to be different settings depending on the IE Enhanced Security Settings. I particular if IE Enhanced Security Se

  • Clicking on Safari no longer gives option to open new windows

    Hi, Snow Leopard is fast for me and has given me back 11 Gigs of space so I'm delighted . However, in Leopard - if you wanted a new safari window while another was already opened, all you had to do was keep the safari logo clicked, and in the options

  • Email sending with attachment

    Hello, I have the following problem : I have an .CSV file in a specific Directory, an I want to attached that file in a email in order to send the file to a specific email address. The file dimension can be over 200 MB, and my question is if it's exi

  • HELP!! Error trying to install XP on X200.

    Hi, I just got my new LENOVO X200 and wanted to have a clean install of XP (I bought the computer with a XP downgrade), so I followed one of the clean install guides online (from the lenovo forum I think...) and after downloading all the drivers from

  • IPhoto resized pics?

    I'm sure this has been covered but... I import large photo files into iPhoto. When I go back and look at the photos after importing, the sixe has been reduced to 5 x 3.5 at 72dpi. Any ideas why this is happening? Can I get my full res photos back? Th