• Arun Kumar

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');


486 views

Recent Posts

See All

Generate Table DDL Command

The DBMS_METADATA package allows you to generate DDL commands for any of the database objects inside Oracle database. Generate Table DDL Command Generate View DDL Command Generate Materialized View DD

Reclaim Unused Space in Oracle

Over a period of time, updates and deletes on objects within a tablespace can create pockets of empty space that individually are not large enough to be reused for new data. This type of empty space i