1

I am using Oracle/MyBatis and trying to debug a stored procedure with an enormous amount of parameters. Inside the stored procedure I get a ORA-01438: value larger than specified precision allowed for this column

So my initial approach would be to do like dbms_output.put_line in the stored procedure to try to see what the values are right before the offending statement. Without MyBatis, I would ordinarily open up a sqlplus script and type set serveroutput on and then run my stored procedure at some later point to see all the debug messages come out. With MyBatis, I cannot figure out how (if possible) to get these debug statements.

I have the ibatis and sql debuggers set for DEBUG and I use log4j to log everything for my Tomcat 6 application.

1 Answer 1

3

The DBMS_OUTPUT package has a few other procedures that you could use. DBMS_OUTPUT.ENABLE functions much like the SQL*Plus command set serveroutput on in that it allocates a buffer for DBMS_OUTPUT.PUT_LINE to write to. DBMS_OUTPUT.GET_LINE can be used to fetch the data written to that buffer by previous calls to DBMS_OUTPUT.PUT_LINE. So it should be possible to call the ENABLE function, call the procedure which writes a number of lines to the buffer, and then call GET_LINE (or GET_LINES) to fetch the data that was written to the DBMS_OUTPUT buffer and write that data to your logs.

It may be simpler, however, to redirect the logging to an Oracle database table rather than trying to use DBMS_OUTPUT. One common approach is to create your own package that has a switch to determine whether to write to DBMS_OUTPUT or whether to write to a table. Something like

CREATE OR REPLACE PACKAGE p
AS
  procedure l( p_str IN VARCHAR2 );
END;

CREATE OR REPLACE PACKAGE BODY p
AS
  g_destination INTEGER;
  g_destination_table    CONSTANT INTEGER := 1;
  g_destination_dbms_out CONSTANT INTEGER := 2;  

  PROCEDURE l( p_str IN VARCHAR2 )
  AS 
  BEGIN
    IF( g_destination = g_destination_dbms_out )
    THEN
      dbms_output.put_line( p_str );
    ELSE
      INSERT INTO log_table ...
    END IF;
  END;

  BEGIN
    g_destination := <<determine which constant to set it to.  This
                       may involve querying a `SETTINGS` table, looking
                       at the environment, or something else>>
  END;
END;
Sign up to request clarification or add additional context in comments.

2 Comments

Yeah I guess I really have to go with the second approach you mention, the switch. Probably not worth the extra effort worrying about how to get it to Tomcat logs.
For the record, here's how to fetch DBMS_OUTPUT.GET_LINES content from JDBC (and thus from MyBatis)

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.