In my previous article I have given ways to find out the Username for SQL query. I got question in my mind that many SQL developers will be facing issue to find the SQL_ID for SQL query step by step. There are multiple ways to find out the SQL_ID for SQL query in oracle. The most useful way is you require to execute some System views to get SQL_ID information. Before executing the System SQL views we require to know that if you can use these system views extensively it may cause the performance issue. You can use the following system views :
In this section I would like to give the steps to find SQL_ID for SQL Query with using V$SQLSTATS view. The V$SQLSTATS view is one of the most important view which is faster than V$SQL view so DBA’s recommends this view to find SQL_ID extensively.
Lets Say we require to find out the SQL_ID for following query :
Select * from Employees where employee id In ( 1,2,3,4,5);
You can directly use the following syntax to find the SQL Id :
Select SQL_ID from V$SQLSTATS Where SQL_TEXT = ‘SQL Query’;
Query :
Select SQL_ID from V$SQLSTATS Where SQL_TEXT = ‘Select * from Employees where employee id In ( 1,2,3,4,5)’;
Output :
SQL_ID
-------------
56rrstssrdsr1
The above query will give you the SQL_ID with simple steps.
You can also use V$SESSION view to find out the SQL_ID for executed SQL query. But by this statement you can only able to find out the SQL_ID for last executed SQL statement.
Lets say the following query is last executed query :
Select * from Employees where employee id In ( 1,2,3,4,5);
You can utilize the following query to find out the SQL_ID
Select Prev_SQL_ID from V$SESSION where SID=System_Context(‘Amit_DBA’,’SID’);
The above query will give you following output :
SQL_ID
-------------
56rrstssrdsr1
You can use the Set feedback command of oracle 18c. The SQL_ID parameter of set feedback command will easily give you the SQL_ID for sql or plsql executed.
Kindly execute following command on SQLPlus.
SET
FEEDBACK ON
SQL_ID
;
Then execute any query :
Select Count(*)from Employees;
Output will be :
12
SQL_ID: 9r8kgzntdn9sq
You can use V$SQLAREA view to find out the SQL_ID easily.
Query :
SELECT * FROM V$SQLAREA WHERE sql_text=’Select count(*) from Employees’;
These are multiple ways to find out SQL_ID for SQL query step by step. I hope you like this article. If you like this article or if you have issues with same kindly comment in comments section.
In my previous article I have given details about application support engineer day to day…
In my previous articles I have given the roles and responsibilities of L1,L2 and L3…
In my previous articles i have given the hierarchy of production support in real company…
In this article i would like to provide information about production support organization structure or…
In my previous article I have given roles for L1 and L2 support engineer with…
I have started this new series of how to become application support engineer. This article…