寫預存程序時遇到一個問題,執行dbms_output.putline(變數名)的時候,報錯
ORA-20000:ORU-10027:buffer overflow,limit of 2000 bytes.
$ oerr ora 20000
20000, 00000, "%s"
// *Cause: The stored procedure 'raise_application_error'
// was called which causes this error to be generated.
// *Action: Correct the problem as described in the error message or contact
// the application administrator or DBA for more information.
應該是變數大小超過了dbms_output.putline的最大值。
解決辦法1:
SQL>set serveroutput on size 1000000
##2014-07-18添加
解決辦法2:
在begin後面加上DBMS_OUTPUT.ENABLE(buffer_size => null) ,表示輸出buffer不受限制。
如下面的語句是為了擷取建立索引語句
set serveroutput on
declare
v_sql varchar2(1000);
v_result varchar2(2000);
begin
for cur_sql in (select 'select dbms_metadata.get_ddl(''INDEX'',''' ||
T.INDEX_NAME || ''',''XXXX'') FROM DUAL' as f_sql
from v$object_usage t
where t.monitoring = 'YES'
AND T.USED = 'NO') loop
begin
DBMS_OUTPUT.ENABLE(buffer_size => null); --表示輸出buffer不受限制
execute immediate cur_sql.f_sql
into v_result;
--DBMS_OUTPUT.PUT_LINE(cur_sql.f_sql);
DBMS_OUTPUT.PUT_LINE(v_result);
end;
end loop;
end;
/
原文連結:http://blog.chinaunix.net/uid-23284114-id-3868872.html