Select Query Hangs

Hi,
Is there a possibility of a SELECT QUERY (table of about 5000 rows) getting hung?
What could be the possible reason and how to resolve this? Again an interview question?
Regards,
SA

A very broad level question.Definetly a query retrieveing data from a table having 5k rows can hang.You need to study explain plan,wait events and many more.

Similar Messages

  • Select query hangs on Oracle 9i but works fine in Oracle 8i

    Hi Guys,
    For a recap of what happened:
    Migrated from Oracle 8i to 9i for a customer, all queries and statements are working fine, except for this particular query. If i run the same query on 8i it works like a charm.
    In 9i, if i remove even one field from the query, it works else it just hangs.
    Any idea, any one???
    **Added 2:09PM: When i removed some ltrim and rtrim that i believe not necessary, the query works fine, is there any field length limitation in Oracle 9i???
    Below is the query:
    set pagesize 100;
    set linesize 1024;
    set heading off;
    set echo off;
    spool scb_xfer_hdr_npsx;
    select ltrim(rtrim(to_char(hdr_srl_no,'99'))) || ';' ||
    'P' || ';' || rtrim(ltrim(payment_type))|| ';'|| ';' ||
    ltrim(rtrim(our_ref_no))|| ';'|| 'MY;KUL;' ||
         rtrim(ltrim(debit_account_no))||';'||
    rtrim(ltrim(to_char(scb_batch_date,'YYYY/MM/DD'))) || ';'|| ';' ||
    rtrim(ltrim(payee_name_1))|| ';'|| ';' ||
    rtrim(ltrim(address_1))|| ';'||
    rtrim(ltrim(address_2))|| ';'||
    rtrim(ltrim(address_3))|| ';'|| ';' ||
    rtrim(ltrim(payee_name_11))|| ';' ||
    rtrim(ltrim(address_11))|| ';'||
    rtrim(ltrim(address_21))|| ';'||
    rtrim(ltrim(address_31))|| ';'|| ';' ||
         rtrim(ltrim(payee_bank_code)) || ';' || ';' ||
         rtrim(ltrim(payee_account_no)) || ';' ||
         rtrim(ltrim(our_ref_no2)) || ';' || ';' ||
         rtrim(ltrim(our_ref_no2)) || ';' || ';' || ';' || ';' ||
    rtrim(ltrim(payment_currency))|| ';'||
    rtrim(ltrim(to_char(payment_amount,'9999999999.99')))|| ';'||
         'C;P;;' || rtrim(ltrim(payee_bank_name))|| ';' ||
         'KL;;' ||
         rtrim(ltrim(delivery_method)) || ';' ||
         rtrim(ltrim(delivery_by)) || ';' ||
         rtrim(ltrim(counter_pickup_location))
    from scb_xfer_hdr_npsx
    order by hdr_srl_no;
    select distinct 'T;' || ltrim(rtrim(to_char(total_payments))) || ';' ||
         ltrim(rtrim(to_char(total_pay_amount,'9999999999.99')))
    from scb_xfer_hdr_npsx;
    spool off;
    spool scb_xfer_dtl_npsx;
    select ltrim(rtrim(to_char(srl_no,'99'))) || ';' || 'I' || ';' ||
         ltrim(rtrim(doc_no)) || ';' || ltrim(rtrim(to_char(doc_date,'yyyy/mm/dd'))) || ';' ||
         ltrim(rtrim(doc_description)) || ';' ||
         ltrim(rtrim(to_char(doc_amount,'9999999999.99')))
    from scb_xfer_dtl_npsx
    order by srl_no;
    spool off;
    set echo on;
    exit;
    Message was edited by:
    Logesh

    Hi,
    are you still on a 32bit kernel on AIX?
    How are the Form4.5 connected, are they on the same box, or are they using the forms GUI?
    What about the statistics, how do you collect them? Is the database set to the COST based optimizer?
    Do you use dbms_utility.analyze_schema, or this:
    exec dbms_stats.gather_schema_stats( -
    ownname => '$OWNER', -
    estimate_percent => 10, -
    granularity => 'ALL', -
    method_opt => 'FOR ALL COLUMNS SIZE 75', -
    degree => NULL , -
    options => 'GATHER $GATH', -
    cascade => TRUE -
    What does it mean the SQL hangs? Can you cancel the query? Do you have to kill the session? Do you use any diagnostic tools like TOAD to trace the session, see what it is doing? Usually if this is a performance/tuning issue, you will see the session is not dead, but you will see advancing reads.
    Regards,
    Richard.

  • Select Query Hangs / No DB Locks / Query Plan is good

    I have below query in application which hangs ( Only sometimes ) and there are some session which also try to insert data into this tables also starts getting hanged.
    SELECT DISTINCT F2 || ' - ' || F3 || ' - ' || F4
    FROM Table1
    WHERE F4 = 6160
    AND F1|| F2|| F3 NOT IN (
    SELECT F2|| F3 || F4
    FROM Table2
    WHERE F1 = 181)
    F2 - varchar(4)
    F3- varchar(100)
    F4- varchar(20)
    F1,F1 are NUMBER
    Table1 has one unique index comprising all fields in ORDER F1,F2, X,F3, F4,Y - X,Y are some different field.
    Table2 has one unique index comprising all fields in ORDER F1,F3, F4,F2 are some different field.
    Below are facts from DBA ----
    1- Session Query Plan was excellent -
    2 - No tables were locked in DB
    3 - Statistics on this table Table1 was calculated on Feb, 2008 and shows 8 millions rows but actual current row count is 13 million. DBA says sometime analyzing statistics again may cause poor query performance.
    4- There were 8 session in DB, 1 was for above select statement and other 7 were trying to insert data into above table.
    Can you please advise what could else be verified to root cause issue as it has been hanging many times - hence causing other session to hang ?
    Many Thanks

    Can you clarify exactly what the DBA meant by "No tables were locked in DB"? What was the exact query that was used to determine this? Was it hitting V$LOCK (GV$LOCK in a RAC system)? Or the DBA_BLOCKERS and DBA_WAITERS tables? Or something else? The specific query here is important because there is a world of difference between a row-level lock and a table-level lock. Of course, locks would never prevent a SELECT statement from running, but it could cause problems for the INSERT statements.
    I strongly concur with Old DBA's suggestion about refactoring the query to not do the concatenation in the NOT IN clause.
    Are the F4 = 6160 and F1 = 181 conditions really using hard-coded numeric literals? Or are these bind variables? Is the data in F1 or F4 skewed-- that is, are there certain values that are more likely than other values?
    How many rows would you expect to be in Table1 with an F4 value of 6160? How many rows in Table2 with a F1 value of 181?
    Justin

  • Query Hangs while Parsing

    In one of our databases, one of the Select query hangs at the parsing stage. The query was working fine few days back. How and what can be traced to see the cause of this hang. Database is in 10.2.0.3 and statistics has been gathered for all the affected tables.

    Thanks for the info. The SEQ# is not changing in the v$session_waits. I have found a workaround for this problem. If I delete the statistics for CS_MEASUREMENT table, the query gets executed in .35 secs! If i collect stats again and runs, it hangs.
    The session trace below.
    TKPROF: Release 10.2.0.3.0 - Production on Fri May 30 11:43:02 2008
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Trace file: css1cldr_ora_10134.trc
    Sort options: default
    count = number of times OCI procedure was executed
    cpu = cpu time in seconds executing
    elapsed = elapsed time in seconds executing
    disk = number of physical reads of buffers from disk
    query = number of buffers gotten for consistent read
    current = number of buffers gotten in current mode (usually for update)
    rows = number of rows processed by the fetch or execute call
    select i.obj#,i.ts#,i.file#,i.block#,i.intcols,i.type#,i.flags,i.property,
    i.pctfree$,i.initrans,i.maxtrans,i.blevel,i.leafcnt,i.distkey,i.lblkkey,
    i.dblkkey,i.clufac,i.cols,i.analyzetime,i.samplesize,i.dataobj#,
    nvl(i.degree,1),nvl(i.instances,1),i.rowcnt,mod(i.pctthres$,256),
    i.indmethod#,i.trunccnt,nvl(c.unicols,0),nvl(c.deferrable#+c.valid#,0),
    nvl(i.spare1,i.intcols),i.spare4,i.spare2,i.spare6,decode(i.pctthres$,null,
    null,mod(trunc(i.pctthres$/256),256)),ist.cachedblk,ist.cachehit,
    ist.logicalread
    from
    ind$ i, ind_stats$ ist, (select enabled, min(cols) unicols,
    min(to_number(bitand(defer,1))) deferrable#,min(to_number(bitand(defer,4)))
    valid# from cdef$ where obj#=:1 and enabled > 1 group by enabled) c where
    i.obj#=c.enabled(+) and i.obj# = ist.obj#(+) and i.bo#=:1 order by i.obj#
    call count cpu elapsed disk query current rows
    Parse 1 0.01 0.00 0 0 0 0
    Execute 3 0.01 0.01 0 0 0 0
    Fetch 10 0.00 0.00 0 33 0 7
    total 14 0.02 0.02 0 33 0 7
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: CHOOSE
    Parsing user id: SYS (recursive depth: 1)
    Rows Row Source Operation
    2 SORT ORDER BY (cr=10 pr=0 pw=0 time=2852 us)
    2 HASH JOIN OUTER (cr=10 pr=0 pw=0 time=2741 us)
    2 NESTED LOOPS OUTER (cr=7 pr=0 pw=0 time=102 us)
    2 TABLE ACCESS CLUSTER IND$ (cr=5 pr=0 pw=0 time=73 us)
    1 INDEX UNIQUE SCAN I_OBJ# (cr=2 pr=0 pw=0 time=29 us)(object id 3)
    0 TABLE ACCESS BY INDEX ROWID IND_STATS$ (cr=2 pr=0 pw=0 time=22 us)
    0 INDEX UNIQUE SCAN I_IND_STATS$_OBJ# (cr=2 pr=0 pw=0 time=18 us)(object id 711)
    2 VIEW (cr=3 pr=0 pw=0 time=361 us)
    2 SORT GROUP BY (cr=3 pr=0 pw=0 time=356 us)
    2 TABLE ACCESS CLUSTER CDEF$ (cr=3 pr=0 pw=0 time=58 us)
    1 INDEX UNIQUE SCAN I_COBJ# (cr=2 pr=0 pw=0 time=25 us)(object id 30)
    select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#,
    sample_size, minimum, maximum, distcnt, lowval, hival, density, col#,
    spare1, spare2, avgcln
    from
    hist_head$ where obj#=:1 and intcol#=:2
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 50 0.01 0.00 0 0 0 0
    Fetch 50 0.00 0.00 0 150 0 50
    total 101 0.01 0.01 0 150 0 50
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: RULE
    Parsing user id: SYS (recursive depth: 2)
    Rows Row Source Operation
    1 TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr=3 pr=0 pw=0 time=81 us)
    1 INDEX RANGE SCAN I_HH_OBJ#_INTCOL# (cr=2 pr=0 pw=0 time=57 us)(object id 257)
    select /*+ rule */ bucket, endpoint, col#, epvalue
    from
    histgrm$ where obj#=:1 and intcol#=:2 and row#=:3 order by bucket
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 60 0.03 0.01 0 0 0 0
    Fetch 60 0.01 0.00 0 206 0 973
    total 121 0.04 0.02 0 206 0 973
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: RULE
    Parsing user id: SYS (recursive depth: 2)
    Rows Row Source Operation
    3 SORT ORDER BY (cr=3 pr=0 pw=0 time=130 us)
    3 TABLE ACCESS CLUSTER HISTGRM$ (cr=3 pr=0 pw=0 time=66 us)
    1 INDEX UNIQUE SCAN I_OBJ#_INTCOL# (cr=2 pr=0 pw=0 time=27 us)(object id 252)
    Elapsed times include waiting on following events:
    Event waited on Times Max. Wait Total Waited
    ---------------------------------------- Waited ---------- ------------
    SQL*Net message to client 1 0.00 0.00
    SQL*Net message from client 1 10.13 10.13
    select pos#,intcol#,col#,spare1,bo#,spare2
    from
    icol$ where obj#=:1
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 7 0.01 0.00 0 0 0 0
    Fetch 25 0.00 0.00 0 50 0 18
    total 33 0.01 0.00 0 50 0 18
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: CHOOSE
    Parsing user id: SYS (recursive depth: 1)
    Rows Row Source Operation
    2 TABLE ACCESS BY INDEX ROWID ICOL$ (cr=6 pr=0 pw=0 time=36 us)
    2 INDEX RANGE SCAN I_ICOL1 (cr=4 pr=0 pw=0 time=38 us)(object id 40)
    select name,intcol#,segcol#,type#,length,nvl(precision#,0),decode(type#,2,
    nvl(scale,-127/*MAXSB1MINAL*/),178,scale,179,scale,180,scale,181,scale,182,
    scale,183,scale,231,scale,0),null$,fixedstorage,nvl(deflength,0),default$,
    rowid,col#,property, nvl(charsetid,0),nvl(charsetform,0),spare1,spare2,
    nvl(spare3,0)
    from
    col$ where obj#=:1 order by intcol#
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 3 0.00 0.01 0 0 0 0
    Fetch 87 0.00 0.00 0 11 0 84
    total 91 0.00 0.01 0 11 0 84
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: CHOOSE
    Parsing user id: SYS (recursive depth: 1)
    Rows Row Source Operation
    12 SORT ORDER BY (cr=3 pr=0 pw=0 time=157 us)
    12 TABLE ACCESS CLUSTER COL$ (cr=3 pr=0 pw=0 time=79 us)
    1 INDEX UNIQUE SCAN I_OBJ# (cr=2 pr=0 pw=0 time=24 us)(object id 3)
    select col#, grantee#, privilege#,max(mod(nvl(option$,0),2))
    from
    objauth$ where obj#=:1 and col# is not null group by privilege#, col#,
    grantee# order by col#, grantee#
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 3 0.00 0.00 0 0 0 0
    Fetch 3 0.00 0.00 0 6 0 0
    total 7 0.00 0.00 0 6 0 0
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: CHOOSE
    Parsing user id: SYS (recursive depth: 1)
    Rows Row Source Operation
    0 SORT GROUP BY (cr=2 pr=0 pw=0 time=57 us)
    0 TABLE ACCESS BY INDEX ROWID OBJAUTH$ (cr=2 pr=0 pw=0 time=34 us)
    0 INDEX RANGE SCAN I_OBJAUTH1 (cr=2 pr=0 pw=0 time=31 us)(object id 103)
    select grantee#,privilege#,nvl(col#,0),max(mod(nvl(option$,0),2))
    from
    objauth$ where obj#=:1 group by grantee#,privilege#,nvl(col#,0) order by
    grantee#
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 3 0.00 0.00 0 0 0 0
    Fetch 18 0.00 0.00 0 12 0 15
    total 22 0.00 0.00 0 12 0 15
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: CHOOSE
    Parsing user id: SYS (recursive depth: 1)
    Rows Row Source Operation
    5 SORT GROUP BY (cr=4 pr=0 pw=0 time=107 us)
    5 TABLE ACCESS BY INDEX ROWID OBJAUTH$ (cr=4 pr=0 pw=0 time=43 us)
    5 INDEX RANGE SCAN I_OBJAUTH1 (cr=2 pr=0 pw=0 time=16 us)(object id 103)
    select con#,obj#,rcon#,enabled,nvl(defer,0)
    from
    cdef$ where robj#=:1
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 3 0.01 0.00 0 0 0 0
    Fetch 3 0.00 0.00 0 3 0 0
    total 7 0.01 0.00 0 3 0 0
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: CHOOSE
    Parsing user id: SYS (recursive depth: 1)
    Rows Row Source Operation
    0 TABLE ACCESS BY INDEX ROWID CDEF$ (cr=1 pr=0 pw=0 time=22 us)
    0 INDEX RANGE SCAN I_CDEF3 (cr=1 pr=0 pw=0 time=20 us)(object id 52)
    select con#,type#,condlength,intcols,robj#,rcon#,match#,refact,nvl(enabled,0),
    rowid,cols,nvl(defer,0),mtime,nvl(spare1,0)
    from
    cdef$ where obj#=:1
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 3 0.00 0.00 0 0 0 0
    Fetch 34 0.00 0.00 0 42 0 31
    total 38 0.00 0.00 0 42 0 31
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: CHOOSE
    Parsing user id: SYS (recursive depth: 1)
    Rows Row Source Operation
    5 TABLE ACCESS CLUSTER CDEF$ (cr=9 pr=0 pw=0 time=17 us)
    1 INDEX UNIQUE SCAN I_COBJ# (cr=2 pr=0 pw=0 time=10 us)(object id 30)
    select intcol#,nvl(pos#,0),col#,nvl(spare1,0)
    from
    ccol$ where con#=:1
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 31 0.01 0.00 0 0 0 0
    Fetch 70 0.00 0.00 0 140 0 39
    total 102 0.01 0.00 0 140 0 39
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: CHOOSE
    Parsing user id: SYS (recursive depth: 1)
    Rows Row Source Operation
    2 TABLE ACCESS BY INDEX ROWID CCOL$ (cr=6 pr=0 pw=0 time=49 us)
    2 INDEX RANGE SCAN I_CCOL1 (cr=4 pr=0 pw=0 time=45 us)(object id 54)
    select condition
    from
    cdef$ where rowid=:1
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 1 0.00 0.00 0 2 0 1
    total 3 0.00 0.00 0 2 0 1
    Misses in library cache during parse: 0
    Optimizer mode: CHOOSE
    Parsing user id: SYS (recursive depth: 1)
    Rows Row Source Operation
    1 TABLE ACCESS BY USER ROWID CDEF$ (cr=1 pr=0 pw=0 time=18 us)
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 0 0.00 0.00 0 0 0 0
    Execute 0 0.00 0.00 0 0 0 0
    Fetch 0 0.00 0.00 0 0 0 0
    total 0 0.00 0.00 0 0 0 0
    Misses in library cache during parse: 0
    Elapsed times include waiting on following events:
    Event waited on Times Max. Wait Total Waited
    ---------------------------------------- Waited ---------- ------------
    SQL*Net message to client 1 0.00 0.00
    SQL*Net message from client 1 10.13 10.13
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 11 0.01 0.01 0 0 0 0
    Execute 167 0.08 0.07 0 0 0 0
    Fetch 361 0.01 0.01 0 655 0 1218
    total 539 0.10 0.10 0 655 0 1218
    Misses in library cache during parse: 10
    Misses in library cache during execute: 10
    0 user SQL statements in session.
    167 internal SQL statements in session.
    167 SQL statements in session.
    Trace file: css1cldr_ora_10134.trc
    Trace file compatibility: 10.01.00
    Sort options: default
    1 session in tracefile.
    0 user SQL statements in trace file.
    167 internal SQL statements in trace file.
    167 SQL statements in trace file.
    11 unique SQL statements in trace file.
    3548 lines in trace file.
    0 elapsed seconds in trace file.

  • Select query over database link hanging

    Hi All,
    I have been looking all over the internet and all over this forum but i could not find the solution for my issue given below.
    There are a number of distributed databases (Oracle 10g) over a private network. Sending and receiving data amongst all the databases work fine. But when one particular database A tries to receive data from database B, it hangs and then the famous old error TNS LOST CONTACT.
    Basically, this has been implemented by creating a batchjob. This worked fine for years and now suddenly this is not working only for the two specific databases.
    It is just a simple select query being hit on the remote database. This is called through a function in the package, which builds the dynamic select query using DBMS_SQL package.
    It actually hangs when doing DBMS_SQL.PARSE ();
    The same function when called in a pl/sql block from database A, works perfectly fine and receives the required data from database B. This was tried with Oracle SQLDeveloper, TOAD and SQLPLUS.
    Things seems to be working fine, but actually unaware of the problem. I tried all the suggestions provided over the metalink also.
    Require your help urgently.
    Thanks
    Akhil.

    Hi Rajat,
    The user uses DEFAULT profile. The details of the parameter are:
    PROFILE RESOURCE_NAME RESOURCE_TYPE LIMIT
    DEFAULT COMPOSITE_LIMIT KERNEL UNLIMITED
    DEFAULT SESSIONS_PER_USER KERNEL UNLIMITED
    DEFAULT CPU_PER_SESSION KERNEL UNLIMITED
    DEFAULT CPU_PER_CALL KERNEL UNLIMITED
    DEFAULT LOGICAL_READS_PER_SESSION KERNEL UNLIMITED
    DEFAULT LOGICAL_READS_PER_CALL KERNEL UNLIMITED
    DEFAULT IDLE_TIME KERNEL UNLIMITED
    DEFAULT CONNECT_TIME KERNEL UNLIMITED
    DEFAULT PRIVATE_SGA KERNEL UNLIMITED
    DEFAULT FAILED_LOGIN_ATTEMPTS PASSWORD 10
    DEFAULT PASSWORD_LIFE_TIME PASSWORD UNLIMITED
    DEFAULT PASSWORD_REUSE_TIME PASSWORD UNLIMITED
    DEFAULT PASSWORD_REUSE_MAX PASSWORD UNLIMITED
    DEFAULT PASSWORD_VERIFY_FUNCTION PASSWORD NULL
    DEFAULT PASSWORD_LOCK_TIME PASSWORD UNLIMITED
    DEFAULT PASSWORD_GRACE_TIME PASSWORD UNLIMITED
    Thanks
    Akhil

  • Select query in not working for Count(*)

    Hi,
    Our batch team running one query that is selecting one table TSFHEAD and this query is hanging. Below are diffrent shenario in which the select query is running on this table.
    select * from tsfhead where create_id = 'BATCH' and create_date = '26-OCT-12';
    --not returning any rows and hanging
    select * from tsfhead where create_id = 'BATCH' ---returning rows
    select * from tsfhead where create_date = '26-OCT-12'; --- returning rows
    select count(*) from tsfhead ----not returning rows and hanging
    This table TSFHEAD has 59000 rows.
    SQL> explain plan for select * from tsfhead where create_id = 'BATCH' and create_date = '26-OCT-12';
    Explained.
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 415503093
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 67 | 215 (1)| 00:00:03 |
    |* 1 | TABLE ACCESS FULL| TSFHEAD | 1 | 67 | 215 (1)| 00:00:03 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
    1 - filter("CREATE_ID"='BATCH' AND "CREATE_DATE"='26-OCT-12')
    I don't know why this query behaving in this manner.Please help.

    RanVijai_dba wrote:
    Thanks for your reply. But +"select count(*) from tsfhead"+ is hanging and +"select * from tsfhead where create_date = '26-OCT-12' "+ is showing records.It might be showing records, but not necessarily the correct records.
    As sb points out, you are treating dates as strings rather than the DATE datatype. That means you could be querying the wrong data, and your query is also not safe in different environments. It could also effect the query execution plan. Also, as pointed out, you should be ideally using 4 digit years. There were many headaches caused by the use of 2 digit years that most companies corrected as part of the millenium bug fixes prior to the year 2000... well over a decade ago, and most good designs now ensure that 4 digit years are used as standard.
    So your query would be better written as:
    select * from tsfhead where create_date = TO_DATE('26-OCT-2012','DD-MON-YYYY')When you say:
    select count(*) from tsfhead... is hanging, you say the table has around 59000 rows in it, and in reality that's a small amount of records, so a count(*) shouldn't take long at all, even doing a full table scan.
    Post the explain plan for that simple count(*) query for us. (and ensure you use {noformat}{noformat} tags to keep the formatting on the forum, as described in {message:id=9360002})                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Problem in the "select" query....Just check out and help me

    Hi there !!
    I am getting the following errors while trying to execute the "select" query from JSP page:
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
    My code is :
    String reg_no=(String)session.getAttribute("reg_no");
    ResultSet rs=stmt.executeQuery("SELECT * FROM reg WHERE regno = "+reg_no);
    (Note: the "regno" in the database is of numeric datatype)
    Try to help me...
    Thanx,
    Ram.

    Just so everyone knows:
    Ram Mohan joined the forum on 7-Sep-2003 and received
    his 25 Dukes for joining.
    Since then, he's posted three questions, each one
    promising 5-10 Dukes, and never once awarded them.
    His strategy seems to be to wave Dukes, ask his
    hit-and-run question, and then bolt.
    Answer his questions if you wish, but don't do it
    expecting Dukes. - MODDuffy, you're getting just as cranky as I have. See what hanging around these forums does to oneself? :)

  • Order by in select query

    Hi guys
    i am getting problem in my select query which is creating one long string, it is working fine without order by but when i run this with order by it get hanged. this query using on function to concatenate multiple strings in one string as well
    Please help me what i am doing wroing.
    select
    regexp_substr(pe.emp_id,'[0-9]+$') ||'|'||
    p.title ||'|'||
    cdt.text||'|'||
    j.tit||staff_pcb.host_pub_tit ||'|'||
    jou.vol ||pcb.vol||pcp.vol ||'|'||
    jou.journal_number||'|'||
    substr (jou.pages||pcb.pages||pcp.pages, 1, instr (jou.pages||pcb.pages||pcp.pages, '-')-1)||'|'||
    substr (jou.pages||pcb.pages||pcp.pages, instr (jou.pages||pcb.pages||pcp.pages, '-')+1)||'|'||
    pcb.st||jou.st||pcp.st||'|'||
    concat_aut(p.id)
    from pub p,journal j,caa c,person pe,class_t cdt,
    (select pcj.pub_id,pcj.vol,pcj.pages,pcja.st
    From pub_C_j_a pcja,pc_j pcj
    where pcja.pub_c_j_id = pcj.pub_id)jou,
    (select pcb.pub_id,pcb.host_pub_tit,pcb.pages,pcb.vol,pcba.st
    From pub_c_b pcb,pub_c_b_a pcba
    where pcba.pub_c_b_id = pcb.pub_id)pcb,
    (select pcp.pub_id,pcp.vol,pcp.pages,pcpa.st
    From pub_c_p pcp,pub_c_p_a pcpa
    where pcpa.pub_c_p_id = pcp.pub_id)pcp,
    where
    p.id = c.pub_id
    and c.person_id = pe.id
    and p.t_c_id = cdt.c_id
    and p.journal_id = j.id(+)
    and p.id = jou.publication_id(+)
    and p.id = pcb.publication_id(+)
    and p.id = pcp.publication_id(+)
    and substr(regexp_substr(pe.emp_id,'[0-9]+$'),1,2) in('77','78')
    and pcb.st||jou.st||pcp.st='1' order by pe.emp_id
    ;

    Not sure about why it's only hanging on order by but looks like your query causing full table scan because of this in WHERE clause:
    and pcb.st||jou.st||pcp.st='1'
    I would change it to something like:
    and ((pcb.st='1'  and jou.st = '' and pcp.st = '') or (jou.st='1'  and pcb.st = '' and pcp.st = '')  or (pcp.st='1'  and jou.st = '' and pcb.st  = '') )

  • Sql query hangs close to the end

    Hi:
    I am on 10.2.0.3.
    My rather simple query hangs for a few minutes close to the end. It's supposed to return 288 rows and it immediately returns 285, then hangs for 4-5 min, than returns the remaining 3 rows. Kind of similar behavior to using "First_rows" hint - which I'm not using...
    The table has about 100,000 rows.
    Some relevant info is below.
    Any ides appreciated.
    TIA
    PLAN_TABLE_OUTPUT
    Plan hash value: 2481764356
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 30 | 3 (0)| 00:00:01 |
    |* 1 | INDEX RANGE SCAN| PSACOMBO_DATA_TBL | 1 | 30 | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    1 - access("SETID"='GLOBL' AND "PROCESS_GROUP"='100ACDTPRJ' AND
    "COMBINATION"='100ACDTPRJ' AND "VALID_CODE"='V')
    optimizer_dynamic_sampling integer 6
    optimizer_features_enable string 10.2.0.3
    optimizer_index_caching integer 25
    optimizer_index_cost_adj integer 75
    optimizer_mode string ALL_ROWS
    optimizer_secure_view_merging boolean TRUE
    unnestsubquery boolean FALSE

    You said the query is supposed to return 288 rows, but from the explain plan, Oracle "see" only 1 row to be returned. Are the stats up-to-date ? What's the actual query ?
    Please, on the forum side, use tags before and after your code to keep it readable (preserve blanks and tabs).
    Nicolas.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Query hangs with outer query

    Hi,
    OS: SPARC 64 bit
    Oracle Version: 10.2.0.3.0 64 bit
    My query hangs when I include the outer query. When I execute without outer query It comes out in a fraction of second but when I includes outer query it starts hang
    Below is my original query which hangs
    select * from (select raw_sql_.**, rownum raw_rnum_ from (SELECT /*+ FIRST_ROWS */ NETWORK_ID||'","'||CALLER_NUMBER||'","'||CALLED_NUMBER FROM CDR FROM CDR WHERE 1 = 1
    AND day_of_year = 99 AND INTERFACE = 'TRAFIC' AND TIME_STAMP BETWEEN to_date('2009/04/08 00:00:00','yyyy/mm/dd hh24:mi:ss') AND to_date
    ('2009/04/09 00:00:00','yyyy/mm/dd hh24:mi:ss') AND NETWORK_ID IN (1025,1026) order by id desc) raw_sql_ WHERE rownum <= 10000) WHERE raw_rnum_ > 0;
    when I execute this it will come out immediately
    select raw_sql_.**, rownum raw_rnum_ from (SELECT /*+ FIRST_ROWS */ NETWORK_ID||'","'||CALLER_NUMBER||'","'||CALLED_NUMBER FROM CDR FROM CDR WHERE 1 = 1
    AND day_of_year = 99 AND INTERFACE = 'TRAFIC' AND TIME_STAMP BETWEEN to_date('2009/04/08 00:00:00','yyyy/mm/dd hh24:mi:ss') AND to_date
    ('2009/04/09 00:00:00','yyyy/mm/dd hh24:mi:ss') AND NETWORK_ID IN (1025,1026) order by id desc) raw_sql_ WHERE rownum <= 10000
    select * from (select raw_sql_.**, rownum raw_rnum_ from (SELECT /*+ FIRST_ROWS */ NETWORK_ID||'","'||CALLER_NUMBER||'","'||CALLED_NUMBER FROM CDR FROM CDR WHERE 1 = 1
    AND day_of_year = 99 AND INTERFACE = 'TRAFIC' AND TIME_STAMP BETWEEN to_date('2009/04/08 00:00:00','yyyy/mm/dd hh24:mi:ss') AND to_date
    ('2009/04/09 00:00:00','yyyy/mm/dd hh24:mi:ss') AND NETWORK_ID IN (1025,1026) order by id desc) raw_sql_ WHERE rownum <= 10000) WHERE raw_rnum_ > 0;
    but when I includes outer query I hangs it is really very weird for me?
    Here is the explain plan for that query
    Execution Plan
    Plan hash value: 3493649369
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 1 | 2015 | 1 (0)| 00:00:01 | | |
    |* 1 | VIEW | | 1 | 2015 | 1 (0)| 00:00:01 | | |
    |* 2 | COUNT STOPKEY | | | | | | | |
    | 3 | PARTITION RANGE SINGLE | | 1 | 5894 | 1 (0)| 00:00:01 | 99 | 99 |
    | 4 | PARTITION LIST ALL | | 1 | 5894 | 1 (0)| 00:00:01 | 1 | 48 |
    |* 5 | TABLE ACCESS BY LOCAL INDEX ROWID| CDR | 1 | 5894 | 1 (0)| 00:00:01 | 4705 | 4752 |
    | 6 | BITMAP CONVERSION TO ROWIDS | | | | | | | |
    |* 7 | BITMAP INDEX SINGLE VALUE | IX_CDR_INTERFACE | | | | | 4705 | 4752 |
    Predicate Information (identified by operation id):
    1 - filter("RAW_RNUM_">0)
    2 - filter(ROWNUM<=10000)
    5 - filter("DAY_OF_YEAR"=99 AND "TIME_STAMP">=TO_DATE('2009-04-08 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND
    "TIME_STAMP"<=TO_DATE('2009-04-09 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND ("NETWORK_ID"=1025 OR
    "NETWORK_ID"=1026))
    7 - access("INTERFACE"='TRAFIC')
    can one explain why it happen? what could be the reason? Is it a bug or something? what should I do now? Issue is critical in the production enviromentent
    Waiting for your Valuable Reply
    Thanks In Advance
    With Regards
    Boo

    user454189 wrote:
    I suspect the issue with the where clause (raw_rnum_ > 0)
    Actually I using bitmap index on ' INTERFACE' column. Does it causing a prob or raw_rnum_ causing a problem?Boo,
    a couple of comments:
    1. Why do you use the deprecated FIRST_ROWS hint? From 9i on the FIRST_ROWS_n mode should be used instead, and since you're using a top-N query format the hint should be superfluous anyway since the optimizer should switch to FIRST_ROWS_n mode automatically.
    2. Why do you use a BITMAP index and not a conventional b*tree index? Let me hazard a guess: Because the INTERFACE column has a small number of distinct values? That would be in most cases a bad idea.
    3. What seems to be odd that you're accessing the data via the BITMAP index on INTERFACE, but request an ORDER BY ID DESC. But there is no order by in the execution plan posted. I wonder where the order should come from? Can you show us the DDL of the bitmap index?
    4. What does the plan look like if you run only the inner query without the outer query?
    You can always gain more information by tracing the statement execution or using the GATHER_PLAN_STATISTICS hint together with the DBMS_XPLAN.DISPLAY_CURSOR function.
    Please read this HOW TO: Post a SQL statement tuning request - template posting that explains what you should provide if you have SQL statement tuning question and how to format it here so that the posted information is readable by others.
    This accompanying blog post shows step-by-step instructions how to obtain that information.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Select Query Problem

    Hi Experts,
    I am having a select query in which I am using a variable in the where condition but it is giving error. Please suggest how to use variable in the select query.
    The query I am using is a s below.
    select * from zexc_rec into table it_ZEXC_REC
          where
           LIFNR in S_LIFNR and
          DOCNO in S_DOCNO and
          DOCTYP in doc_typ and
          DATE1 in S_DATE1 and
          MATNR in S_MATNR.
    Here doc_typ is a variable.
    Thanks.

    Rahul,
    use RANGES type variable instead of variable . It acts as a select-options variable. Thn use this variable in SELECT query with IN.
    Eg :
    RANGES r_t510 FOR t510-lgart.
        r_t510-low = '1600'. 
        APPEND r_t510.
        r_t510-low = '3190'. 
        APPEND r_t510.
    Note  : can be use SIGN, OPTIONS properties too in RANGES type.
    More deatils go through on HELP of RANGES
    Rgds,
    Ranjith

  • 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

  • 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>

  • Select query differences between oracle 9 and oracle 8.

    Hi,
    I have a problem using the select query between oracle 7 and oracle 9i I don't have the same result :
    ex:
    With oracle7
    SQL> select 'champ1','champ2' from DUAL;
    'CHAMP 'CHAMP
    champ1 champ2
    With Oracle 9
    SQL> select 'champ1','champ2' from DUAL;
    'CHAMP1' 'CHAMP2'
    champ1 champ2
    So Can someone tell me how to solve this problem ? Is there a parameter in oracle 9 to set?
    Thanx.

    Whenever you are posting anything over internet forums like this - you should be very careful about not just posting the details which requires to solve the problem - also should be sensible about your question.
    This is not at all desired when you are posting such question. It may be because - you may not well aware of the fact.
    My suggestion is -> First Go through the basics Of SQL in general.
    Then go for any specific product like Oracle/ SQL Server/ Sybase etc.
    And, finally learn the advanced commands of that DB.
    You asked it - may be you thought the difference in output in terms of lines. But, that is not your actual output. That is the graphical display part only.
    Anyway,
    You can get the quite familier output by first type the following command ->
    set lin 310Regards.
    Satyaki De.

  • Select Query resulting in Scientific Notation

    Hello all,
    I am running a Select query through a batch file that extracts data from an Oracle database. Several of the fields that I am extracting from contain numbers that are up to 38 digits long. When I extract the data, it converts the numbers into scientific notation and it is important for me to have the entire field. Is there something I can change to my query that will pull the data in its entire form? This is what I'm running now:
    select * FROM ML.APPT where APPTDATE >= to_date('01/1/2010','mm/dd/yyyy'
    I apologize in advance if this has been answered already.
    Thanks!

    >
    When the extractor finishes, it returns the data into a flat file.
    don't quite understand the TO_CHAR function. Does this function mean I need to say something like this: select "TO_CHAR('column name', 99999999999999999999999999999999999999" FROM ML.APPT where APPTDATE >= to_date('01/1/2010','mm/dd/yyyy')
    >
    Yes- if the tool you use to extract the data (your 'extractor') is converting the numeric data to a string then it is responsible for creating the string in the proper format. If the number is an integer that can have as many digits as you have '9's in your sample format string then that is what you need to do.
    Here is how sql*plus (Oracle's tool) will display the data using default settings
    SQL> select 12345678901234567890123456789012345678 no_format,
      2  to_char(12345678901234567890123456789012345678, '99999999999999999999999999
    999999999999') with_format
      3   from dual;
    NO_FORMAT WITH_FORMAT
    1.2346E+37  12345678901234567890123456789012345678
    SQL>
    ----- TOAD will display something similiar but the default uses more decimal digits in the scientific notation data
    NO_FORMAT,WITH_FORMAT
    1.23456789012346E37, 12345678901234567890123456789012345678You can either format the numeric data in the query using TO_CHAR or the 'extractor' can do it when it converts the data to a string.

Maybe you are looking for