Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: How to get the current/last run SQL statement into a string variable?
JB wrote:
> Hi All,
>
> I'd like to know how I can retrieve the current (or last run) SQL
> statement into a string variable.
> I'm trying to get this so in case of an error I can log the SQL
> statement that caused the error.
> Is there some sort of system variable that would contains it like
> SQLERRM contains the last Error?
>
> Thanks
> JB
>
> Simplified Code sample
>
> BEGIN
> INSERT INTO T1 (ID, NAME)
> VALUES ( 1, 'TEST');
>
> EXCEPTION
> WHEN OTHERS THEN
> sError := SQLERRM;
>
> -- How do I get the SQL statement that cause the error into a String
> variable?
> sSqlStatement := ?????
> END;
>
You can certainly use event triggers for this sort of thing, the context of your post though suggests that log4plsql http://www.oracle.com/technology/pub/articles/moulard_log4plsql.html might be just the thing.
-- Niall Litchfield Oracle DBA http://www.orawin.info/servicesReceived on Sat Apr 07 2007 - 11:30:32 CDT
![]() |
![]() |