Powerdesigner表名及字段的大小写转换脚本

来源:互联网 发布:天谕女光刃捏脸数据 编辑:程序博客网 时间:2024/05/22 08:13
用PowerDesigner设计表结构时,若一不小心在写表结构和字段的时候用了大小写混合或者小写。PowerDesigner则在生成SQL时会自动在表名上使用双引号。例如:
/*==============================================================*/
/* Table: "test"                                                */
/*==============================================================*/
create table "test"  (
   "username"           varchar2(24),
   "full_name"          varchar2(24)
);
ORACLE会认为该表和字段使用小写字母命名,但是ORACLE默认是使用大写字母的,这样会导致有些用法用不了(比如修改字段名,数据修改等)。下面提供段脚本代码可以把PowerDesigner中的小写字母变为大写字母。
 
使用方法:进入PowerDesigner,打开需要转换的PDM,在菜单栏找到:Tools – Excute Commands – Edit/Run Script,或者直接按Ctrl+Shift+X调出脚本执行窗口,输入下边的代码就可以了。

代码如下:
Option Explicit 
ValidationMode = True 
InteractiveMode = im_Batch 
Dim mdl ' 当前模型 
' 获取当前模型 
Set mdl = ActiveModel 
If (mdl Is Nothing) Then 
   MsgBox "没有打开一个模型"
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then 
   MsgBox "当前模型不是一个PDM"
Else 
'调用处理程序 
   ProcessFolder mdl 
End If   
'调用的处理程序 
Private sub ProcessFolder(folder) 
   Dim Tab '要处理的表 
   for each Tab in folder.Tables 
    ' if not Tab.isShortcut then 
        ' Tab.code = tab.name 
        '表名处理,前边添加前缀,字母小写 
        Tab.name=  UCase(Tab.name) 
        Tab.code= UCase(Tab.code) 
         Dim col ' 要处理的列 
         for each col in Tab.columns 
            '列名称和code全部小写,大写诗UCase 
            col.code= UCase(col.code) 
            col.name= UCase(col.name) 
         next 
      'end if
   next   
' 处理视图 
'  Dim view 'running view 
'   for each view in folder.Views 
   '   if not view.isShortcut then 
       '  view.code = view.name 
    '  end if
  ' next    
   ' 递归进入 sub-packages 
   Dim f ' sub  folder 
   For Each f In folder.Packages 
      if not f.IsShortcut then 
         ProcessFolder f 
      end if
   Next 
end sub 
0 0
原创粉丝点击