Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve sql text of cursor?

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.).

like image 746
McArthey Avatar asked Mar 28 '13 16:03

McArthey


People also ask

Which method is used to retrieve the SQL query results from the cursor object?

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.

Which statement is used to retrieve the row from the cursor?

FETCH statement to retrieve rows from the result table of the cursor.

What does fetch do in 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.


1 Answers

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

like image 130
Sathyajith Bhat Avatar answered Oct 05 '22 04:10

Sathyajith Bhat