Reputation: 1933
I'm looping through the table definitions in a database and extracting the DDL in order to be able to create 'golden data' sets of table duplicates for software testing purposes. I've got the below code which extracts the DDL just fine up to one table where it throws a ORA-06502 error. The thing is, I've defined the variable that the DDL is being returned to as a CLOB, which should be big enough. Here's the code:
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;
I don't understand why I'm getting that error.
Upvotes: 2
Views: 2799
Reputation: 18410
On Oracle 10gR2, When I call DBMS_OUTPUT.PUT_LINE with a varchar2 or clob longer than 8191 bytes, I receive an ORA-06502 error. The solution would be to loop through the clob, pulling out lines and calling put_line once for each.
Upvotes: 5