Same query in 9i & 11g returning different counts

Recently our DB was upgraded from 9i to 11g. We observed some weird results like same query returning more records in 11g than in 9i. I later found out that was because of Null values. I used below commands to achieve same results.
1)     ALTER session set optimizer_features_enable='9.2.0'; -
2)     SELECT /*+ optimizer_features_enable=('9.2.0' )*/ *
FROM TABLE_NAME
WHERE
ORDER BY COL1 DESC , COL2 ASC,COL3 ASC;
Do we have any documentation/material/link which explains this behavior? Any documentation on data type difference between 9i & 11g? Similar issue i observed in connect by prior.I had to select level in order to get the same records but in 9i without selecting level also we were getting desired result.
Thanks

Hi,
MSINHA wrote:
Recently our DB was upgraded from 9i to 11g. We observed some weird results like same query returning more records in 11g than in 9i. I later found out that was because of Null values. I used below commands to achieve same results.
1)     ALTER session set optimizer_features_enable='9.2.0'; -
2)     SELECT /*+ optimizer_features_enable=('9.2.0' )*/ *
FROM TABLE_NAME
WHERE
ORDER BY COL1 DESC , COL2 ASC,COL3 ASC;If you're getting any results other than an error message, then I don't believe you're running the query above. You need include some condition in the WHERE clause, or leave out the WHERE clause altogether.
Do you have row-level security in either database?
As Blushadow said, post a complete test script that people can use to re-create the problem and test their ideas. Include CREATE TABLE and INSERT statements for some sample data, and the complete query that you're using. If you are using dbms_rls row-level security, include the function and the code to enable it.
There's no version 9h or 9j, so it's kind of silly to say you're using 9i. The same goes for 10g. Why not give the actual version numbers, such as 9.2.0.6.0 and 10.2.0.3.0?
See the forum FAQ {message:id=9360002}

Similar Messages

  • CONNECT BY QUERY returns different count of rown in 10g resp. 11g databases

    Folks,
    I just spot a bellow issue in our databases.
    1.) 10g database:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.1.0.5.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> select * from global_name;
    SQL> SELECT ROWNUM
      2    FROM   dual
      3  CONNECT BY ROWNUM <= 2;
        ROWNUM
             1
             2
             3
    SQL> 2. 11g database
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select * from global_name;
    SQL> SELECT ROWNUM
      2    FROM   dual
      3    CONNECT BY ROWNUM <= 2;
        ROWNUM
             1
             2
    SQL> As you can see in 10g above query returns 3 records, in 11g only 2.
    Why it's like that? Can it be somehow set, to produce the same output?
    Many thanks,
    Tomas

    I get correct rows on both database version !
    Oracle Versions
    10g 10.2.0.1.0
    11g 11.1.0.6.0
    SQL> select rownum from dual connect by rownum <= 2;
        ROWNUM
             1
             2
    SQL> select * from v$version ;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    SQL> select rownum from dual connect by rownum <= 2;
        ROWNUM
             1
             2
    SQL> select * from v$version ;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE    11.1.0.6.0      Production
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production

  • Query returning different counts

    Dear all,
    10.2.0.4 on solaris ..
    Why is the 2 queries are displaying different rows
    SQL> select count(*) FROM MEDT_BL where rowid  in(SELECT rowid FROM MEDT_BL WHERE BILLDATE IN ('21-JUN-2011','21-MAY-2011','21-APR-2011') UNION ALL
    SELECT rowid FROM MEDT_BL WHERE NVL(BILLED,'N') = 'Y');  2
      COUNT(*)
      40131732
    SQL> select count(*) from (SELECT * FROM MEDT_BL WHERE BILLDATE IN
    ('21-JUN-2011','21-MAY-2011','21-APR-2011') UNION ALL SELECT * FROM MEDT_BL WHERE NVL(BILLED,'N') <> 'Y')  2
      COUNT(*)
       7426398Thanks
    Kai

    Your second query double counts any records that meet both conditions while you first query counts each row only once if it matches either condition. The sub-query in the IN clause is implicitly "distincted". Consider
    SQL > select * from t;
            ID DESCR
             1 One
             2 Two
             3 Three
             4 Four
             5 Five
             6 Six
             7 Seven
             8 Eight
             9 Nine
            10 Ten
            11 Eleven
            12 Twelve
            13 Thirteen
            14 Fourteen
            15 Fifteen
    SQL > select * from t
      2   where rowid in (select rowid from t
      3                   where mod(id, 2) = 0
      4                   union all
      5                   select rowid from t
      6                   where descr like '%teen');
            ID DESCR
             2 Two
             4 Four
             6 Six
             8 Eight
            10 Ten
            12 Twelve
            13 Thirteen
            14 Fourteen
            15 Fifteen
    SQL > select *
      2   from (select * from t
      3         where mod(id, 2) = 0
      4         union all
      5         select * from t
      6        where descr like '%teen');
            ID DESCR
             2 Two
             4 Four
             6 Six
             8 Eight
            10 Ten
            12 Twelve
            14 Fourteen
            13 Thirteen
            14 Fourteen
            15 FifteenIn the first version the row for 14, Fourteen only appeared once because the rowids were "distincted" while in the second query, it appears twice. Once from the top half of the union because 14 is even, and once from the bottom half of the union because Fourteen ends with teen.
    To make the second query equivalent to the first, you would need to use a union all, or combine both predicates into one query like:
    select count(*)
    from MEDT_BL
    where billdate in ('21-JUN-2011','21-MAY-2011','21-APR-2011') or
          nvl(billed,'N') = 'Y')As a side note, '21-JUN-2011','21-MAY-2011', and '21-APR-2011' are not dates, they are strings. Assuming that the billdate column is actually a date datatype, you need to use to_date to make the comparision correct:
    select count(*)
    from MEDT_BL
    where billdate in (TO_DATE('21-JUN-2011', 'dd-mon-yyyy'),
                       TO_DATE('21-MAY-2011', 'dd-mon-yyyy'),
                       TO_DATE('21-APR-2011', 'dd-mon-yyyy')) or
          nvl(billed,'N') = 'Y')John

  • How to call the same query more than once with different selection criteria

    Hi,
    Please do anybody know how to solve this issue? I need to call one query with the fixed structure more than once with different selection criteria. For example. I have following data
    Sales organization XX
                         Income 2008  Income 2009
    Customer A       10                 20
    Customer B        30                  0
    Sales organization YY
                         Income 2008  Income 2009
    Customer A        20                5
    Customer B        50                10
    Now, I need this. At the selection screen of query, user fill variable  charakteristic "Sales organization" with interval  XX - YY, than I need to generate two separate results per sales organization, one for Sales Organization XX and the second for SO YYwhich will be displayed each on separate page, where result for SO YY will be dispayed under result for SO YY. Are there some options how to do it for example in Report Designer or WAD or with programming? In Report Designer is possible to use one query more than once, but I dont know how to force each query in RD to display result only for one Sales Organization, which will be defined in selection screen.
    Thank you very much
    J.

    Hello,
    thanks to all for cooperation. Finally we solved this issue with the following way..
    User fill appropriate SO on the selection screen, which is defined as range. This will resulte, that selected SO are listed in report below each othe (standard behavior). Required solution we achieved with the Report Designer, we set page break under each Result row of RD. This caused, that report is divided into required part per SO, which are stated each on separate page.
    J.

  • Views - SELECT from VIEW and SELECT from the query inside view definition returning different results

    Hi,
    I am facing this weird issue. Any help would be appriciated.
    I have view with the following definition:
    CREATE VIEW [marketing].[OpenedMails]
    AS
    SELECT
    ID_EmailAddress, 
    ID_Date_Opened, 
    ID_Contact, 
    ID_MailSendJobs,
    COUNT(ID_OpenedMails) AS OpenCount,
    CASE
    WHEN ROW_NUMBER() OVER (PARTITION BY CAST(ID_EmailAddress AS VARCHAR(10)) + ' ' + CAST(ID_MailSendJobs AS VARCHAR(10)) ORDER BY ID_Date_Opened) = 1 THEN 1 
    ELSE 0 
    END
    AS UniqueOpenCount
    FROM            
    dbo.Fact_OpenedMails
    where ID_Contact = 382340
    GROUP BY ID_EmailAddress, ID_Date_Opened, ID_Contact, ID_MailSendJobs;
    order by ID_MailSendJobs 
    When I run the the select statement in the view definition I get combination of both 1 and 0 for the 'UniqueOpenCount' column.
    But when I run the select from the view itself using the following query:
    SELECT [ID_EmailAddress]
          ,[ID_Date_Opened]
          ,[ID_Contact]
          ,[ID_MailSendJobs]
          ,[OpenCount]
          ,[UniqueOpenCount]
      FROM [marketing].[OpenedMails]
    I get equal amount of rows but only 0 values for the 'UniqueOpenCount' column which seems to be very weird to me. Why is this happening ? Can anyone help regarding how to solve this ??
    Result from the select inside view definition:
    Result from the select query directly from the view:
    Thanks in advance.
    Vivek Kamath

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You failed. Temporal
    data should use ISO-8601 formats – you failed again. Code should be in Standard SQL AS much AS possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    Things like “ID_Date_Opened” are wrong. The affixes “id” and “date” are called attribute properties in ISO-11179 and data modeling. Since a date is a unit of measurement on a temporal scale, it cannot be an identifier by definition. My guess is this would be
    “open_date” if it were done right. And the only display format in ANSI/ISO Standard SQL is ISO-8601 (yyyy-mm-dd)
    An email address of -1?? Email addresses are VARCHAR(256), not numeric. There is no reason to cast them AS string!
    Your vague “mail_send_jobs” is plural, but columns hold scalars and cannot be plural by definition. The partition cause can hold a list of columns: 
    WHEN ROW_NUMBER() 
         OVER (PARTITION BY email_address, mail_send_job 
                   ORDER BY open_date)
         = 1 
    THEN 1 ELSE 0 END 
    This still makes no sense, but the syntax is better. You do not understand how ROW_NUMBER() works. 
    Would you like to try again with proper Netiquette? 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Oracle function and query return different results

    Hi, I am using oracle 10g database.
    Function is :
    create or replace FUNCTION FUNC_FAAL(myCode number,firstDate date
    *, secondDate date)*
    RETURN INTEGER as
    rtr integer;
    BEGIN
    select count() into rtr*
    from myschema.my_table tbl where tbl.myDateColumn between firstDate and
    secondDate and tbl.kkct is null and tbl.myNumberColumn  = myCode ;
    return (rtr);
    END FUNC_FAAL;
    This function returns 117177 as result.
    But if I run same query in the function seperately ;
    select count()*
    from myschema.my_table tbl
    where tbl.myDateColumn between firstDate and secondDate
    and tbl.kkct is null and tbl.myNumberColumn  = myCode ;
    I get different result 11344 (which is the right one).
    Table and function are in the same schema.
    What can be the problem ?
    Thanks.

    1. i think ur parameter name and Column names are same Firstdate and seconddate try to choose different name
    2. try using Trunc function around your dates
    where trunc(tbl.myDateColumn) between trunc(firstDate) and trunc(secondDate)then compare the result....sometimes time elements comes into play.
    Baig
    [My Oracle Blog|http://baigsorcl.blogspot.com/]

  • Same query at same time, but different execution plans from two schemas

    Hi!
    We just had some performance problems in our production system and I would like to ask for some advice from you.
    We had a select-query that was run from USER1 on SCHEMA1, and it ran a table scan on a huge table.
    Using session browser in TOAD I copied the Sql-statement, logged on SCHEMA1 and ran the same query. I got a different execution plan where I avoided the table scan.
    So my question is:
    How is it possible that the same query get different execution plans when running in two different schemas at the same time.
    Some more information:
    The user USER1 runs "alter session set current_schema=SCHEMA1;" when it logs on. Besides that it doesn't do anything so session parameter values are the same for USER1 and SCHEMA1.
    SCHEMA1 is the schema owning the tables.
    ALL_ROWS is used for both USER1 and SCHEMA1
    Our database:
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    PL/SQL Release 9.2.0.8.0 - Production
    CORE     9.2.0.8.0     Production
    TNS for Linux: Version 9.2.0.8.0 - Production
    NLSRTL Version 9.2.0.8.0 - Production
    Anybody has some suggestions to why I experience different execution plan for the same query, run at the same time, but from different users?

    Thanks for clarification of the schema structure.
    What happens if instead of setting the current session schema to SCHEMA1, if you simply add the schema name to alle tables, views and other objects inside your select statement?
    As in select * from schema1.dual;I know that this is not what you want eventually, but it might help to find any misleading objects.
    Furthermore it is not clear what you meant with: "avoided a table scan".
    Did you avoid a full table scan (FTS) or was the table completely removed from the execution plan?
    Can you post both plans?
    Edited by: Sven W. on Mar 30, 2010 5:27 PM

  • Ad Hoc Query - reporting on both PA and OM data in same query.

    Is it really not possible to report on both PA and OM in the same query?  Does the two different infosets prevent you from doing this? 
    As a workaround I can run two separate queries and just join the data using Excel.  However - I'm having some trouble using the OM infoset.  I have a list of job ID's and I'm trying to report on the job short text and the "duty code" which is a custom OM object.  Is there a way to add this custom object to the infoset? 
    Also, I'm finding it difficult to report on the relationships as "Object" is always listed as an output ONLY.  Is there a way to make it available as an input?

    If you are using logical database PNP, then you can try to add infotype and check the option 'Infotype of related objects' .
    This will allow you various HRP tables to add to your query by the relationship.
    If you check responsiblity you can use relationship B007 and selecting 1000 would give you the short text and long text of the ID.
    This is a very good option available for PNP database.
    Regards,
    SC

  • Problem with different resultset with same data and same query in Oracle 8.1.7 and 9i

    Hello,
    I have been using this query in oracle 8.1.7
    SELECT
    ID,
    AREA_NO
    FROM MANAGER_AREA MGR
    WHERE COMPANY_ID = :id AND
    (:value < (SELECT COUNT(ROWID)
    FROM MANAGER_WORK MW
    WHERE MW.AREA_ID = MGR.ID AND
    (MW.END_WORK IS NULL OR MW.END_WORK >= SYSDATE)))
    order by AREA_NO;
    In the above query I want to see rows from MANAGER_AREA table depending upon date criteria in the table MANAGER_WORK and also upon the parameter :value i.e if I pass a value as 0 I get to see records for which their is atleast 1 record in MANAGER_WORK with the date criteria and if I pass -1 then I get all the records because minimum value that count(*) would give is 0. The resultset was as expected in 8.1.7.
    A couple of days back I installed PERSONAL 9i to test for testing the basic functionality of our program with the same data. This query fails and irrespective whether I pass -1 or 0 it returns me same dataset which I would have got in case if I pass 0.
    I do not know whether this is a bug that has got introduced in 9i. Can anybody help me with this problem. It would be difficult for me to change the parameter send to this query as the Query is called from many different places.
    Thanks in advance
    Amol.

    I cannot use a Group by and a having statement over here. The problem with 'Group by' and 'having' clause is If I have to make a join between the two tables. When I use join then I get only rows that are linked to each other in the table.
    If I use outer join to solve that problem then I have to take in consideration the other date condition. My previous query use to virtually discard the corelated query result by using -1 as the value. This will not happen in the join query.
    Amol.

  • Issue returning a count of rows in a SELECT QUERY...

    I am working in Oracle 11.2g and I have a query where I want to return the count of DAILY records as well as WEEKLY records for specific marketers.
    Here is my query:
    Select     Mka_Mktr_No, 
              Case When Rat_Freq_Cd = 'D' Then Count(*) Else 0 End DailyCount,
              case when Rat_Freq_Cd = 'W' then count(*) Else 0 End WeeklyCount
            From     Marketer_Account, Acct
            Where     Mka_Exp_Dt >= '01-NOV-2012'
            And     Mka_Eff_Dt <= '30-NOV-2012'
            and     rat_acct_no = mka_acct_no
            And     Rat_Usage_Cd = 'P'
            and rat_freq_cd != 'M'
            Group By Mka_Mktr_No, Rat_Freq_Cd
            Order By Mka_Mktr_No;I would prefer to have the results show up on the SAME row, but instead I get the following results:
    MKA_MKTR_NO            DAILYCOUNT             WEEKLYCOUNT           
    10005                  68                     0                     
    10005                  0                      2                      Note how it shows each count on a seperate row. Is there a way to tweak the query to show the counts on the same row:
    MKA_MKTR_NO            DAILYCOUNT             WEEKLYCOUNT           
    10005                  68                     2       and not have two seperate rows?
    Many thanks,
    Sean

    Don't group by rat_freq_cd
    SQL> with test_data as
      2      (
      3      select 1 mka_mktr_no, 'W' rat_freq_cd from dual union all
      4      select 1 mka_mktr_no, 'W' rat_freq_cd from dual union all
      5      select 1 mka_mktr_no, 'D' rat_freq_cd from dual union all
      6      select 2 mka_mktr_no, 'D' rat_freq_cd from dual union all
      7      select 2 mka_mktr_no, 'W' rat_freq_cd from dual union all
      8      select 2 mka_mktr_no, 'W' rat_freq_cd from dual union all
      9      select 2 mka_mktr_no, 'D' rat_freq_cd from dual union all
    10      select 2 mka_mktr_no, 'D' rat_freq_cd from dual union all
    11      select 2 mka_mktr_no, 'D' rat_freq_cd from dual union all
    12      select 3 mka_mktr_no, 'D' rat_freq_cd from dual union all
    13      select 3 mka_mktr_no, 'D' rat_freq_cd from dual union all
    14      select 3 mka_mktr_no, 'W' rat_freq_cd from dual union all
    15      select 3 mka_mktr_no, 'D' rat_freq_cd from dual union all
    16      select 3 mka_mktr_no, 'D' rat_freq_cd from dual union all
    17      select 3 mka_mktr_no, 'W' rat_freq_cd from dual
    18      )
    19  select
    20      mka_mktr_no,
    21      count(case when rat_freq_cd = 'D' then rat_freq_cd end) dailycount,
    22      count(case when rat_freq_cd = 'W' then rat_freq_cd end) weeklycount
    23  from
    24      test_data
    25  group by mka_mktr_no;
    MKA_MKTR_NO DAILYCOUNT WEEKLYCOUNT
              1          1           2
              2          4           2
              3          4           2

  • Same query giving different results

    Hi
    I m surprised to see the behaviour of oracle. I have two different sessions for same scheema on same server. In both sessions same query returns different results. The query involves some calculations like sum and divisions on number field.
    I have imported this data from another server using export / import utility available with 9i server. Before export every thing was going fine. Is there some problem with this utility.
    I m using Developer 6i as the front end for my client server application. The behaviour of my application is very surprizing as once it shows the correct data and if I close the screen and reopen, it shows wrong data.
    I m really stucked with the abnormal behaviour. Please tell me the possiblities and corrective action for these conditions.
    Regards
    Asad.

    There is nothing uncommitted in both the sessions. But still different results are returned.
    I m sending u the exact query and result returned in both sessions.
    Session 1:
    SQL> rollback;
    Rollback complete.
    SQL> SELECT CC.CREDIT_HRS,GP.GRADE_PTS
    2 FROM GRADE G, COURSE_CODE CC, GRADE_POLICY GP
    3 WHERE G.COURSE_CDE=CC.COURSE_CDE
    4 AND G.SELECTION_ID=45 AND G.GRADE_TYP=GP.GRADE_TYP
    5 AND G.TERM_PROG_ID=17 AND GP.TERM_ID=14
    6 /
    CREDIT_HRS GRADE_PTS
    3 4
    4 3.33
    4 3.33
    3 4
    3 4
    3 4
    3 4
    7 rows selected.
    SQL>
    SESSION 2:
    SQL> rollback;
    Rollback complete.
    SQL> SELECT CC.CREDIT_HRS,GP.GRADE_PTS
    2 FROM GRADE G, COURSE_CODE CC, GRADE_POLICY GP
    3 WHERE G.COURSE_CDE=CC.COURSE_CDE
    4 AND G.SELECTION_ID=45 AND G.GRADE_TYP=GP.GRADE_TYP
    5 AND G.TERM_PROG_ID=17 AND GP.TERM_ID=14
    6 /
    CREDIT_HRS GRADE_PTS
    3 4
    4 3.33
    3 4
    3 4
    3 4
    3 4
    6 rows selected.
    SQL>
    U can see in session 1, seven rows are returned while in session 2 six rows are returned. I have issued a rollback before query to be sure that data in both sessions is same.

  • Execute the same query twice, get two different results

    I have a query that returns two different results:
    Oracle Version : 10.2.0.1.0
    I am running the following query on the Oracle server in SQL*Plus Worksheet.
    SELECT COUNT(*)
    FROM AEJOURNAL_S1
    WHERE CHAR_TIME BETWEEN TO_DATE('12-AUG-10 01:17:39 PM','DD-MON-YY HH:MI:SS AM') AND
    TO_DATE('13-AUG-10 14:17:34','DD-MON-YY HH24:MI:SS')
    AND DESC2 LIKE '%'
    AND DESC1 LIKE '%'
    AND DESC2 LIKE '%'
    AND ETYPE LIKE '%'
    AND MODULE LIKE '%'
    AND LEVELL = '11-WARNING'
    ORDER BY ORDD DESC;
    The very first time the query is run, it will return a count of 259. The next time the query is run, lets say, 10 seconds later, it will return a count of 260. The above query is exemplary of the kind of thing I'm trying to do. It seems like the more fields filtered against '%', the more random the count return becomes. Sometime you have to execute the query three or four times before it levels out to a consistent number.
    I'm using '%' as the default for various fields, because this was the easiest thing to do to support a data-driven Web interface. Maybe I have to 'dynamically' build the entire where clause, instead of just parameterizing the elements and having default '%'. Anyway, to eliminate the web interface for the purpose of troubleshooting the above query was run directly on the Oracle server.
    This query runs against a view. The view does a transpose of data from a table.
    Below is the view AEJOURNAL_S1
    SELECT
    CHAR_TIME,
    CHAR_INST,
    BATCH_ID,
    MIN(DECODE(CHAR_ID,6543,CHAR_VALUE)) AS ORDD,
    MIN(DECODE(CHAR_ID,6528,CHAR_VALUE)) AS AREAA,
    MIN(DECODE(CHAR_ID,6529,CHAR_VALUE)) AS ATT,
    COALESCE(MIN(DECODE(CHAR_ID,6534,CHAR_VALUE)),'N/A') AS CATAGORY,
    MIN(DECODE(CHAR_ID,6535,CHAR_VALUE)) AS DESC1,
    MIN(DECODE(CHAR_ID,6536,CHAR_VALUE)) AS DESC2,
    MIN(DECODE(CHAR_ID,6537,CHAR_VALUE)) AS ETYPE,
    MIN(DECODE(CHAR_ID,6538,CHAR_VALUE)) AS LEVELL,
    MIN(DECODE(CHAR_ID,6539,CHAR_VALUE)) AS MODULE,
    MIN(DECODE(CHAR_ID,6540,CHAR_VALUE)) AS MODULE_DESCRIPTION,
    MIN(DECODE(CHAR_ID,6541,CHAR_VALUE)) AS NODE,
    MIN(DECODE(CHAR_ID,6542,CHAR_VALUE)) AS STATE,
    MIN(DECODE(CHAR_ID,6533,CHAR_VALUE)) AS UNIT
    FROM CHAR_BATCH_DATA
    WHERE subbatch_id = 1774
    GROUP BY CHAR_TIME, CHAR_INST, BATCH_ID
    So... why does the query omit rows on the first execution? Is this some sort of optimizer issue. Do I need to rebuild indexes? I looked at the indexes, they are all valid.
    Thanks for looking,
    Dan

    user2188367 wrote:
    I have a query that returns two different results:
    Oracle Version : 10.2.0.1.0
    I am running the following query on the Oracle server in SQL*Plus Worksheet.
    SELECT COUNT(*)
    FROM AEJOURNAL_S1
    WHERE CHAR_TIME BETWEEN TO_DATE('12-AUG-10 01:17:39 PM','DD-MON-YY HH:MI:SS AM') AND
    TO_DATE('13-AUG-10 14:17:34','DD-MON-YY HH24:MI:SS')
    AND DESC2 LIKE '%'
    AND DESC1 LIKE '%'
    AND DESC2 LIKE '%'
    AND ETYPE LIKE '%'
    AND MODULE LIKE '%'
    AND LEVELL = '11-WARNING'
    ORDER BY ORDD DESC;
    The very first time the query is run, it will return a count of 259. The next time the query is run, lets say, 10 seconds later, it will return a count of 260. The above query is exemplary of the kind of thing I'm trying to do. It seems like the more fields filtered against '%', the more random the count return becomes. Sometime you have to execute the query three or four times before it levels out to a consistent number.
    I'm using '%' as the default for various fields, because this was the easiest thing to do to support a data-driven Web interface. Maybe I have to 'dynamically' build the entire where clause, instead of just parameterizing the elements and having default '%'. Anyway, to eliminate the web interface for the purpose of troubleshooting the above query was run directly on the Oracle server.
    This query runs against a view. The view does a transpose of data from a table.
    Below is the view AEJOURNAL_S1
    SELECT
    CHAR_TIME,
    CHAR_INST,
    BATCH_ID,
    MIN(DECODE(CHAR_ID,6543,CHAR_VALUE)) AS ORDD,
    MIN(DECODE(CHAR_ID,6528,CHAR_VALUE)) AS AREAA,
    MIN(DECODE(CHAR_ID,6529,CHAR_VALUE)) AS ATT,
    COALESCE(MIN(DECODE(CHAR_ID,6534,CHAR_VALUE)),'N/A') AS CATAGORY,
    MIN(DECODE(CHAR_ID,6535,CHAR_VALUE)) AS DESC1,
    MIN(DECODE(CHAR_ID,6536,CHAR_VALUE)) AS DESC2,
    MIN(DECODE(CHAR_ID,6537,CHAR_VALUE)) AS ETYPE,
    MIN(DECODE(CHAR_ID,6538,CHAR_VALUE)) AS LEVELL,
    MIN(DECODE(CHAR_ID,6539,CHAR_VALUE)) AS MODULE,
    MIN(DECODE(CHAR_ID,6540,CHAR_VALUE)) AS MODULE_DESCRIPTION,
    MIN(DECODE(CHAR_ID,6541,CHAR_VALUE)) AS NODE,
    MIN(DECODE(CHAR_ID,6542,CHAR_VALUE)) AS STATE,
    MIN(DECODE(CHAR_ID,6533,CHAR_VALUE)) AS UNIT
    FROM CHAR_BATCH_DATA
    WHERE subbatch_id = 1774
    GROUP BY CHAR_TIME, CHAR_INST, BATCH_ID
    So... why does the query omit rows on the first execution? Is this some sort of optimizer issue. Do I need to rebuild indexes? I looked at the indexes, they are all valid.
    Thanks for looking,
    DanIn fact you the first time you ran the query the data has been retrived from disk to memory , in the second time the data is already in memory so the respnse time should be faster ,but if you chagne any condition or column or letter case the optimizer will do the first step (data will be retrived from disk to memory )

  • SQL Server 2012 Physical vs. Hyper-V Same Query Different Results

    I have a database that is on physical hardware (16 CPU's, 32GB Ram).
    I have a copy of the database that was attached to a virtual Hyper-V server (16 CPU's, 32GB Ram).
    Both Servers and SQL Servers are identical OS=2008R2 Standard, SQL Server 2012R2 Standard same patch level SP1 CU8.
    Same query run on both servers return same data set, but the time is much different 26 Sec on Physical, 5 minutes on virtual.
    Statistics are identical on both databases, query execution plane is identical on both queries.
    Indices are identical on both databases.
    When I use set statistics IO, I get different results between the two servers.
    One table in particular (366k rows) on physical shows logical reads of 15400, on Hyper-V reports logical reads of 418,000,000 that is four hundred eighteen million for the same table.
    When the query is run on the physical it uses no CPU, when run on the Hyper-V it takes 100% of all 16 processors.
    I have experimented with Maxdop and it does exactly what it should by limiting processors but it doesn't fix the issue.

    A massive difference in logical reads usually hints at differences in the query plan.
    When you compare query plans, it is essential that you look at actual query plans.
    Please note that if your server / Hyper-V supports parallelism (which is almost always nowadays), then you are likely to have two query plans: a parallel and a serial query plan. Of course the actual query plan will make clear which one is used in which
    case.
    To say this again, this is by far the most likely reason for your problem.
    There are other (unlikely) reasons that could be the case here:
    runaway parallel threads or other bugs in the optimizer or engine. Make sure you have installed the latest service pack
    Maybe the slow server (Hyper-V) has extreme fragmentation in the relevant tables
    As mentioned by Erland, you have much much more information about the query and query plan than we do. You already know whether or not parallelism is used, how many threads are being used in it, if you have no, one or several Loop Joins in the query (my
    bet is on at least one, possibly more), etc. etc.
    With the limited information you can share (or choose to share), involving PSS is probably your best course of action.
    Gert-Jan

  • Same query takes different time to fetch result from Database

    Hi all,
    I am having a scenario in which a query is taking different time keeping other environmental variables constant.
    When that query runs for 1 user it takes just 2 minutes to fetch result and the DB connection becomes inactive after fetching the result.
    But if I run the same query after some time in similar environment it takes 25 minutes. sometimes 40 minutes to execute and give the result to the app server from the same database.
    I am not able to understand this behavior from DB. Can anybody try to explain this behavior?
    The details of the DB are,
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    OS Details:
    Windows 2008 server Enterprise Edition.
    I tried analyzing that query in oracle, it recommended there are lots of hard parsing in that query.
    Regards,

    user10915512 wrote:
    Hi all,
    I am having a scenario in which a query is taking different time keeping other environmental variables constant.
    When that query runs for 1 user it takes just 2 minutes to fetch result and the DB connection becomes inactive after fetching the result.
    But if I run the same query after some time in similar environmentBut not exactly the same environment. So what is different that it is only "similar"?
    it takes 25 minutes. sometimes 40 minutes to execute and give the result to the app server from the same database.
    I am not able to understand this behavior from DB. Can anybody try to explain this behavior?Run a statspack on the 'well behaved' query and on the 'not well behaved' query. Compare and contrast the results.
    >
    The details of the DB are,
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    OS Details:
    Windows 2008 server Enterprise Edition. To paraphrase Forest Gump, "My momma always said Windows was like a box of chocolates ...."
    >
    >
    I tried analyzing that query in oracle, it recommended there are lots of hard parsing in that query.
    Regards,

  • Huge difference in Execution time in same Query with different Parameter

    Hi Experts,
    We are facing an unique problem once we are executing the query in HANA SQL prompt. This Query was generated from BObj and executing in HANA system. Once this query running with following condition, it is taking almost 7-00 minute to execute and returning around 924 rows.
    << WHERE
    Table__1."LOGSYS"  IN  ('RKGCLNT102')
    AND
    Table__1."CompanyCode"  IN  ('7240','7245')
    AND
    Table__1."Plant"  IN ……………… >
    However if we run the same query with some different plant, It is taking only 2 second. Please find the Query here.
    << WHERE
    Table__1."LOGSYS"  IN  ('RKGCLNT102')
    AND
    Table__1."CompanyCode"  IN  ('7245','7600')
    AND
    Table__1."Plant"  IN ……………… >
    This is really an unexpected behavior and we are not able to get the actual reason why it is behaving like this.
    Could anyone please help to analyze this issue to fine the root cause.
    Thanks in Advance.
    Regards
    Satrajit.

    Hi there
    Unfortunately you provided too few information to analyze the issue.
    Maybe the underlying tables have very skew data and the first select has to read a larger share of the base tables.
    Maybe the columns had been unloaded before and the first query had to load them into memory first.
    Is the runtime always bad with the one and always good with the other set of parameters?
    Have you checked the PlanViz for both versions? How do these differ?
    - Lars

Maybe you are looking for

  • Creation of sales order

    While creating a sales order iam getting a error message which says "The appropriate pricing procedure could not be determined because no entry with keys 'GOZ1 G1 G1' 'A' '' exists in table 683V. Can u help please ?? Nikhil

  • Using  Data Pump when database is read-only

    Hello I used flashback and returned my database to the past time then I opened the database read only then I wanted use data pump(expdp) for exporting a schema but I encounter this error ORA-31626: job does not exist ORA-31633: unable to create maste

  • Calling_reports_unleashes_user_name_and_password

    hi all, i have a problem with calling report.... when i call a report, browser address bar unleashes my user_name and password. can i hide it any way??? i use the follwing code to call reports: DECLARE      report_url VARCHAR2(3000);      login_strin

  • Eclipse and JDeveloper

    Somebody knows what is the purpose of eclipse with jdevelper? Do I need to install eclipse? I cant find the version that the guide is talking about eclipse SDK 3.0 from the eclipse web site - anyone knows where i can get this?

  • Embed PDF in a Flex Application

    Hi All, I am trying to embed a PDF Document in a Flex Container, but I think it is impossible.. Some people talks about iframes, but it is not a nice workarround at all. I have read that in Adobe Air it is possible to do that. ¿Why in Adobe Air and n