Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to find out Sql_id and Sql_text for last executed Query

2646086Sep 11 2014 — edited Sep 12 2014

Hi,

We need to capture Sql_id and Sql_text for last executed Query.

For example;

1. I have executed below query:

1.1 select * from hz_cust_accounts;

2. Now when i am trying to get above query's sql_id and sql_text using below queries then it does return the self query text.

2.1 select SID from V$mystat where rownum<=1;

2.2

SELECT

     S.USERNAME, S.SID, S.SERIAL#, SQL_TEXT,t.sql_id

FROM

  V$SESSION S,

  V$SQLTEXT_WITH_NEWLINES T

WHERE S.SQL_ID IS NOT NULL

AND S.SQL_ID = T.SQL_ID

and s.sid =SID

Above query is showing values of query executed in the step 2.2 however we need to see the sql_id of query executed at step 1.1.

Please help.

Thanks,

Kapil Pandey

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 10 2014
Added on Sep 11 2014
4 comments
7,611 views