Pro* C code to fetch cursor and loop. [message #431613] |
Wed, 18 November 2009 09:21 |
varun_p_n
Messages: 4 Registered: November 2009 Location: India
|
Junior Member |
|
|
i HAVE THE FOLLOWING CODE WRITTEN IN A *.pc FILE. I am trying to loop to fetch data from cursor. But the code exist after it fetches the first record. Let me know what is it the right way to fetch data from cursor ?
EXEC SQL BEGIN DECLARE SECTION;
char str[64];
EXEC SQL END DECLARE SECTION;
/*cursor declarations*/
EXEC SQL DECLARE Get_SQLText_Cursor CURSOR FOR
SELECT SQL_TEXT FROM v$SQLTEXT_WITH_NEWLINES WHERE address = ( SELECT prev_sql_addr FROM v$session WHERE audsid = userenv('SESSIONID'))ORDER BY piece;
/* open the cursor*/
EXEC SQL OPEN Get_SQLText_Cursor;
NextSelect = TRUE;
NumSelects = 0;
while(NextSelect)
{
EXEC SQL WHENEVER NOT FOUND GOTO NOTFND;
EXEC SQL FETCH Get_SQLText_Cursor
INTO :str;
strcat (sqlText,str);
NOTFND: NextSelect=FALSE;
}
EXEC SQL CLOSE Get_SQLText_Cursor;
if ( sqlca.sqlcode != ORA_OK )
{
return FALSE;
}
|
|
|
|
|
|
Re: Pro* C code to fetch cursor and loop. [message #431630 is a reply to message #431629] |
Wed, 18 November 2009 11:17 |
varun_p_n
Messages: 4 Registered: November 2009 Location: India
|
Junior Member |
|
|
bool Function(char * sqlText)
{
EXEC SQL BEGIN DECLARE SECTION;
char str[64];
EXEC SQL END DECLARE SECTION;
/*cursor declarations*/
EXEC SQL DECLARE Get_SQLText_Cursor CURSOR FOR
SELECT SQL_TEXT FROM v$SQLTEXT_WITH_NEWLINES WHERE address = ( SELECT prev_sql_addr FROM v$session WHERE audsid = userenv('SESSIONID'))ORDER BY piece;
/* open the cursor*/
EXEC SQL OPEN Get_SQLText_Cursor;
if (sqlca.sqlcode != ORA_OK)
{
return FALSE;
}
while(1)
{
EXEC SQL WHENEVER NOT FOUND GOTO NOTFND;
EXEC SQL FETCH Get_SQLText_Cursor
INTO :str;
strcat (sqlText,str);
NOTFND: break;
}
EXEC SQL CLOSE Get_SQLText_Cursor;
if ( sqlca.sqlcode != ORA_OK )
{
return FALSE;
}
return TRUE;
}
In the above code the while loop does not work properly. Exists the loop in the first iteration.
the code EXEC SQL WHENEVER NOT FOUND GOTO NOTFND;
doesnot work. which i thought is a standard Pro* C code to exit the loop after the data is fetched from cursor.
[Updated on: Wed, 18 November 2009 11:18] Report message to a moderator
|
|
|
|
Re: Pro* C code to fetch cursor and loop. [message #431706 is a reply to message #431634] |
Thu, 19 November 2009 03:55 |
varun_p_n
Messages: 4 Registered: November 2009 Location: India
|
Junior Member |
|
|
I have started using the forums recently. This is my first post in the oracle forum. Will make sure to read the oracle forum guidelines and then post it accordingly. Any way i have worked around this issue, got it solved.
Thanks Michel for your replies.
Regards,
Varun.
|
|
|