写了一个从oracle表生成mysql 建表语句的过程如下。
有些部分是定制化需求,需要根据实际使用场景微调。
create or replace procedure p_wjf_ora_to_mysql(i_tablename in varchar2,
i_tab_owner in varchar2) as
--declare
----datatype cursor
cursor c_v1 is
select a.COLUMN_NAME,
a.DATA_TYPE,
a.DATA_LENGTH,
a.NULLABLE,
a.DATA_DEFAULT,
a.DATA_PRECISION,
a.DATA_SCALE,
a.COLUMN_ID
from dba_tab_columns a
where table_name = upper(i_tablename)
and owner = upper(i_tab_owner)
order by COLUMN_ID;
v_row c_v1%rowtype;
-----index cursor
cursor c_v2 is
select a.INDEX_NAME, b.CONSTRAINT_TYPE, a.owner
from dba_indexes a, DBA_CONSTRAINTS b
where a.TABLE_OWNER = upper(i_tab_owner)
and a.TABLE_NAME = upper(i_tablename)
and a.index_name = b.INDEX_NAME(+)
and a.owner = b.INDEX_OWNER(+);
v_row_ind c_v2%r