PD建模在
PD菜单栏中,依次点击“Tools ->Excute Commands->Edit/Run Script
'开始
Option ExplicitDim mdl ' the current model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no Active Model"
End IfDim HaveExcel
Dim RQ
RQ = vbYes 'MsgBox("Is  Excel Installed on your machine ?", vbYesNo + vbInformation, "Confirmation")
If RQ = vbYes Then
HaveExcel = True
' Open & Create  Excel Document
Dim x1 '
Set x1 = CreateObject("Excel.Application")
x1.Workbooks.Open "D:\My Data\Project\Data\DIM\维表\MOD_NODE.xls" '指定 excel文档路径
x1.Workbooks(1).Worksheets("Sheet1").Activate '指定要打开的sheet名称
Else
HaveExcel = False
End Ifa x1, mdlsub a(x1, mdl)
dim rwIndex 
dim tableName
dim colname
dim table
dim col
dim counton error Resume Nextset table = mdl.Tables.CreateNew '创建一个 表实体
table.Name = "Sheet1" '指定 表名,如果在 Excel文档里有,也可以 .Cells(rwIndex, 3).Value 这样指定
table.Code = "Sheet1" '指定 表名
count = count + 1For rwIndex = 2 To 1000 '指定要遍历的 Excel行标 由于第1行是 表头, 从第2行开始
With x1.Workbooks(1).Worksheets("Sheet1")
If .Cells(rwIndex, 1).Value = "" Then
Exit For
End Ifset col = table.Columns.CreateNew '创建一列/字段
'MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, "列"
If .Cells(rwIndex, 1).Value = "" Then
col.Name = .Cells(rwIndex, 1).Value '指定列名
Else 
col.Name = .Cells(rwIndex, 1).Value
End If
'MsgBox col.Name, vbOK + vbInformation, "列"
col.Comment = .Cells(rwIndex, 1).Value '指定列说明
col.Code = .Cells(rwIndex, 2).Value '指定列名
col.DataType = .Cells(rwIndex, 3).Value '指定列数据类型
If .Cells(rwIndex, 4).Value = "否" Then
col.Mandatory = true '指定列是否可空 true 为不可空 
End If
If rwIndex = 2 Then
col.Primary = true '指定主键
End If
End With
Next
MsgBox "生成数据 表结构共计 " + CStr(count), vbOK + vbInformation, " 表"Exit Sub
End sub

解决方案 »

  1.   

    Option Explicit   
    Dim mdl ' the current model 
    Set mdl = ActiveModel 
    If (mdl Is Nothing) Then   
      MsgBox "There is no Active Model" 
    End If 
      
    Dim HaveExcel 
    Dim RQ  
    RQ = vbYes 'MsgBox("Is Excel Installed on your machine ?", vbYesNo + vbInformation, "Confirmation") 
    If RQ = vbYes Then  
       HaveExcel = True  
    ' Open & Create Excel Document 
     Dim x1 '  
      Set x1 = CreateObject("Excel.Application")
      x1.Workbooks.Open "d:\User_1.xlsx"             此处把目录名称,文件名称改一下
      x1.Workbooks(1).Worksheets("Sheet1").Activate 
    Else
       HaveExcel = False 
    End If 
      
    a x1, mdl 
      
    sub a(x1,mdl) 
    dim rwIndex 
    dim tableName 
    dim colname 
    dim table 
    dim col 
    dim count 
      
    'on error Resume Next 
    For rwIndex = 1 To 1000 step 1   
        With x1.Workbooks(1).Worksheets("Sheet1")
      'MsgBox "生成数据表结构共计1 ="+CStr(.Cells(2,2).Value ), vbOK + vbInformation, "表" 
       If .Cells(rwIndex, 1).Value = "" Then 
           Exit For 
       End If  
      If .Cells(rwIndex, 3).Value = "" Then 
        set table = mdl.Tables.CreateNew 
            table.Name = .Cells(rwIndex , 1).Value 
            table.Code = .Cells(rwIndex , 2).Value 
            count = count + 1  
       Else   
        colName = .Cells(rwIndex, 1).Value 
        set col = table.Columns.CreateNew  
       'MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, "列" 
        col.Name = .Cells(rwIndex, 1).Value 
        'MsgBox col.Name, vbOK + vbInformation, "列"
         col.Code = .Cells(rwIndex, 2).Value 
        col.Comment = .Cells(rwIndex,1).Value  
        col.DataType = .Cells(rwIndex, 3).Value 
       End If 
      End With 
    Next 
      
    MsgBox "生成数据表结构共计" + CStr(count), vbOK + vbInformation, "表" 
     
    Exit Sub 
    End sub
      

  2.   

      v_sdate := to_char(i_sdate,'yyyymmddhh24miss');
      v_sdate := to_char(i_sdate,'yyyyMMdd')||'000000';--格式yyyymmddhh24miss
      v_edate := to_char(i_edate,'yyyyMMdd')||'235959';--格式yyyymmddhh24miss,日期时分秒为'23:59:59'
      S_TIME  := to_char(i_sdate,'yyyymmdd');
      E_TIME  := to_char(i_edate,'yyyymmdd');  err_msg VARCHAR2(200); --错误信息
      v_sdate VARCHAR2(8);   --开始时间
      v_edate VARCHAR2(8);   --结束时间
      v_area  VARCHAR2(200); --区域信息
      
    begin
      v_sdate := to_char(i_sdate, 'yyyymmdd');
      v_edate := to_char(i_edate, 'yyyymmdd');
      
      IF (i_area IS NULL) THEN
          SELECT to_char(WMSYS.WM_CONCAT(area_id)) INTO v_area FROM tbl_area;
    --把查询到的数据放入v_area,以逗号分隔
        ELSE
          v_area := i_area;
        END IF; WHERE u.area_id IN (SELECT regexp_substr(v_area, '[^,]+', 1, LEVEL) FROM dual
                CONNECT BY LEVEL <= length(v_area) - length(REPLACE(v_area, ',', '')) + 1)LEFT JOIN t_mk_user_info_day rh
           ON ta.area_id = rh.area_id AND rh.statis_date = E_TIME --关联多个条件--保留二位小数,并对数据做处理
    to_char(round(sum(t.play_duration_h),2),'FM99999999990.00') as play_duration_h,   --访问时长(小时)
    with temp as
     (select count(t.user_state) as count_users, t.area_name, t.user_state --按照区域,用户状态统计用户
        from t_mk_user_info_day_cx t
       where t.statis_date = '20170119'
       group by t.user_state, t.area_name
       order by t.user_state, t.area_name)select t.count_users, t.area_name, t.user_state, t.row_number --按照区域,获取统计的最大用户数
      from (select t.*,
                   row_number() over(partition by t.area_name order by t.count_users desc) row_number
              from temp t) t
     where row_number = 1
      

  3.   

    --dba用户查看数据库用户情况
    select * from user$;
    ---------------------------------------------------
    --修改数据库用户名及密码
    UPDATE USER$ SET NAME='IPTV_BJOTT' WHERE USER#=83;--系统更改,此时可能会提示新用户不存在。
    ALTER SYSTEM CHECKPOINT;
    ALTER USER IPTV_BJOTT IDENTIFIED BY IPTV_BJOTT;--出现以上情况执行下面2条语句
    ALTER SYSTEM FLUSH SHARED_POOL;
    ALTER USER IPTV_BJOTT IDENTIFIED BY IPTV_BJOTT;--修改后的账号解锁
    ALTER USER IPTV_BJOTT ACCOUNT UNLOCK;
    --------------------------------------------------
    --新建用户
    create user iptvrpt identified by "iptvrpt";
    --新用户赋权限
    grant create session to iptvrpt;  
    grant create table to  iptvrpt;  
    grant create procedure to  iptvrpt; 
    grant create tablespace to  iptvrpt;  
    grant create view to  iptvrpt;
    grant create sequence to  iptvrpt;
    grant resource to iptvrpt;
    GRANT debug any procedure, debug connect session TO iptvrpt;
    --新用户指定表空间
    alter user iptvrpt default tablespace iptvrpt;
    grant unlimited tablespace to iptvrpt;--可设置密码不区分大小写
    alter system set sec_case_sensitive_logon=False;
    --command命令行窗口查看指令
    show parameter sec_case_sensitive_logon;--------------------------------------------------
    --表空间  
    --建立表空间(一般建N个存数据的表空间和一个索引空间):  
    create tablespace 表空间名  
    datafile ' 路径(要先建好路径)\***.dbf  ' size *M  
    tempfile ' 路径\***.dbf ' size *M  
    autoextend on  --自动增长  
    --还有一些定义大小的命令,看需要  
     default storage(  
     initial 100K,  
     next 100k,  
    ); 
    select file_name,tablespace_name from dba_data_files;
    --例子:创建表空间  
    create tablespace DEMOSPACE   
    datafile 'E:/oracle_tablespaces/DEMOSPACE_TBSPACE.dbf'   
    size 1500M   
    autoextend on next 5M maxsize 3000M;  
    --删除表空间  
    drop tablespace DEMOSPACE including contents and datafiles  imp userid="'sys/[email protected]:1521/ora11g as sysdba'" file=C:\Users\tabledata.dmp fromuser=IPTVRPT touser=iptvrpt ignore=y清除分区数据,不删除分区
    ALTER TABLE dim_service_perf_min TRUNCATE PARTITION(MIN201705210115);新增分区
    ALTER TABLE dim_service_perf_min ADD PARTITION MIN201705210000 VALUES LESS THAN (TO_DATE(' 2017-05-21 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'));关于Oracle数据库如何查询非当前用户名命名空间下的表不需要写ower直接from 表名
    eg:比如说IPTVRPTOWNER下面有REL_VOD_INFO表,创建同义词后就可以直接在IPTVRPT用户下查询REL_VOD_INFO而不需要加ower
    之前select * from IPTVRPTOWNER.rel_vod_info,
    grant create any synonym to iptvrpt;
    create synonym REL_VOD_INFO for IPTVRPTOWNER.REL_VOD_INFO;
    更改后select * from rel_vod_info
      

  4.   

    今天一个客户问到这样一个问题,说是一个普通用户,有create 的系统权限和select any table权限,数据库版本为8174。但是该用户可以看到public dblink的用户名和口令。询问可不可以将其加密?
    dblink的口令存储在link$视图里。如果普通用户被赋予select any table权限,而O7_DICTIONARY_ACCESSIBILITY参数设置为true。那么该用户将有权查询link$ view,从而得知口令。
    要让普通用户(非sysdba)不能够查到link$,可以将参数设置为false。
    grant resource to iptvrpt;
    grant create database link to iptvrpt;
    grant create public database link to iptvrpt ;Oracle数据库创建Database Link有两种方式,一种是通过菜单,一种是通过SQL。
    创建一个dblink,命名为dblink_name,从A数据库连到B数据库,B数据库的IP为192.168.1.73,端口为1521,实例名为oracle,登录名为tast,密码为test。
    菜单方式:
    打开plsql,点击【File】-【New】-【Database link】,打开如下图所示窗口
     
    填好各项信息后,点击【Apply】即可完成Database Link的创建。SQL方式
    -- Drop existing database link   
    drop public database link dblink_name;  
     
    -- Create database link   
    create public database link dblink_name  
    connect to SYSTEM  
    using '192.168.1.73:1521/oracle'; create database link IPTV_178_TO_REPORTDB
      connect to iptvrpt identifid by pwd
      using '192.168.0.1:1562/reportdb';
      

  5.   

    请问怎么把pd里面的模型数据导入到excel表里呢
      

  6.   


    如果是导出一个表,columns列右上角不是有个excel图标么。
    如果是导出一个库到excel,百度里面有代码可以直接使用。我给一个参考
      

  7.   

    打开 powerdesigner 使用ctrl + shift + x 运行代码'****************************************************************************** 
    '* File:     pdm2excel.txt 
    '* Title:    pdm export to excel 
    '* Purpose:  To export the tables and columns to Excel 
    '* Model:    Physical Data Model 
    '* Objects:  Table, Column, View 
    '* Author:   Chirs 
    '* Created:  2015-01-28 
    '* Version:  1.0 
    '****************************************************************************** 
    Option Explicit 
       Dim rowsNum 
       rowsNum = 0 
    '----------------------------------------------------------------------------- 
    ' Main function 
    '----------------------------------------------------------------------------- 
    ' Get the current active model 
    Dim Model 
    Set Model = ActiveModel 
    If (Model Is Nothing) Or (Not Model.IsKindOf(PdPDM.cls_Model)) Then 
      MsgBox "The current model is not an PDM model." 
    Else 
     ' Get the tables collection 
     '创建EXCEL APP 
     
     
    Dim beginrow
     Dim EXCEL, BOOK, SHEET
     Set EXCEL = CreateObject("Excel.Application")
     EXCEL.Visible = True
     Set BOOK = EXCEL.Workbooks.Add(-4167) '新建工作簿
     
     BOOK.Sheets(1).Name = "数据库表结构"
     Set SHEET = EXCEL.workbooks(1).sheets("数据库表结构")
     
     ShowProperties Model, SHEET
     EXCEL.visible = true 
     '设置列宽和自动换行 
     SHEET.Columns(1).ColumnWidth = 10   
     SHEET.Columns(2).ColumnWidth = 30   
     SHEET.Columns(3).ColumnWidth = 20   
     
     SHEET.Columns(1).WrapText =true 
     SHEET.Columns(2).WrapText =true 
     SHEET.Columns(3).WrapText =true 
     
    End If
     
    '----------------------------------------------------------------------------- 
    ' Show properties of tables 
    '----------------------------------------------------------------------------- 
    Sub ShowProperties(mdl, sheet) 
       ' Show tables of the current model/package 
       rowsNum=0 
       beginrow = rowsNum+1 
       ' For each table 
       output "begin" 
       Dim tab 
       For Each tab In mdl.tables 
          ShowTable tab,sheet 
       Next 
       if mdl.tables.count > 0 then 
            sheet.Range("A" & beginrow + 1 & ":A" & rowsNum).Rows.Group 
       end if 
       output "end" 
    End Sub
     
    '----------------------------------------------------------------------------- 
    ' 数据表查询 
    '-----------------------------------------------------------------------------
    Sub ShowTable(tab, sheet)   
       If IsObject(tab) Then 
         Dim rangFlag
          sheet.cells(1, 1) = "序号" 
          sheet.cells(1, 2) = "表名"
          sheet.cells(1, 3) = "实体名"
          '设置边框 
          sheet.Range(sheet.cells(1, 1),sheet.cells(1, 3)).Borders.LineStyle = "1"
          '设置背景颜色
          sheet.Range(sheet.cells(1, 1),sheet.cells(1, 3)).Interior.ColorIndex = "19"
     
          rowsNum = rowsNum + 1
          sheet.cells(rowsNum+1, 1) = rowsNum 
          sheet.cells(rowsNum+1, 2) = tab.code
          sheet.cells(rowsNum+1, 3) = tab.comment
          '设置边框
          sheet.Range(sheet.cells(rowsNum+1,1),sheet.cells(rowsNum+1,3)).Borders.LineStyle = "2"
     
          '增加Sheet
          BOOK.Sheets.Add , BOOK.Sheets(BOOK.Sheets.count)
          BOOK.Sheets(rowsNum+1).Name = tab.code 
     
          Dim shtn
          Set shtn = EXCEL.workbooks(1).sheets(tab.code)
          '设置列宽和换行
           shtn.Columns(1).ColumnWidth = 30   
           shtn.Columns(2).ColumnWidth = 20   
           shtn.Columns(3).ColumnWidth = 20
       shtn.Columns(4).ColumnWidth = 20
           shtn.Columns(5).ColumnWidth = 30   
           shtn.Columns(6).ColumnWidth = 20   
     
           shtn.Columns(1).WrapText =true 
           shtn.Columns(2).WrapText =true 
           shtn.Columns(3).WrapText =true
       shtn.Columns(4).WrapText =true
           shtn.Columns(5).WrapText =true 
           shtn.Columns(6).WrapText =true
     
           '设置列标题
           shtn.cells(1, 1) = "字段名" 
           shtn.cells(1, 2) = "字段类型"
           shtn.cells(1, 3) = "约束"
       shtn.cells(1, 4) = "字段中文名"
           shtn.cells(1, 5) = tab.code
           shtn.cells(1, 6) = tab.Name
           '设置边框 
           shtn.Range(shtn.cells(1, 1),shtn.cells(1, 3)).Borders.LineStyle = "1"
           shtn.Range(shtn.cells(1, 5),shtn.cells(1, 6)).Borders.LineStyle = "1"
           '设置背景颜色
           shtn.Range(shtn.cells(1, 1),shtn.cells(1, 3)).Interior.ColorIndex = "19"
           shtn.Range(shtn.cells(1, 5),shtn.cells(1, 6)).Interior.ColorIndex = "19"
     
          Dim col ' running column 
          Dim colsNum
          Dim rNum 
          colsNum = 0
          rNum = 0 
                for each col in tab.columns 
                  rNum = rNum + 1 
                  colsNum = colsNum + 1 
     
                shtn.cells(rNum+1, 1) = col.code
                shtn.cells(rNum+1, 2) = col.datatype
                shtn.cells(rNum+1, 3) = col.mandatory
    shtn.cells(rNum+1, 4) = col.comment  
                next 
                shtn.Range(shtn.cells(rNum-colsNum+2,1),shtn.cells(rNum+1,3)).Borders.LineStyle = "2"         
                rNum = rNum + 1 
     
                Output "FullDescription: "       + tab.Name
     
       End If   
    End Sub