Oracle 11g :SELECT query blocked..??

Hi Experts,
could you please explain why the below SQL query is blocked?
SELECT 1 FROM DUAL is blocking the SQL statement on GTTAPPUSR@gttccuatcriba04 ( SID=469 ) blocked SQL -> DELETE FROM GTTDB.PURCHASE_ENTRY_ID=:1
SELECT 1 FROM DUAL is blocking the SQL statement on GTTAPPUSR@gttccuatcriba04 ( SID=367 ) blocked SQL -> DELETE FROM GTTDB.PURCHASE_ENTRY_ID=:1
I am scratching my head without any solution when I had a look at the db today. Thanks in advance for your help.
Regards,
Boris
Edited by: user12075620 on Dec 4, 2012 8:58 AM

The SELECT statement is not blocking the UPDATE. As I said in the previous reply, the string that this query produces does not match the logic.
This query is (at least on the surface) correctly identifying that session 1 is blocking session 2. Session 1 holds some lock that session 2 is waiting on. So far, so good. Since session 2 is waiting on the lock, we can easily enough see what session 2 is running (the UPDATE statement). But since session 1 is not blocked, it is potentially off running a ton of other SQL statements (or no SQL statement at all). The query is looking to see what session 1 is running currently. It has no way of determining what session 1 ran at some point in the past to acquire the lock in the first place.
Going back to my KING example,
At noon, session 1 runs
UPDATE emp
   SET sal = sal * 2
WHERE ename = 'KING'Session 1 now has a lock on the KING row in the EMP table. But session 1 neither commits nor rolls back, it is still in a transaction. Session 1 might not have any more activity for a long time-- the user might go off to lunch, for example (obviously, applications should not be designed to allow users to maintain open transactions indefinitely, but not all applications are designed correctly). Or it might start running other queries. Let's say that session 1 now runs a query that is going to go for an hour
SELECT *
  FROM giant_view_with_lots_of_computationsNow, at 12:45, session 2 comes in and runs
UPDATE emp
   SET bonus = 100
WHERE ename = 'KING'Session 2 is blocked. Session 2 is running the UPDATE statement. Session 1 still holds the lock but it is running some completely unrelated SQL statement.
If we run the query you posted, the query will correctly report that session 1 is running the query against the GIANT_VIEW_WITH_LOTS_OF_COMPUTATIONS but incorrectly imply that this SELECT query is the source of the lock. It is not. It simply happens to be the query that the session that does hold the lock happens to be executing at the current moment (why the application seems to be running a lot of queries that select a constant from dual is a separate question).
Justin

Similar Messages

  • Oracle 11g/R2 Query Result Cache - Incremental Update

    Hi,
    In Oracle 11g/R2, I created replica of HR.Employees table & executed the following statement (+Although using SUM() function is non-logical in this case, but just testifying the result+)
    STEP - 1
    SELECT      /+ RESULT_CACHE */ employee_id, first_name, last_name, SUM(salary)*
    FROM           HR.Employees_copy
    WHERE      department_id = 20
    GROUP BY      employee_id, first_name, last_name;
    EMPLOYEE_ID      FIRST_NAME LAST_NAME     SUM(SALARY)
    202           Pat           Fay          6000
    201           Michael           Hartstein     13000
    Elapsed: 00:00:00.01
    Execution Plan
    Plan hash value: 3837552314
    | Id | Operation           | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT      | | 2 | 130 | 4 (25)| 00:00:01 |
    | 1 | RESULT CACHE      | 3acbj133x8qkq8f8m7zm0br3mu | | | | |
    | 2 | HASH GROUP BY      | | 2 | 130 | 4 (25)| 00:00:01 |
    |* 3 | TABLE ACCESS FULL     | EMPLOYEES_COPY | 2 | 130 | 3 (0)| 00:00:01 |
    --------------------------------------------------------------------------------------------------     Statistics
    0 recursive calls
    0 db block gets
    0 consistent gets
    0 physical reads
    0 redo size
    *690* bytes sent via SQL*Net to client
    416 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    2 rows processed
    STEP - 2
    INSERT INTO HR.employees_copy
    VALUES(200, 'Dummy', 'User','[email protected]',NULL, sysdate, 'MANAGER',5000, NULL,NULL,20);
    STEP - 3
    SELECT      /*+ RESULT_CACHE */ employee_id, first_name, last_name, SUM(salary)
    FROM           HR.Employees_copy
    WHERE      department_id = 20
    GROUP BY      employee_id, first_name, last_name;
    EMPLOYEE_ID      FIRST_NAME LAST_NAME SUM(SALARY)
    202      Pat      Fay      6000
    201      Michael      Hartstein      13000
    200      Dummy User      5000
    Elapsed: 00:00:00.03
    Execution Plan
    Plan hash value: 3837552314
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT |          | 3 | 195 | 4 (25)| 00:00:01 |
    | 1 | RESULT CACHE | 3acbj133x8qkq8f8m7zm0br3mu | | | | |
    | 2 | HASH GROUP BY | | 3 | 195 | 4 (25)| 00:00:01 |
    |* 3 | TABLE ACCESS FULL| EMPLOYEES_COPY | 3 | 195 | 3 (0)| 00:00:01 |
         Statistics
    0 recursive calls
    0 db block gets
    4 consistent gets
    0 physical reads
    0 redo size
    *714* bytes sent via SQL*Net to client
    416 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    3 rows processed
    In the execution plan of STEP-3, against ID-1 the operation RESULT CACHE is shown which shows the result has been retrieved directly from Result cache. Does this mean that Oracle Server has Incrementally Retrieved the resultset?
    Because, before the execution of STEP-2, the cache contained only 2 records. Then 1 record was inserted but after STEP-3, a total of 3 records was returned from cache. Does this mean that newly inserted row is retrieved from database and merged to the cached result of STEP-1?
    If Oracle server has incrementally retrieved and merged newly inserted record, what mechanism is being used by the Oracle to do so?
    Regards,
    Wasif
    Edited by: 965300 on Oct 15, 2012 12:25 AM

    965300 wrote:
    Hi,
    In Oracle 11g/R2, I created replica of HR.Employees table & executed the following statement (+Although using SUM() function is non-logical in this case, but just testifying the result+)
    STEP - 1
    SELECT      /+ RESULT_CACHE */ employee_id, first_name, last_name, SUM(salary)*
    FROM           HR.Employees_copy
    WHERE      department_id = 20
    GROUP BY      employee_id, first_name, last_name;
    EMPLOYEE_ID      FIRST_NAME LAST_NAME     SUM(SALARY)
    202           Pat           Fay          6000
    201           Michael           Hartstein     13000
    Elapsed: 00:00:00.01
    Execution Plan
    Plan hash value: 3837552314
    | Id | Operation           | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT      | | 2 | 130 | 4 (25)| 00:00:01 |
    | 1 | RESULT CACHE      | 3acbj133x8qkq8f8m7zm0br3mu | | | | |
    | 2 | HASH GROUP BY      | | 2 | 130 | 4 (25)| 00:00:01 |
    |* 3 | TABLE ACCESS FULL     | EMPLOYEES_COPY | 2 | 130 | 3 (0)| 00:00:01 |
    --------------------------------------------------------------------------------------------------     Statistics
    0 recursive calls
    0 db block gets
    0 consistent gets
    0 physical reads
    0 redo size
    *690* bytes sent via SQL*Net to client
    416 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    2 rows processed
    STEP - 2
    INSERT INTO HR.employees_copy
    VALUES(200, 'Dummy', 'User','[email protected]',NULL, sysdate, 'MANAGER',5000, NULL,NULL,20);
    STEP - 3
    SELECT      /*+ RESULT_CACHE */ employee_id, first_name, last_name, SUM(salary)
    FROM           HR.Employees_copy
    WHERE      department_id = 20
    GROUP BY      employee_id, first_name, last_name;
    EMPLOYEE_ID      FIRST_NAME LAST_NAME SUM(SALARY)
    202      Pat      Fay      6000
    201      Michael      Hartstein      13000
    200      Dummy User      5000
    Elapsed: 00:00:00.03
    Execution Plan
    Plan hash value: 3837552314
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT |          | 3 | 195 | 4 (25)| 00:00:01 |
    | 1 | RESULT CACHE | 3acbj133x8qkq8f8m7zm0br3mu | | | | |
    | 2 | HASH GROUP BY | | 3 | 195 | 4 (25)| 00:00:01 |
    |* 3 | TABLE ACCESS FULL| EMPLOYEES_COPY | 3 | 195 | 3 (0)| 00:00:01 |
         Statistics
    0 recursive calls
    0 db block gets
    4 consistent gets
    0 physical reads
    0 redo size
    *714* bytes sent via SQL*Net to client
    416 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    3 rows processed
    In the execution plan of STEP-3, against ID-1 the operation RESULT CACHE is shown which shows the result has been retrieved directly from Result cache. Does this mean that Oracle Server has Incrementally Retrieved the resultset?
    Because, before the execution of STEP-2, the cache contained only 2 records. Then 1 record was inserted but after STEP-3, a total of 3 records was returned from cache. Does this mean that newly inserted row is retrieved from database and merged to the cached result of STEP-1?
    If Oracle server has incrementally retrieved and merged newly inserted record, what mechanism is being used by the Oracle to do so?
    Regards,
    Wasif
    Edited by: 965300 on Oct 15, 2012 12:25 AMNo, the RESULT CACHE operation doesn't necessarily mean that the results are retrieved from there. It could be being
    written to there.
    Look at the number of consistent gets: it's zero in the first step (I assume you had already run this query before) and I would
    conclude that the data is being read from the result cache.
    In the third step there are 4 consistent gets. I would conclude that the data is being written to the result cache, a fourth step repeating
    the SQL should show zero consistent gets and that would be the results being read.

  • Oracle 11g unpivot query help

    Hello,
    I have a single row of data showing school term start and end dates in 2011/12. I need to convert this single row of data (containing 16 columns) into 5 rows comprised of just 4 columns (year, term, term_start, term_end).
    Is it possible to use just Oracle 11g's unpivot function_ to convert the following 16 columns of data:
    select * from
    (select 2012 as terms_year,
    1 as T1,'05-SEP-2011' as T1_SD, '21-OCT-2011' as T1_ED,
    2 as T2,'31-OCT-2011' as T2_SD, '16-DEC-2011' as T2_ED,
    3 as T3,'03-JAN-2012' as T3_SD, '10-FEB-2012' as T3_ED,
    4 as T4,'20-FEB-2012' as T4_SD, '30-APR-2012' as T4_ED,
    5 as T5,'16-APR-2012' as T5_SD, '01-JUN-2012' as T5_ED
    from dual) mytable
    aka
    TERMS_YEAR             T1                     T1_SD       T1_ED       T2                     T2_SD       T2_ED       T3                     T3_SD       T3_ED       T4                     T4_SD       T4_ED       T5                     T5_SD       T5_ED      
    2012                   1                      05-SEP-2011 21-OCT-2011 2                      31-OCT-2011 16-DEC-2011 3                      03-JAN-2012 10-FEB-2012 4                      20-FEB-2012 30-APR-2012 5                      16-APR-2012 01-JUN-2012 into the following 4 columns of data (year, term, term_start, term_end):
    select terms_year, term, t1_sd as term_start, t1_ed as term_end from
    (select 2012 as terms_year, 1 as term, '05-SEP-2011' as T1_SD, '21-OCT-2011' as T1_ED from dual union all
    select 2012 as terms_year, 2 as term, '31-OCT-2011' as T2_SD, '16-DEC-2011' as T2_ED from dual union all
    select 2012 as terms_year, 3 as term, '03-JAN-2012' as T3_SD, '10-FEB-2012' as T3_ED from dual union all
    select 2012 as terms_year, 4 as term, '20-FEB-2012' as T4_SD, '30-APR-2012' as T4_ED from dual union all
    select 2012 as terms_year, 5 as term, '16-APR-2012' as T5_SD, '01-JUN-2012' as T5_ED from dual) mytable
    aka
    TERMS_YEAR             TERM                   TERM_START  TERM_END   
    2012                   1                      05-SEP-2011 21-OCT-2011
    2012                   2                      31-OCT-2011 16-DEC-2011
    2012                   3                      03-JAN-2012 10-FEB-2012
    2012                   4                      20-FEB-2012 30-APR-2012
    2012                   5                      16-APR-2012 01-JUN-2012 Much obliged if anyone can teach me how - I can't get my head around the pivot/unpivot syntax! E.g.
    Select *
    From mytable
    UNPIVOT (
    unpivot_clause
    unpivot_for_clause
    unpivot_in_clause)
    Thanks,
    TP.

    Hi,
    Using the SELECT ... PIVOT feature:
    SELECT       terms_year
    ,       term
    ,       term_start
    ,       term_end
    FROM       mytable
    UNPIVOT       (  ( term
              , term_start
              , term_end
              )     FOR num_col
                 IN ( (t1, t1_sd, t1_ed)     AS 1
                 , (t2, t2_sd, t2_ed)     AS 2
                 , (t3, t3_sd, t3_ed)     AS 3
                 , (t4, t4_sd, t4_ed)     AS 4
                 , (t5, t5_sd, t5_ed)     AS 5
    ORDER BY  terms_year     -- If needed
    ,            num_col
    ;The basic syntax for UNPIVOTing to 1 column (plus a label column) is
    UNPIVOT (    outcol
         FOR  label     IN ( incol_1  AS label_val_1
                           , incol_2  AS label_val_2
                      , incol_n  AS label_val_n
         )where
    outcol       is the pivoted output column, containing values from the original table,
    label       is a label column, which will contain values hard-coded in the query,
    incol_1, incol_2, ..., incol_n       are the columns from the origianl table to be unpivoted
    label_val_1, label_val_2, ..., label_val_n       are the hard-coded values that will go in the label column.
    The syntax for pivoting to m columns (m > 1) is like that for pivoting 1 column, but
    instead of outcol, you give a comma-delimited list of m outcols, enclosed in parentheses, and
    instead of incol_1, incol_2, ... incol_n, you give a comma-delimited list of m columns, enclosed in parentheses.
    By the way, storing dates in VARCHAR2 columns is not a very good idea. Use DATE columns instead.
    Edited by: Frank Kulash on Jul 16, 2012 6:11 PM

  • Oracle SQL Select query takes long time than expected.

    Hi,
    I am facing a problem in SQL select query statement. There is a long time taken in select query from the Database.
    The query is as follows.
    select /*+rule */ f1.id,f1.fdn,p1.attr_name,p1.attr_value from fdnmappingtable f1,parametertable p1 where p1.id = f1.id and ((f1.object_type ='ne_sub_type.780' )) and ( (f1.id in(select id from fdnmappingtable where fdn like '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#%')))order by f1.id asc
    This query is taking more than 4 seconds to get the results in a system where the DB is running for more than 1 month.
    The same query is taking very few milliseconds (50-100ms) in a system where the DB is freshly installed and the data in the tables are same in both the systems.
    Kindly advice what is going wrong??
    Regards,
    Purushotham

    SQL> @/alcatel/omc1/data/query.sql
    2 ;
    9 rows selected.
    Execution Plan
    Plan hash value: 3745571015
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | SORT ORDER BY | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | TABLE ACCESS FULL | PARAMETERTABLE |
    |* 5 | TABLE ACCESS BY INDEX ROWID| FDNMAPPINGTABLE |
    |* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    |* 7 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
    |* 8 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    Predicate Information (identified by operation id):
    5 - filter("F1"."OBJECT_TYPE"='ne_sub_type.780')
    6 - access("P1"."ID"="F1"."ID")
    7 - filter("FDN" LIKE '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#
    8 - access("F1"."ID"="ID")
    Note
    - rule based optimizer used (consider using cbo)
    Statistics
    0 recursive calls
    0 db block gets
    0 consistent gets
    0 physical reads
    0 redo size
    0 bytes sent via SQL*Net to client
    0 bytes received via SQL*Net from client
    0 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    9 rows processed
    SQL>

  • Oracle 11g Certification Query

    Hi all,
    I have given my Oracle 11g exams for OCP certification. Now, i need to take one of the mandatory training to fulfill the requirements for certification. I am in Kuwait and when i select the country as Kuwait, the cheapest training course is of $1230. I am an indian, so when i select the country as India on the oracle site, the price reduces down to $540 for the same course. This is for the Live Virtual Class (LVC) rates. Can i book the LVC with India as country. Do I have to be present in India for the LVC training or only taking a course is compulsion.
    Kindly advice.

    Zuzar Sajjad Tutawala wrote:
    Hi all,
    I have given my Oracle 11g exams for OCP certification. Now, i need to take one of the mandatory training to fulfill the requirements for certification. I am in Kuwait and when i select the country as Kuwait, the cheapest training course is of $1230. I am an indian, so when i select the country as India on the oracle site, the price reduces down to $540 for the same course. This is for the Live Virtual Class (LVC) rates. Can i book the LVC with India as country. Do I have to be present in India for the LVC training or only taking a course is compulsion.
    Kindly advice.If you take LVC training my understanding, and it has been discussed in previous threads, if you need to be prsent in the country from which hte LVC is being presented. So if you want to take it in India you will need to travel back there.

  • Oracle 11g spatial query

    An Oracle 11g spatial database with 5 features in it. A doughnut, triangle, line, trapezium, pentagon.
    I want to query what coordinates of features exist in a rectange box including the last point that intersects the rectangle box.
    It really difficult to explain without pictures. Please look at this page.
    http://www.h2ss.co.uk/q/question.jsp
    Thanks, I appreciate it.

    Thanks for the replies.
    I acknowledge that what bkzar and jsharma say will work. But in real terms it is impractical for me to create a new table with the SDO_GEOMETRY's. I have over a thousand polygons, each with over 5000 points in my spatial table.
    Let me give you a background to what I am trying to achieve.
    I am trying to extract features from 11g and render them on Google Maps. However some of my polygons are huge and have over 5000 points, Google cannot render them effectively, however Google does give me the coordinates of the visible view, i.e the current rectangle view.
    My idea was that if you are zoomed right into Google Map and a particular feature intersects the rectangle view than I can query for a portion of the feature, including the first and last points that fall outside of the rectangle box.
    I need to be able to somehow filter the SDO_GEOMETRY that don't exist in the rectangle box.
    Thanks

  • Oracle 11g : UTL_FILE query

    Hi,
    I am having 2 server. One server has oracle database while on another one is application server where all the data files and application specific shell scripts are kept. We are connecting to database via the application server.
    I am using Oracle 11g:
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE 11.1.0.6.0 Production
    TNS for HPUX: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    I know that using UTL_FILE in PL/SQL procedure we can create file on the server (where oracle is installed).
    My requirement is generated some report which will involve writing to more than 2 files simultaneously. I know I can easily do this in PL/SQL procedure.
    But my issue is that due to space issue I cannot generate the files on database server and need to generate the same on the application one (client side)
    Queries:
    1] Is it also possible to create file on client machince instead of server in my case the application server via PL/SQL because I read that in Oracle 11g
    UTL_FILE provides file access both on the client side and on the server side.
    2] If yes any idea, how is this possible?
    3] If not, is there any way by which I can write to 2 or more file simultaneously on the client using oralce. I know SQL*Plus can spool file on client. But it is only one file at a time.
    Rgds,
    Amol

    Looking at the 11g documentation you are probably referring to:
    http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/u_file.htm#BABDEJDH
    where it says...
    >
    UTL_FILE provides file access both on the client side and on the server side. When run on the server, UTL_FILE provides access to all operating system files that are accessible from the server. On the client side, as in the case for Forms applications, UTL_FILE provides access to operating system files that are accessible from the client.
    >
    This is referring to client installed forms applications where it provides a local UTL_FILE functionality that accesses the local file system. It doesn't mean that UTL_FILE within PL/SQL that is running on the database server can access the client machine's file system as this would also be a breach of network security.

  • Oracle 11g -select on dictionary view hangs

    Hi Experts,
    I have issued the below query and it's hanging for a long time.
    SQL> select * from gv$session where rownum<=1;
    Could you please someone shed light on this issue?
    Regards,
    Richard
    Edited by: user12075620 on May 16, 2011 8:44 PM

    Duplicated and even triplicated post, probably Jive issue.
    To be continued over there :
    http://forums.oracle.com/forums/message.jspa?messageID=9594103#9594103
    Nicolas.

  • Dynamic %HINT ORACLE in select query

    Hi Experts,
    I am trying to implement given below code with dynamic % hint oracle
          SELECT vbeln posnr uepos
             FROM vbap INTO TABLE i_vbap
             FOR ALL ENTRIES IN i_vbak
              WHERE vbeln EQ i_vbak-vbeln
                %_hints oracle '&max_in_blocking_factor 500&&max_blocking_factor 500&'.
    I want value 500 dynamic,
    So far I have tried
    %hint oracle lv_oracle_string.
    %hint oracle (lv_oracle_string).
    WHERE (lv_oracle_string).     "where conditon with %_hints oracle '&max_in_blocking_factor 500&&max_blocking_factor 500&'.
    Any other ideas?
    Thanks in Advance

    Samuel,
    Thank you so much, whatever you mentioned, I have tried ealier, but it was giving me dump because of incorrect spacing in my string.
    Given below sloved my problem.
    CONCATENATE '''&max_in_blocking_factor ' lv_oracle '&&max_blocking_factor ' lv_oracle '&'''
              INTO lv_oracle_string RESPECTING BLANKS.
              SELECT vbeln posnr uepos
                 FROM vbap INTO TABLE i_vbap
                 FOR ALL ENTRIES IN i_vbak
                 WHERE vbeln EQ i_vbak-vbeln
                 %_hints oracle lv_oracle_string.
    Thanks you so much again. You Rock

  • Oracle 11g 2 installation blocked

    Hello, I'm installing the 11g release 2 Oracle version under a CentOS 6.3 virtual image, which is running on a CentOS 6.4 physical server.
    I've followed the steps about previous requirements showed in the "Quick installation guide", so I think that the environment was correct before I started the installation (hardware requirements, packages installed, groups and users created...)
    I tried installation twice, and it stopped at the same point both times:
    - Progress: 60%
    - Status: Copying files
         "Copying files for 'Oracle Notification Service 11.2.0.0.0'
    There is 34G free space in the home folder, and 12G free space in the /tmp, so I have no clue where the problem could be... Any help/idea??
    Thanks in advance

    Make the following checks:
    1. Permissions in whole directory structure $ORACLE_HOME.
    If necessary run the following command:
    find / oracle-type d | xargs chmod 775
    If it is a RAC check on both nodes.
    2. Check LIMITS in /etc/security/limits.conf
    3. Check if /tmp is full
    4. Make sure the sysctl.conf this parameterized correctly.

  • Oracle 11g with OPTIMIZER_MODE=RULE go faster!!

    I recently migrated Oracle 9.2.0.8 to Oracle 11g but the querys doesn't work as I hope.
    The same query takes 3:20 min aprox using optimizer_mode=ALL_ROWS and 0:20 using optimizer_mode=RULE or using RULE hint.
    The query in CBO makes a cartesian product between the indexes of the table.
    This is one query and the "autrotrace on" log on Oracle 11g:
    SELECT /*+ NO_INDEX (PK0004111303310) */MIN(BASE.ID_SCHED_TASK)+1 I
    FROM M4RJS_SCHED_TASKS BASE
    WHERE NOT EXISTS
    (SELECT BASE2.ID_SCHED_TASK
    FROM M4RJS_SCHED_TASKS BASE2
    WHERE BASE2.ID_SCHED_TASK>BASE.ID_SCHED_TASK
    AND BASE2.ID_SCHED_TASK<BASE.ID_SCHED_TASK+2)
    ORDER BY 1 ASC
    Execution Plan
    Plan hash value: 3937517195
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 14 | | 328 (2)| 00:00:04 |
    | 1 | SORT AGGREGATE | | 1 | 14 | | | |
    | 2 | MERGE JOIN ANTI | | 495 | 6930 | | 328 (2)| 00:00:04 |
    | 3 | INDEX FULL SCAN | PK0004111303310 | 49487 | 338K| | 119 (1)| 00:00:02 |
    |* 4 | FILTER | | | | | | |
    |* 5 | SORT JOIN | | 49487 | 338K| 1576K| 209 (2)| 00:00:03 |
    | 6 | INDEX FAST FULL SCAN| PK0004111303310 | 49487 | 338K| | 33 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    4 - filter("BASE2"."ID_SCHED_TASK"<"BASE"."ID_SCHED_TASK"+2)
    5 - access("BASE2"."ID_SCHED_TASK">"BASE"."ID_SCHED_TASK")
    filter("BASE2"."ID_SCHED_TASK">"BASE"."ID_SCHED_TASK")
    Statistics
    1 recursive calls
    0 db block gets
    242 consistent gets
    8 physical reads
    0 redo size
    519 bytes sent via SQL*Net to client
    524 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    1 rows processed
    Thanks to all !

    Sorry Mschnatt, I posted the wrong query, i was testing with HINTS, the correct query is your posted query.
    1* I analyzed the tables and the result is the same:
    This is the query and "autorace on" log using OPTIMIZER_MODE=RULE on Oracle 11g:
    SQL> R
    1 SELECT MIN(BASE.ID_SCHED_TASK)+1 I
    2 FROM M4RJS_SCHED_TASKS BASE
    3 WHERE NOT EXISTS
    4 (SELECT BASE2.ID_SCHED_TASK
    5 FROM M4RJS_SCHED_TASKS BASE2
    6 WHERE BASE2.ID_SCHED_TASK>BASE.ID_SCHED_TASK
    7 AND BASE2.ID_SCHED_TASK<BASE.ID_SCHED_TASK+2)
    8* ORDER BY 1 ASC
    I
    2
    Elapsed: 00:00:00.33
    Execution Plan
    Plan hash value: 795265574
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | SORT AGGREGATE | |
    |* 2 | FILTER | |
    | 3 | TABLE ACCESS FULL | M4RJS_SCHED_TASKS |
    |* 4 | INDEX RANGE SCAN | PK0004111303310 |
    Predicate Information (identified by operation id):
    2 - filter( NOT EXISTS (SELECT 0 FROM "M4RJS_SCHED_TASKS" "BASE2"
    WHERE "BASE2"."ID_SCHED_TASK"<:B1+2 AND "BASE2"."ID_SCHED_TASK">:B2))
    4 - access("BASE2"."ID_SCHED_TASK">:B1 AND
    "BASE2"."ID_SCHED_TASK"<:B2+2)
    Note
    - rule based optimizer used (consider using cbo)
    Statistics
    0 recursive calls
    0 db block gets
    101509 consistent gets
    0 physical reads
    0 redo size
    519 bytes sent via SQL*Net to client
    524 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed
    This is the query and "autorace on" log using OPTIMIZER_MODE=ALL_ROWA on Oracle 11g:
    Elapsed: 00:03:14.78
    Execution Plan
    Plan hash value: 3937517195
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 12 | | 317 (2)| 00:00:04 |
    | 1 | SORT AGGREGATE | | 1 | 12 | | | |
    | 2 | MERGE JOIN ANTI | | 495 | 5940 | | 317 (2)| 00:00:04 |
    | 3 | INDEX FULL SCAN | PK0004111303310 | 49487 | 289K| | 119 (1)| 00:00:02 |
    |* 4 | FILTER | | | | | | |
    |* 5 | SORT JOIN | | 49487 | 289K| 1176K| 198 (3)| 00:00:03 |
    | 6 | INDEX FAST FULL SCAN| PK0004111303310 | 49487 | 289K| | 33 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    4 - filter("BASE2"."ID_SCHED_TASK"<"BASE"."ID_SCHED_TASK"+2)
    5 - access("BASE2"."ID_SCHED_TASK">"BASE"."ID_SCHED_TASK")
    filter("BASE2"."ID_SCHED_TASK">"BASE"."ID_SCHED_TASK")
    Statistics
    0 recursive calls
    0 db block gets
    242 consistent gets
    0 physical reads
    0 redo size
    519 bytes sent via SQL*Net to client
    524 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    1 rows processed
    3* This is an example query, the problem persist in other bigger queries.
    Thanks for you help

  • Oracle 11g: Block Corruption in SYSAUX File

    Hello All,
    I am facing Data corruption issue in the SYSAUX file.
    We are using Oracle 11G (Microsoft 32 bit) and our system is running in noarchivelog mode.
    Following are the errors in the alert log.
    e:\sc\sc15.2\databases\oracleconfig\diag\rdbms\enmscsdb\nm45\trace\nm45_p000_5944.trc
    Corrupt block relative dba: 0x0088a9f8 (file 2, block 567800)
    Fractured block found during buffer read
    Data in bad block:
    type: 6 format: 2 rdba: 0x0088a9f8
    last change scn: 0x0000.0b3bb7c7 seq: 0x1 flg: 0x04
    spare1: 0x0 spare2: 0x0 spare3: 0x0
    consistency value in tail: 0xc7000601
    check value in block header: 0xee6b
    computed block checksum: 0x72c6
    Reread of rdba: 0x0088a9f8 (file 2, block 567800) found same corrupted data
    Thu Jan 22 16:46:44 2009
    SMON: Restarting fast_start parallel rollback
    SMON: ignoring slave err,downgrading to serial rollback
    ORACLE Instance nm45 (pid = 12) - Error 1578 encountered while recovering transaction (9, 11) on object 458.
    Errors in file e:\sc\sc15.2\databases\oracleconfig\diag\rdbms\enmscsdb\nm45\trace\nm45_smon_6492.trc:
    ORA-01578: ORACLE data block corrupted (file # 2, block # 567800)
    ORA-01110: data file 2: 'E:\SC\SC15.2\DATABASES\ORACLECONFIG\SYSAUXNM45.ORA'
    Thu Jan 22 16:46:45 2009
    Trace dumping is performing id=[cdmp_20090122164645]
    Corrupt Block Found
    TSN = 1, TSNAME = SYSAUX
    RFN = 2, BLK = 567800, RDBA = 8956408
    OBJN = 458, OBJD = 458, OBJECT = I_WRI$_OPTSTAT_HH_OBJ_ICOL_ST, SUBOBJECT =
    SEGMENT OWNER = SYS, SEGMENT TYPE = Index Segment
    Following query indicates the corruption is in index.
    SQL> SELECT tablespace_name, segment_type, owner, segment_name FROM dba_extents
    WHERE file_id = 2 and 567800 between block_id AND block_id + blocks - 1;
    TABLESPACE_NAME SEGMENT_TYPE OWNER
    SEGMENT_NAME
    SYSAUX INDEX SYS
    I_WRI$_OPTSTAT_HH_OBJ_ICOL_ST
    ==============
    DBverify output:
    ==============
    E:\SC\SC15.2\Databases\OracleConfig>dbv file=SYSAUXNM45.ORA blocksize=8192
    DBVERIFY: Release 11.1.0.7.0 - Production on Thu Jan 22 16:59:11 2009
    Copyright (c) 1982, 2007, Oracle. All rights reserved.
    DBVERIFY - Verification starting : FILE = E:\SC\SC15.2\Databases\OracleConfig/SY
    SAUXNM45.ORA
    DBV-00200: Block, DBA 8956312, already marked corrupt
    Page 567800 is influx - most likely media corrupt
    Corrupt block relative dba: 0x0088a9f8 (file 2, block 567800)
    Fractured block found during dbv:
    Data in bad block:
    type: 6 format: 2 rdba: 0x0088a9f8
    last change scn: 0x0000.0b3bb7c7 seq: 0x1 flg: 0x04
    spare1: 0x0 spare2: 0x0 spare3: 0x0
    consistency value in tail: 0xc7000601
    check value in block header: 0xee6b
    computed block checksum: 0x72c6
    DBVERIFY - Verification complete
    Total Pages Examined : 1623864
    Total Pages Processed (Data) : 540984
    Total Pages Failing (Data) : 0
    Total Pages Processed (Index): 964944
    Total Pages Failing (Index): 0
    Total Pages Processed (Other): 17849
    Total Pages Processed (Seg) : 0
    Total Pages Failing (Seg) : 0
    Total Pages Empty : 100086
    Total Pages Marked Corrupt : 2
    Total Pages Influx : 1
    Total Pages Encrypted : 0
    Highest block SCN : 190789648 (0.190789648)
    SQL> select * from v$database_block_corruption;
    FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
    2 567800 1 0 FRACTURED
    2 567704 1 0 FRACTURED
    How to resolve this issue.
    Thanks
    With Regards
    Hemant Joshi.

    Drop and re-creating the index would be better than re-building the index.
    Check the metalink note: Identify the corruption extension using RMAN/DBV/ANALYZE etc - 836658.1
    Note 28814.1 - Handling Oracle Block Corruptions in Oracle7/8/8i/9i/10g
    Note 472231.1 - How to identify all the Corrupted Objects in the Database reported by RMAN
    ORA-1578 Main Reference Index for Solutions -830997.1

  • Oracle report problem-Passing a column value from a query block to another

    Hi I am facing a problem in oracle reports.
    I have 3 query blocks say Q1,Q2 and Q3.
    From Q1 I get a tblkey coulmn and for each value of tblkey I need to pass it on to Q2 which gives me a status and now finally Q3 will take tblkey and status to give me final output.
    Can somebody please tell me how I can do it?
    Thanks,
    Avin

    Depending on your report requirement, you may do a join of Q1, Q2, and Q3; or keep all Qs and for Q3 use subqueries ...
    Select ... from ... where tblkey, status in (
    select tblkey, status from ... where tblkey in (
    select tblkey from .... where .... ) )
    Good luck.
    DC

  • Query not considering function based index in oracle 11g

    I have a query which used Function Based Index when run in oracle 9i but when I run the same query
    without any changes, it does not consider index. Below is the query:
    SELECT distinct patient_role.domain_key, patient_role.patient_role_key,
    patient_role.emergency_contact_name,
    patient_role.emergency_contact_phone, patient_role.emergency_contact_note,
    patient_role.emergency_contact_relation_id,
    patient_role.financial_class_desc_id, no_known_allergies, patient_role.CREATED_BY,
    patient_role.CREATED_TIMESTAMP,
    patient_role.CREATED_TIMESTAMP_TZ, patient_role.UPDATED_BY, patient_role.UPDATED_TIMESTAMP,
    patient_role.UPDATED_TIMESTAMP_TZ,
    patient_role.discontinued_date
    FROM encounter, patient_role
    WHERE patient_role.patient_role_key = encounter.patient_role_key
    AND UPPER(TRIM(leading :SYS_B_0 from encounter.account_number)) = UPPER(TRIM(leading :SYS_B_1 from
    :SYS_B_2))
    AND patient_role.discontinued_date IS null
    AND encounter.discontinued_date IS null ;
    Index definition:
    CREATE INDEX "user1"."IX_TRIM_ACCOUNT_NUMBER" ON "user1."ENCOUNTER" (UPPER(TRIM(LEADING
    '0' FROM "ACCOUNT_NUMBER")), "PATIENT_ROLE_KEY", "DOMAIN_KEY", "DISCONTINUED_DATE")
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
    BUFFER_POOL DEFAULT)
    TABLESPACE "user1"
    Database : Oracle 11g (11.2.0.3)
    O/S : Linux 64 bit (the query does not consider index even on windows os)
    Any suggestions?
    -Onkar
    Edited by: onkar.nath on Jul 2, 2012 3:32 PM

    Onkar,
    I don't appreciate you posting this question in several forums at the same time.
    If I would know you also posted this on Asktom, I wouldn't even have bothered.
    As to your 'issue':
    First of all: somehow cursor_sharing MUST have been set to FORCE. Oracle is a predictable system, not a fruitmachine.
    Your statement the '0' is replaced by a bind variable anyway is simply false. If you really believe it is not false, SUBMIT a SR.
    But your real issue is not Oracle: it is your 'application', which is a mess anyway. Allowing for alphanumeric numbers is a really bad idea.
    Right now you are already putting workaround on workaround on workaround on workaround.
    Issue is the application: it is terminal., and you either need to kill it, or to replace it.
    Sybrand Bakker
    Senior Oracle DBA

  • Select first and last records in grouped results - Oracle 11g

    Say I have the following information in an Oracle 11g table:
    Qty
    Production order
    Date and time
    20
    00000000000000001
    12-JAN-14 00:02
    20
    00000000000000001
    12-JAN-14 00:05
    20
    00000000000000001
    12-JAN-14 00:07
    20
    00000000000000001
    13-JAN-14 00:09
    30
    00000000000000002
    12-JAN-14 00:11
    30
    00000000000000002
    12-JAN-14 00:15
    30
    00000000000000002
    12-JAN-14 00:20
    30
    00000000000000002
    14-JAN-14 00:29
    I would like to write a query that would return the following:
    Qty
    Production order
    First
    Last
    80
    00000000000000001
    12-JAN-14 00:02
    13-JAN-14 00:09
    120
    00000000000000002
    12-JAN-14 00:11
    14-JAN-14 00:29
    That is, the sum of the Qty column grouped by Production order, and the date/time of the first and last records for each Production order.
    I came up with a query that yielded this result:
    Qty
    Production order
    First
    Last
    80
    00000000000000001
    12-JAN-14 00:02
    14-JAN-14 00:29
    120
    00000000000000002
    12-JAN-14 00:02
    14-JAN-14 00:29
    Which means that the First and Last columns show the overall first and last date / time of the whole table. Please note that this is a dummy table. Sorry I am now allowed to write the actual query
    I came up with since work policies do not allow me to share it. Also, I tried with windowing functions such as rank()and row_number() but my user does not have enough privileges to do so.
    Any help or hints will be greatly appreciated.

    Due to the fact that Oracle does not record the rows in any particular order, it would be wrong that the "first date" would be the first row processed by the query.
    Therefore you would have to supply some other column if you do not want to consider the table as ordered by date.
    Also, any analytical functions will need you to supply the "order by" and if its the date, then just a simple query will do:
    SQL>WITH Tab1 (Qty, Production_Order, Pdate)
      2       AS (SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:02', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      3           SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:05', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      4           SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:07', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      5           SELECT 20, '00000000000000001', TO_DATE ( '13-JAN-14 00:09', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      6           SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:11', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      7           SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:15', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      8           SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:20', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
      9           SELECT 30, '00000000000000002', TO_DATE ( '14-JAN-14 00:29', 'DD-MON-YY HH24:MI') FROM DUAL)
    10  SELECT   SUM ( Qty), Production_Order, MIN ( Pdate), MAX ( Pdate)
    11      FROM Tab1
    12  GROUP BY Production_Order
    13* ORDER BY Production_Order
    SQL> /
      SUM(QTY) PRODUCTION_ORDER     MIN(PDATE)                    MAX(PDATE)
            80 00000000000000001    12-Jan-2014 00:02:00          13-Jan-2014 00:09:00
           120 00000000000000002    12-Jan-2014 00:11:00          14-Jan-2014 00:29:00

Maybe you are looking for

  • Entered wrong wireless password and don't know how to change it

    I recently switched to a Macbook Pro from a PC and attempted to connect to my 2Wire home wireless network on it. Unfortunately, I entered the password wrong on the secured network, and now the computer regularly tries to connect automatically to the

  • Can't open Appleworks

    I was erasing the free space on my disk tonight in order to get rid of some data that I had deleted and happened to open appleworks and create a document while I was waiting. The only funny thing that happened was a message "your startup disk is full

  • Extractor for Purchasing Conditions for tables EKKO, EKPO and KONV

    Hi Experts, I want to know if there is an Extractor for Purchasing Conditions with fields in tables of Origin: EKKO, EKPO and KONV. Or, at least an extractor with the table KONV. Or, how I can look for it. Any feedback, will be really apreciated. Tha

  • Incorrect display of GB in Itunes

    My Itunes is telling me that with only 512 songs I have 16.32 GB worth of memory. This is impossible as I uploaded this music from cds. Another computer has exactly the same music from the same cds except with 1112 songs it only reads 4.4 GB. What is

  • How to convert OLM files into windows office 2010

    I have temp. a desktop PC and I would like to import my MAC outlook file (.olm) into my office windows 2010 computer. Is there a way to import my olm file inti my windows office 2010? Regards