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

Trading and Mindset

                Especially in India, when we say about TRADING, the majority of people think about either risk or loss or both. The reason behind the risks are extremely untutored on charting techniques, ill-educated about the trading platform, witless goals on the outcome, cretinous decisions when trade, lack of knowledge about current affairs and market conditions and so on. General info on Trading. Trading means buying or selling goods, commodities, metals, oils, currencies, stock & futures, etc. In trading either you can be an individual trader and be a boss of your own (OR) you can learn the skills, develop your own strategies and join a company as a professional trader. Before entering into Trading Network, you need to set your mind with the below qualities: 1 - Being patient. 2 - Not being greedy. 3 - Self Educated (both fundamental and technical analysis). If you miss any of the above at any point ...
Charles Darwin's illness Charles Robert Darwin  (12 February 1809 – 19 April 1882) was an English naturalist who realised and presented compelling evidence that all species of life have evolved over time from common ancestors, through the process he called natural selection and now forms the basis of modern evolutionary theory. Darwin’s scientific discovery remains the foundation of biology, as it provides a unifying logical explanation for the diversity of life. For much of his adult life Charles Darwin's illness repeatedly affected him with an uncommon combination of symptoms, leaving him severely debilitated for long periods of time, incapable of normal life and intellectual production, staying in bed most of the time for months. Charles Darwin wrote that "Constant attacks....makes life an intolerable bother and stops all work". He consulted with more than 20 doctors, but with the medical science of the time the cause remained undiagnosed. He tried all ...

Cryonics Technology

Today, I am going to articulate an interesting topic. It is about Cryonics Technology. It is the first and foremost prominent technology that relates to AFTERLIFE! Does it sound weird? Cryonics is the low-temperature freezing, that would be -130 °C and storage of corpses!  Now, you might have a plethora of WH-Questions! Cryonics Technology comes into the picture only when the human being expires due to lung/liver/heart or any other organ failure or due to any diseases. This technology will keep the body and other organs as undamaged as possible by freezing them and circulating the blood throughout the vessels. So that, In future, If the dead person gets antidote or cure, then they will implement the fix and then the dead can come back to life AGAIN!  It is like " I am back " as Keanu Reeves says in the movie John Wick. Let's go a little deeper into this topic! This will be fascinating. James Bedford was an American Psychology professor whose body was first preserved aft...