dbms_xplan too
Dana Day, June 09, 2023 - 5:29 pm UTC
I do this a LOT. I use select * from table(dbms_xplan.display_cursor([sql_id]));
Works fine 99% of the time.
Also using AWR sql_id report can get you the full text with many other relevant pieces of information.
June 12, 2023 - 4:30 am UTC
Agreed.
(As long as the plan is still in v$sql_plan)
Follow-up question
Ravi S, June 10, 2023 - 5:32 pm UTC
Thanks Chris and also Dana for the comments.
My apology for not asking the question in details in the first place.
Our company has operation in multiple countries and developers execute SQL statements on the DB. When they run into issues, we've to tune their queries. However, developers are not allowed to send Queries in email due to security reasons (I know it sounds weird). Max they send SQL_ID or PLAN_HASH_VALUE. That's the reason for my original question, and I was looking for objects where I can get these SQL's.
Thanks again,
Ravi S
June 12, 2023 - 4:35 am UTC
v$sql or v$sqlstats is your best bet in that case.
If they've been aged out, then its time to look into the AWR historical tables if you're licensed for that.
Finding full SQL text
mathguy, June 11, 2023 - 5:54 pm UTC
OK, so it seems that your question has nothing (or very little) to do with EXPLAIN PLAN. Your user sends you an SQL_ID and you want to find the full text of that statement, so that you can run EXPLAIN PLAN on it. What you want to do with the full SQL text seems irrelevant; once the user sends you the SQL_ID and you can find the full text of the query, you can run EXPLAIN PLAN on it but that doesn't seem to matter.
Chris already answered that, perhaps just a bit indirectly. Query V$SQL, use the SQL_ID in the WHERE clause, and select SQL_FULLTEXT. If you are only seeing the first 1000 characters, this means that you selected SQL_TEXT, not SQL_FULLTEXT. Both are columns in V$SQL; the full text is a CLOB, while the (reduced) text is just the first 1000 characters, in VARCHAR2(1000) data type.
The same view has another column, HASH_VALUE, which you can use if that's what you get from your user.
June 12, 2023 - 4:36 am UTC
agreed