If you need to get SQL_ID of a query from a busy system, which has similar queries scattered all around, it becomes a hassle to get what you are looking for. If the query for which you are getting SQL_ID is big, or contains lots of apostrophes or other not-so-nice characters, then it becomes more cumbersome. The most simple way to get SQL_ID of query is to add comment in the query text and then get the SQL_ID from v$SQL view on the basis of that comment. Here is a working example: select /* MYCOMMENT */ name,age,salary from user.mytable where age > 78 order by name; COL SQL_TEXT format a45 select /* MYCOMMENT1 */ sql_id, substr(sql_text,1,200) sql_text from v$sql where upper(sql_text) like '%MYCOMMENT%' and sql_text not like '%/* MYCOMMENT1 */%' ; Enjoy query fishing :)
Share this
Previous story
← Silent Installation of RAC 12c database
You May Also Like
These Related Stories
Migrating to Microsoft SQL Server or Azure SQL Database
![](https://www.pythian.com/hubfs/Imported_Blog_Media/Oracle-Migration-Webinar.jpg)
Migrating to Microsoft SQL Server or Azure SQL Database
Jul 15, 2020
1
min read
Be Warned: cmclean.sql Is Dangerous!
Be Warned: cmclean.sql Is Dangerous!
Jul 18, 2013
5
min read
Introduction to Azure SQL Managed Instance – SQL on the edge episode 17
![](https://www.pythian.com/hubfs/Imported_Blog_Media/Warner-SQL-on-the-Edge-3.png)
Introduction to Azure SQL Managed Instance – SQL on the edge episode 17
Aug 7, 2018
4
min read
No Comments Yet
Let us know what you think