0

我在 Oracle DB 中面临以下异常。

java.lang.RuntimeException: java.lang.RuntimeException: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [call SRS_ADMIN.SLI_UTIL.copyData(?,?)]; nested exception is java.sql.SQLException: ORA-06502: PL/SQL: numeric or value error: character string buffer too small

我想让命令知道 DBMS_OUTPUT 的大小。

4

1 回答 1

2

您得到的 ORA-06502 错误与dbms_output. 当您有一个varchar2变量并且您尝试将一个太长的值放入其中时,您会得到这个。

例如,将 11 个字符的值放入 10 个字符的变量中:

declare
  var varchar2(10);
begin
  var := 'abcdefghikl';
end;
/

ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 4

您需要获取完整的错误堆栈;从 SQL*Plus 或 SQL Developer 调用具有相同值的过程将为您提供更多信息,并查明过程中发生错误的行。

如果你在缓冲区中放了太多东西dbms_output,你会得到一个不同的错误:

set serveroutput on size 2000
begin
  for i in 1..40 loop
    dbms_output.put('12345678901234567890123456789012345678901234567890');
  end loop;
  dbms_output.put_line('X');
end;
/

ORA-20000: ORU-10027: buffer overflow, limit of 2000 bytes

据我所知,无法查看当前缓冲区大小;文档没有显示任何内容,如果它是包变量,那么如果没有 getter 函数dbms_output您将无法看到它。


如果您从中得到例外:

inout_error_msg := v_msg || '; errorcode--> ' || v_err;

...然后调用者传递给过程的变量太小:

declare
  msg varchar2(10);
begin
  copyData(msg);
end;
/

ORA-06502: PL/SQL: numeric or value error: character string buffer too small

增加传递变量的大小可以解决这个问题:

declare
  msg varchar2(200);
begin
  copyData(msg);
end;
/

anonymous block completed

显然,您必须决定变量的大小;它需要足够大以应对任何可能的反应。SQLERRM最多可以有512 个字符,所以你需要考虑到这一点,加上错误代码,加上你的固定文本,所以……呃……至少 536?为了允许将来进行更改,您可能应该将其变大,这样您就不必回来修改调用者。

于 2014-04-29T15:45:48.450 回答