oracle表转换mysql建表语句
生活随笔
收集整理的這篇文章主要介紹了
oracle表转换mysql建表语句
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
先上代碼:
select --t1.table_name,case when t1.COLUMN_ID <> 1 then ' ,'||lower(t1.COLUMN_NAME)||' ' else 'create table ' || t1.table_name || ' ( ' ||lower(t1.COLUMN_NAME)||' ' end||casewhen t1.DATA_TYPE like '%VARCHAR%' then 'VARCHAR'when t1.DATA_TYPE like '%DATE%' then 'DATETIME'when t1.DATA_TYPE like '%NUMBER%' then 'INT'when t1.DATA_TYPE like '%TIMESTAMP%' then 'TIMESTAMP'else '無法識別的類型' end|| ' ( '||t1.data_length||' )'||'null comment '||''''||t2.comments||'''' || case when t1.COLUMN_ID=t3.COLUMN_ID then ')'||'comment' || ''''||t3.comments || ''' ;' end as txtfrom all_tab_columns t1left join all_col_comments t2on t1.owner = t2.ownerand t1.table_name = t2.table_nameand t1.column_name = t2.column_nameleft join (select max(COLUMN_ID) COLUMN_ID ,a.owner, b.table_name,comments from all_tab_columns aleft join all_tab_comments b on a.owner = b.owner and a.table_name = b.table_namegroup by a.owner, b.table_name,comments )t3on t1.owner = t3.ownerand t1.table_name = t3.table_namewhere t1.table_name in ('TABLE_NAME1','TABLE_NAME2','TABLE_NAME3')and t1.owner = upper('db_name')order by t1.table_name,t1.column_id;解釋一下,這個sql主要是通過 all_tab_columns和all_col_comments兩個數據字典,獲取對應的表名、列表、類型、長度、注釋,轉換成mysqlDDL語句。
此代碼沒有進行主鍵判斷,因為在我的工作中已經夠用了,各位如果要轉換的表很多那就得關聯上user_constraints數據字典了
代碼復制下來就能用,把table_name,和db_name換成要轉換的表面和庫名就行。注意表名大小寫。
總結
以上是生活随笔為你收集整理的oracle表转换mysql建表语句的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2021年安徽普通高考考试成绩查询,安徽
- 下一篇: [java] 虚拟机(JVM)底