Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Script for reverse eng of table
Hi,
This script for reverse eng of tables works on 7.3 .........not on
8.0 or above .....
HTH. shreepad
(See attached file: ddltab.sql)
v_table_name VARCHAR2(30) ; v_sqlfhandle UTL_FILE.FILE_TYPE ;
v_filedir VARCHAR2(70) := '/hildb1/dbdump4/ghi100' ; v_sqlfname VARCHAR2(70);
v_owner dba_tables.owner%type; v_tablename dba_tables.table_name%type; v_tablespacename dba_tables.tablespace_name%type; v_inittrans dba_tables.ini_trans%type; v_maxtrans dba_tables.max_trans%type; v_pctfree dba_tables.pct_free%type; v_pctused dba_tables.pct_used%type; v_pctinc dba_tables.pct_increase%type; v_initial dba_tables.initial_extent%type; v_next dba_tables.next_extent%type; v_min dba_tables.min_extents%type; v_max dba_tables.max_extents%type; v_tab dba_tab_columns.table_name%type; v_col dba_tab_columns.column_name%type; v_type varchar2(2000) ; v_len dba_tab_columns.default_length%type; v_col1 dba_tab_columns.column_name%type; v_type1 dba_tab_columns.data_type%type; v_precision dba_tab_columns.data_precision%type; v_scale dba_tab_columns.data_scale%type; v_datadef long ; v_sync varchar2(2000); v_sync1 varchar2(2000) ; v_sync2 varchar2(2000) ; v_def dba_tab_columns.default_length%type ; v_cid dba_tab_columns.column_id%type ; v_cid1 dba_tab_columns.column_id%type ; v_null varchar2(30);
cursor c2(v_tablename varchar2,v_owner varchar2) is
select column_name,
decode(data_type,'LONG',' LONG ',
'RAW',' RAW ' || '(' || data_length || ')' , 'LONG RAW','LONG RAW' , 'DATE' , ' DATE ' , 'CHAR' , ' CHAR' || '(' || data_length || ')', 'VARCHAR2', ' VARCHAR2' || '(' || data_length || ')' , 'NUMBER' , ' NUMBER ' ) datatyp, decode(nvl(data_precision,0),' ' , '(' || data_precision ),decode(nvl(data_scale,0), ')' , ',' || data_scale || ')' ), decode(nullable,'N','NOT NULL',' ') ,
cursor c3 (v_tablename varchar2,v_owner varchar2) is select max(column_id) from dba_tab_columns where owner=v_owner and table_name=v_tablename;
begin
open c1;
loop
v_sync:=' ' ;
v_sync1:=' ' ;
fetch c1 into v_owner,v_tablename,v_tablespacename,v_inittrans,
v_maxtrans,v_pctfree,v_pctused,v_pctinc,v_initial,v_next,v_min,v_max;
exit when c1%notfound;
v_sqlfname:=v_tablename || '_tab'|| '.sql' ;
v_sqlfhandle := UTL_FILE.FOPEN(v_filedir, v_sqlfname, 'w');
v_sync:='create table ' || v_owner|| '.'||v_tablename || '(' ;
UTL_FILE.PUTF(v_sqlfhandle, '%s\n',
'------ This script has been created by Shree -------------');
UTL_FILE.PUTF(v_sqlfhandle, '%s\n',
'
fetch c3 into v_cid; loop
exit when c2%notfound;
v_sync:=' ' ;
if v_cid=c2%rowcount
then
if v_len=0 then v_sync:=v_col || v_type || v_precision || v_scale ; else v_sync:=v_col || v_type || v_precision || v_scale || ' default ' || v_datadef ; end if; else if v_len=0 then v_sync:=v_col || v_type || v_precision || v_scale || ' ,' ; else v_sync:=v_col || v_type || v_precision || v_scale || ' default ' || v_datadef || ' , ' ; end if;
end loop; close c2; close c3;
' INITIAL ' || v_initial || ' NEXT ' || v_next || ' MINEXTENTS '|| v_min ||
'-------------------------- End of Script---------------------------------');UTL_FILE.FFLUSH(v_sqlfhandle);
Received on Tue Jul 03 2001 - 07:14:32 CDT
![]() |
![]() |