Skip to main content

How to identify the SQL_ID of a statement


The SQL_ID of a statement can be found in an AWR or ASH report or by selecting it from the database data dictionary using the V$SQL view.

If the SQL can be identified with a particular identifiable string or by some kind of unique comment such as /* TARGET SQL */ then this will make it easier to locate.

For Example:
SELECT /* TARGET SQL */ * FROM dual;

SELECT sql_id, plan_hash_value, substr(sql_text,1,40) sql_text  
FROM  v$sql 
WHERE sql_text like 'SELECT /* TARGET SQL */%'

SQL_ID        PLAN_HASH_VALUE SQL_TEXT
------------- --------------- ----------------------------------------
0xzhrtn5gkpjs       272002086 SELECT /* TARGET SQL */ * FROM dual

The plan_hash_value is included here for convenience.
You can also find the SQL_ID in the V$SQL view using a substitution variable:
SELECT sql_id, plan_hash_value, SUBSTR(sql_text,1,40) Text
FROM v$sql
WHERE sql_text LIKE '%&An_Identifiable_String%';
If SQL is no longer available in v$sql, you can find it in the AWR history views: DBA_HIST_SQLTEXT and DBA_HIST_SQLSTAT :
SELECT
    s.sql_id,
    s.plan_hash_value,
    t.sql_text,
    s.snap_id
FROM
    dba_hist_sqlstat   s,
    dba_hist_sqltext   t
WHERE s.dbid = t.dbid
AND   s.sql_id = t.sql_id
AND   sql_text LIKE 'SELECT /* TARGET SQL */%'
ORDER BY
    s.sql_id
You can use the snap_id to determine when the SQL was executed along with other information from AWR.

Comments

Popular posts from this blog

TOP 10 VENOMOUS SNAKES IN THE WORLD

            It’s important to point out here that there’s a difference between   venomous snakes   and   poisonous snakes . Venomous here implies that something is capable of injecting someone or something with Venom, while poisonous implies that it is capable of harming you by merely touching or eating it.    Now let see the rating from 10th to 1st place -  10. Rattle Snake         The Rattle Snake is a sub-family of the pit vipers, it has a very unique tail that makes it easy to be identified. At the end of it’s tail is located the rattle which makes so much noise when shaken, that’s where the name “rattle snake” comes from. Large number of it can be found in America particularly at the south, western part of United States and Mexico. One Striking feature of rattle snake that they possessed from the pit vipers families is that they have two organs that...
Alexander Graham Bell, the teacher of the deaf and his deaf wife Alexander Graham Bell. Alexander Graham Bell  (3 March 1847 – 2 August 1922) was an eminent scientist, inventor and innovator who is widely credited with inventing the first practical telephone. Bell was deeply affected by his mother's gradual deafness, (she began to lose her hearing when he was 12) and learned a manual finger language so he could sit at her side and tap out silently the conversations swirling around the family parlour. He also developed a technique of speaking in clear, modulated tones directly into his mother's forehead wherein she would hear him with reasonable clarity. Bell's preoccupation with his mother's deafness led him to study Acoustics (study of all mechanical waves in gases, liquids, and solids including vibration, sound, ultrasound and infrasound). Alexander Graham Bell, his wife Mabel Gardiner Hubbard, and their daughters Elsie (left) an...

ORA-30013: undo tablespace 'UNDOTBS1' is currently in use

ORA-30013 is the error reported when the specified Undo tablespace is in use. In other words, this implies there are some background processes still using the undo tablespace.   This error can be reported in both space management or transaction management.   Error ORA-30013 reported while dropping the Undo tablespace.   In this case, the Undo tablespace is used by other active transactions, leading to the error. In such cases, we have to wait until the transactions are committed or rolled back before dropping the Undo tablespace. This situation is similar to that of the ORA-1548 case. Error ORA-30013 reported while bringing up the database.   This happens for RAC databases while the undo tablespace mentioned for an instance is already in use. The solution will be to set separate Undo tablespace for all instances.   Since undo_tablespace is an instance local parameter, we have to ensure that the "Alter system set undo_tablespace" is being invo...