Find SQL Id of the Statement You Just Ran

While connected to the database, you might want to know the sql id of the query you just ran (in your own session, not some other session).

Let’s run a sample query

set serveroutput off
Select * from hr.employees;

Now you might want to know the SQL ID of the above command. You must query PREV_SQL_ID column from V$SESSION

select prev_sql_id from v$session where sid=sys_context('userenv','sid');

You can check if the sql id returned above is correct by checking the SQL TEXT associated with the sql id

select sql_id, sql_text from v$sqltext 
where sql_id in ('fxdbrc4jhqn5r');

Was this article helpful?

Related Articles


  1. Hi Arun,

    Thanks for your post.
    Can you please make one page how do we get SQL_TEXT by using SID & PID ?
    How do you get these values, and how these are related to the corresponding SQL Query ?
    Could you please make one page for these Questions

    Oracle Enthuse

  2. HI

    I have the execution plan for one sql statement with me when ever that sql runs it has to pick that execution plan

Leave a Comment