PD建模在
PD選單欄中,依次點擊“Tools ->Excute Commands->Edit/Run Script
'開始
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:\My Data\Project\Data\DIM\維表\MOD_NODE.xls" '指定 excel檔案路徑
x1.Workbooks(1).Worksheets("Sheet1").Activate '指定要打開的sheet名稱
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
set table = mdl.Tables.CreateNew '創建一個 表物體
table.Name = "Sheet1" '指定 表名,如果在 Excel檔案里有,也可以 .Cells(rwIndex, 3).Value 這樣指定
table.Code = "Sheet1" '指定 表名
count = count + 1
For rwIndex = 2 To 1000 '指定要遍歷的 Excel行標 由于第1行是 表頭, 從第2行開始
With x1.Workbooks(1).Worksheets("Sheet1")
If .Cells(rwIndex, 1).Value = "" Then
Exit For
End If
set 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
uj5u.com熱心網友回復:
Option ExplicitDim 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
uj5u.com熱心網友回復:
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
uj5u.com熱心網友回復:
--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
uj5u.com熱心網友回復:
今天一個客戶問到這樣一個問題,說是一個普通用戶,有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';
uj5u.com熱心網友回復:
請問怎么把pd里面的模型資料匯入到excel表里呢uj5u.com熱心網友回復:
如果是匯出一個表,columns列右上角不是有個excel圖示么。
如果是匯出一個庫到excel,百度里面有代碼可以直接使用。我給一個參考
uj5u.com熱心網友回復:
打開 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/29810.html
標籤:開發
上一篇:oracle安裝出現這個怎么解決
