If I have a cursor and would like to log the text of the cursor during execution is it possible to use the cursor name in some way and retrieve the SQL?
For example,
OPEN cursor_1 for
SELECT ...
I'd like to believe I can do something like cursor_1%NAME
much like I can use the other attributes of a cursor. (%ISOPEN, %FOUND, etc.).
An overview of the SQL cursor @@FETCH_STATUS function. SQL cursor is one of the most popular database objects. It is used to retrieve data from the result set of an SQL query one row at a time.
FETCH statement to retrieve rows from the result table of the cursor.
The FETCH statement advances the cursor to the first or next row in the set, and loads the values indicated in the SELECT clause of the DECLARE CURSOR statement into host language variables.
AFAIK, there's no way of linking a cursor name to it's SQL text being parsed, but joining V$open_cursor
with v$sql
using SQL_ID
, you should be able to pull out & log the details of the SQL statement being logged for those cursors which are open.
SELECT sql_id,
user_name,
sid,
saddrsql_fulltext
FROM v$sql
join v$open_cursor USING (sql_id)
Perhaps you could correlate the SQL text with cursor, but that's going to have to be a manual process
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With