6

We are seeing a lot of "ORA-00936: missing expression" errors in our application log. Is there a way in Oracle to determine what statement(s) are failing?

I tried querying v$sql, but these statements are not inserted into that view, since they don't pass the syntax checks.

Our C# application is using Linq to generate a query to an Oracle database. This makes it a bit difficult to get the sql query from the application. I was hoping I could just get it from Oracle easier.

4 Answers 4

7

You can create a trigger in Oracle that will log all errors (or pretty much all - NO_DATA_FOUND is not considered an error). In the example below, any error in the schema is recorded in the TRACK_DETAIL table (error in one row, failed SQL in the next). You can make it more sophisticated with a sequence number, date/time etc.

create table track_detail (val varchar2(4000));

create or replace procedure track (p_text IN VARCHAR2) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
begin
  insert into track_detail(val)
  values (p_text);
  commit;
end;
.
/
create or replace TRIGGER log_err after servererror on schema
DECLARE
  v_temp VARCHAR2(2000) := substr(dbms_utility.format_error_stack,1,2000);
  v_num NUMBER;
  v_sql_text ora_name_list_t;
begin
  v_temp := translate(v_temp,'''','"');
  track(v_temp);
  v_num  := ora_sql_txt(v_sql_text);
  v_temp := null;
  BEGIN
    FOR i IN 1..v_num LOOP
      v_temp := v_temp || v_sql_text(i);
    END LOOP;
  EXCEPTION
    WHEN VALUE_ERROR THEN NULL;
  END;
  v_temp := translate(v_temp,''''||chr(0)||chr(10),'"');
  track(v_temp);
end;
/

Remember to drop (or disable) the trigger when you have finished with it.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 I forgot about database-level triggers while writing my answer :(
Thats awesome. I had no idea you could create a trigger on "servererror"! Thanks!
Accepted this as the answer because it worked best for my situation. I could go in to a running DB, create the trigger, get the error, and remove the trigger without effecting users or redeploying app code. Thanks Gary!
2

If you can enable sql tracing from the application code somehow (alter session set sql_trace=true), the statements will show up in the trace files on the database host.

Comments

1

You could try using something like Wireshark on the port used to connect to Oracle to see what SQL statements are being sent. Might not be the best answer--but it might get you where you need to go quicker.

Comments

1

Try SQL monitoring solution from Kris Vandermotten blog.

Also you can redirect log with DataContext.Log property :

using (NorthwindDataContext context = new NorthwindDataContext())
{
  context.Log = Console.Out;
}

Or use any other debugging tools like LInQ to Entities Visualizer ...

1 Comment

I never realized that Log property was there. Thanks for that! Technically we are using a Linq expression against an Entity Framework ObjectContext, not a DataContext. This was also on a server were I don't have access to change the code, hence my wanting to grab the query from Oracle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.