Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: How to get the current/last run SQL statement into a string variable?

Re: How to get the current/last run SQL statement into a string variable?

From: Niall Litchfield <niall.litchfield_at_dial.pipex.com>
Date: Sat, 07 Apr 2007 17:30:32 +0100
Message-ID: <4617C728.6030404@dial.pipex.com>


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/services
Received on Sat Apr 07 2007 - 11:30:32 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US