Yes it is very much possible. It is a new feature in SQL*Plus
. Read SQL*Plus error logging – New feature release 11.1 to know more about the feature in depth.
NOTE : SQL*Plus error logging is set OFF by default. So, you need to “set errorlogging on” to use the SPERRORLOG table.
The SPERRORLOG table looks like this:
SQL> desc sperrorlog;
Name Null? Type
----------------------------------------- -------- ----------------------------
USERNAME VARCHAR2(256)
TIMESTAMP TIMESTAMP(6)
SCRIPT VARCHAR2(1024)
IDENTIFIER VARCHAR2(256)
MESSAGE CLOB
STATEMENT CLOB
For example,
SQL> set errorlogging on
SQL>
SQL> SELECT * FROM dula;
SELECT * FROM dula
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
SQL> SELECT USERNAME, TIMESTAMP, MESSAGE, STATEMENT FROM sperrorlog;
USERNAME TIMESTAMP MESSAGE STATEMENT
---------- ------------------------------ -------------------------------------------------- ------------------
LALIT 10-MAR-15 04.08.13.000000 PM ORA-00942: table or view does not exist SELECT * FROM dula
SQL>
So, the statement which had an error is now logged in the SPERRORLOG table.
EDIT
My database has many kinds of clients and sometimes they use a wrong SQL string. but those clients were written in different languages such as C++, C, Java, .Net
The above mentioned solution is only applicable for the scripts executed via SQL*Plus. If the queries are executed through the application client, then to find the complete information you could trace the entire session that the application is using to interact with the database.
You could have a look at this article for an example on how to generate a trace file.