您的位置:首页 > 数据库 > Oracle

Power Designer 逆向工程 oracle 表名、字段名添加注释

2015-03-27 19:06 405 查看

第一步:修改导出SQL

打开Power Designer ,选择 Database->Edit Current DBMS...打开对话框,找到Script->Objects->Table->SqlListQuery,打开后修改value中的sql语句,修改结果如下:

{OWNER, TABLE, TABLE_TYPE, COMMENTS}
select
t.owner,
t.table_name,
c.table_type,
c.comments
from
sys.all_all_tables t,
sys.USER_TAB_COMMENTS c
where
not exists (select 1 from sys.all_mviews s where s.owner = t.owner and t.table_name in (s.mview_name, s.update_log))
and t.iot_name is null
and nvl(t.dropped, 'NO') = 'NO'
and t.table_name = c.table_name(+)
[  and t.table_name=%.q:TABLE%]
[  and t.owner=%.q:SCHEMA%]
order by
t.owner, t.table_name


修改后点击应用,确定。

该部分解决思路参考自: http://blog.csdn.net/xinyuxiaoxiao5460/article/details/7599154 感谢该文章作者。

第二步:开始逆向工程导出表信息

File->Reverse Engineer -> Database... 打开对话框,选择oracle版本,选择Share the DBMS definition (如下图),点击确定,进入下一步:



选择数据源,如下图:



如果没有数据源,则点击后面的数据库图标按钮,创建数据源。此处不再赘述。选择数据源后,点击options标签,选择File encoding(文件编码方式),因为要支持中文,我选择的UTF-8。



点击确定按钮,进入选择表的窗口。选择你要导出的表,没什么特别的话就全选就行了。



然后点击OK按钮,等待导出完成。导出完成后,你可以看到表名的注释和表字段的注释都导出来了,但是name的位置还是显示的字母,不是注释。

第三步:用脚本将name设置成comments

在此操作之前,先设置code不跟随name改变。选择菜单中Tools->General Options...,在打开的窗口中找到Dialog,去掉Name to Code mirroring 前面的勾,点击OK。



选择菜单中Tools->Excute Commands -> Edit/Run Scripts... 在打开的窗口中粘贴如下脚本,点击Run按钮,等待执行完成即可。

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

Dim mdl 'the current model

'get the current active model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model"
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not an Physical Data model."
Else
ProcessFolder mdl
End If

'This routine copy name into code for each table, each column and each view
'of the current folder
Private sub ProcessFolder(folder)

Dim Tab 'running table
for each Tab in folder.tables
if not tab.isShortcut then
if len(tab.comment) <> 0 then
tab.name = tab.comment
end if
On Error Resume Next
Dim col 'running column
for each col in tab.columns
if len(col.comment) <>0 then
col.name =col.comment
end if
On Error Resume Next
next
end if
next
end sub


至此,逆向工程结束。

转载请注明文章来源:/article/10894490.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: