奇怪的ORA-06502:PL / SQL:数字或值错误

时间:2011-12-15 19:35:40

标签: sql oracle

我循环遍历数据库中的表定义并提取DDL,以便能够为软件测试目的创建表“重复”的“黄金数据”集。我有以下代码,它提取DDL就好了一个表,它会抛出一个ORA-06502错误。问题是,我已经定义了DDL作为CLOB返回的变量,它应该足够大。这是代码:

    create or replace
procedure gettabledescription as 
  current_date_time  varchar2(32);
  sql_statement varchar2(200);
  ddl_return clob;
  new_ddl clob;
BEGIN
  DBMS_OUTPUT.ENABLE;
  current_date_time:= to_char(sysdate,'MM/DD/YYYY - HH24:MI:SS');
  dbms_output.put_line(current_date_time);
  for cursor_rec in (select * from user_objects where object_type='TABLE' and object_name not like 'TM%' and object_name not like 'TZ_%' and object_name not like 'EXT_%' and object_name not like 'RPT_%' and object_name not like 'ETL_%') loop
    sql_statement := 'select dbms_metadata.get_ddl(''TABLE'',' || '''' || cursor_rec.object_name || '''' || ') from dual';
    execute immediate sql_statement into ddl_return;
    **error thrown here** new_ddl := replace(ddl_return,TO_CHAR(cursor_rec.object_name),'QA_' || TO_CHAR(cursor_rec.object_name));
    dbms_output.put_line(new_ddl);
   end loop;
END GETTABLEDESCRIPTION;

我不明白为什么我会收到这个错误。

1 个答案:

答案 0 :(得分:5)

在Oracle 10gR2上,当我使用长度超过8191字节的varchar2或clob调用DBMS_OUTPUT.PUT_LINE时,收到ORA-06502错误。解决方案是循环遍历clob,拉出行并为每个行调用put_line。