- 简介
- 环境依赖
- 快速上手
- 配置文件
- 命令介绍
- mtk
- init-project
- config
- license
- mig
- show
- sync
- sync-schema
- sync-sequence
- sync-object-type
- sync-domain
- sync-wrapper
- sync-server
- sync-user-mapping
- sync-queue
- sync-table
- sync-nickname
- sync-rule
- sync-table-data
- sync-table-data-estimate
- sync-index
- sync-constraint
- sync-db-link
- sync-view
- sync-mview
- sync-function
- sync-procedure
- sync-package
- sync-trigger
- sync-synonym
- sync-table-data-com
- sync-alter-sequence
- sync-coll-statistics
- check-table-data
- gen
- gen completion
- encrypt
- convert-plsql
- report
- self
- mvd
- usql
- 图形化
- 常见问题
- Release
使用MTK迁移Oracle到openGauss/MogDB
支持版本
- 10.2+
- 11.2+
- 12c+
How to
-
下载安装MTK
tar -zxvf mtk_<version>_linux_<platform>.tar.gz
-
申请授权
cd mtk_<version>_linux_<platform> ./mtk license gen License File Not Found (default license.json) The License code is invalid, start applying ? Email: xxxx@xxxx.com -- 填写邮箱信息 >> please enter a valid email address # 复制邮箱里的文件`license.json`到此目录
-
安装Oracle驱动. 参考Oracle
-
Oracle创建迁移用户
sqlplus as sysdba create user mtk_mig identified by "password"; grant connect,resource to mtk_mig; grant select any dictionary to mtk_mig; grant select any table to mtk_mig; grant select_catalog_role to mtk_mig;
-
MogDB 创建数据库和用户
gsql create database db DBCOMPATIBILITY='A' ENCODING='UTF8' LC_COLLATE='C' LC_CTYPE='C'; \c db create user mtk_mig with password "mtkMigAbc123" sysadmin;
注意字符集排序规则. 创建数据库语法参考create database
-
初始化项目
./mtk init-project -s oracle -t mogdb -n ora2mg tree -f ora2mg/ ora2mg ├── ora2mg/config │ └── ora2mg/config/mtk.json ├── ora2mg/data ├── ora2mg/report └── ora2mg/schema
编辑配置文件. 具体查看MTK配置说明章
vi ora2mg/config/mtk.json
-
编辑
source
节点,定义源数据库连接信息. 配置参考source -
编辑
target
节点,定义目标数据库连接信息. 配置参考target修改connect和type信息,parameter根据运行在进行调整
-
编辑
object
节点,定义迁移对象. 配置参考object
编辑完成后,运行config-check检查配置文件是否正确
./mtk config-check -c ora2mg/config/mtk.json
配置文件配置正常会输出类型信息
use config : ora2mg/config/mtk.json There is no error in the configuration file
-
-
迁移
步骤 描述 命令 ./mtk mig-tab-pre -c ora2mg/config/mtk.json 迁移表 mig-tab-pre ./mtk mig-tab-data -c ora2mg/config/mtk.json 迁移表数据 mig-tab-data ./mtk mig-tab-post -c ora2mg/config/mtk.json 迁移索引约束 mig-tab-post ./mtk mig-tab-other -c ora2mg/config/mtk.json 迁移存储过程PLSQL相关 mig-tab-other -
查看报告
报告和运行日志会生成在
ora2og/report
目录下. 如下[2022-01-20 11:29:25.800978] INFO reportDir: ora2mg/report/report_20220120110125 function=GenReport line=412 file=mtk/cmd/mtk/services/cmd.go [2022-01-20 11:29:26.426822] INFO the text report : ora2mg/report/report_20220120110125.txt function=PrintReport line=270 file=mtk/cmd/mtk/services/cmd.go [2022-01-20 11:29:26.429545] INFO the warring report : ora2mg/report/report_20220120110125.warring function=PrintReport line=281 file=mtk/cmd/mtk/services/cmd.go [2022-01-20 11:29:26.430118] INFO the error report : ora2mg/report/report_20220120110125.err file=mtk/cmd/mtk/services/cmd.go function=PrintReport line=292
文件名 说明 ora2mg/report/report_20220120110125 html报告 ora2mg/report/report_20220120110125.txt 文本报告 ora2mg/report/report_20220120110125.warring 只包含警告信息的文本报告 ora2mg/report/report_20220120110125.err 只包含错误信息的文本报告
Performance
MTK 使用 Golang 进行开发. 连接Oracle的驱动有以下选择.
驱动名称 | 描述 |
---|---|
godror | cgo 需要Oracle客户端 |
go-oci8 | cgo 需要Oracle客户端 |
ora | cgo 需要Oracle客户端 |
go-ora | Pure go 不需要Oracle客户端 |
CGO类型的驱动性能低于Go原生语言驱动,是因为架构限制,如godror驱动调用路径为 Godror Driver->CGO Libraries->ODPI-C->OCI
. 一般性能瓶颈在CGO Libraries
efficient-fetching-of-data-from-oracle-database-in-golang Drivers based on CGO have a complex architecture, they wrap around an existing library which may also be another wrapper or technology. If we take a look at the Godror Golang driver, we’ll see that it’s a 4-level architecture driver:
MTK 新增参数 pureDriver
支持使用 go-ora
驱动. 在启用此参数后MTK会自动判断在查询数据库表数据时是否使用 go-ora
驱动. 存在以下情况不会使用
- 表存在XML列类型
- 表存在Spatial类型
- 表存在UDT类型
在使用go-ora
时Number
类型的数据会存在异常数据情况,MTK内部进行TO_CHAR(COL_NAME) AS COL_NAME
进行查询
{
"source": {
"type": "oracle",
"connect": {
"version": "",
"host": "127.0.0.1",
"user": "system",
"port": 1521,
"password": "oracle",
"dbName": "mtk",
"dsn": "",
"charset": "ZHS16GBK",
"pureDriver": true
},
"parameter": {
"debugTest": false
}
}
}
Oracle迁移用户权限
迁移用户必须能访问DBA_*
/ALL_*
视图和查询迁移表权限.
- connect
- select any dictionary
- select any table
- select_catalog_role
MTK 从 2.3.0 以后访问
DBA_*
视图,不在查询ALL_*
视图.
MTK Type 和oracle type 对应
对应 DBA_OBJECT
里的 OBJECT_TYPE
MTK | Oracle |
---|---|
Schema | User |
ObjectType | TYPE/TYPE BODY |
Domain | |
CustomType | |
Sequence | SEQUENCE/Large Sequence |
Queue | |
Table | TABLE |
Constraint | |
Index | INDEX |
View | VIEW |
Trigger | TRIGGER |
Procedure | PROCEDURE |
Function | FUNCTION |
Package | PACKAGE/PACKAGE BODY |
Synonym | Synonym |
DBLink | |
Rule |
注意事项
空字符串和NULL问题
Oracle 里 ''
= NULL
和 openGauss A兼容模式一致, 和PG
兼容模式 ''
! = NULL
不一样.
DBCOMPATIBILITY [ = ] compatibility_type
指定兼容的数据库的类型。取值范围: A、B、C、PG。分别表示兼容Oracle、MySQL、Teradata和PostgreSQL。但是C目前已经放弃支持。因此常用的取值是A、B、PG。
说明:
- A兼容性下,数据库将空字符串作为NULL处理,数据类型DATE会被替换为TIMESTAMP(0) WITHOUT TIME ZONE。
- 将字符串转换成整数类型时,如果输入不合法,B兼容性会将输入转换为0,而其它兼容性则会报错。
- PG兼容性下,CHAR和VARCHAR以字符为计数单位,其它兼容性以字节为计数单位。例如,对于UTF-8字符集,CHAR(3)在PG兼容性下能存放3个中文字符,而在其它兼容性下只能存放1个中文字符。
序列
MogDB/openGauss 3.0.0
largeSequence
配置为on大于9223372036854775807迁移为Large SequencelargeSequence
配置为on小于9223372036854775807迁移为SequencelargeSequence
配置为off迁移为Sequence
MogDB/openGauss 3.0.0 之前如果值大于9223372036854775807会有警告信息。
MTK 取 Oracle 序列值通过 DBA_SEQUENCES.LAST_NUMBER+CACHE_SIZE. 如不满足要求请参考取序列最后值
Type
-
CREATE OR REPLACE TYPE TY_STR_SPLIT IS TABLE OF VARCHAR2 (4000)
MogDB/openGauss 3.0.0 Support
MTK v2.4.2 Support
表
-
IOT_OVERFLOW 不支持
-
NESTED TABLE 不支持
-
OBJECT TYPE TABLE
MogDB/openGauss 3.0.0 Support
MTK v2.4.2 Support
CREATE OR REPLACE TYPE address_obj as OBJECT( street VARCHAR2(20), city VARCHAR2(20), state CHAR(2), zip CHAR(5)); / CREATE TABLE address_table OF ADDRESS_OBJ;
-
分区表
- Hash Partition Table
- List Partition Table
- Range Partition Table
- Sub Partition Table
- System Partition table
- interval Partition openGauss语法限制部分支持
-
Convert interval(NUMTOYMINTERVAL(1,'year')) --> interval(1 year)
Oracle openGauss NUMTOYMINTERVAL(1,'YEAR') 1 year NUMTOYMINTERVAL ( 1, 'MONTH' ) 1 MONTH numtodsinterval ( 1, 'day' ) 1 day -
number interval -- invalid input syntax for type interval
-
-
物化视图的表不迁移,迁移物化视图
Char 字段类型
如果存在字符集转换,需要注意Char类型字段数据.
- Oracle
SQL> create table tab_char(id number, col_char char(2));
Table created.
SQL> insert into tab_char values (1,'1');
1 row created.
SQL> select id,'"'||col_char||'"' ,col_char from tab_char;
ID '"' C
---------- --- -
1 "1 " 1
- openGauss/MogDB
由于从GBK字符集迁移到UTF8,字段长度会变大
MogDB=#create table tab_char(id bigint, col_char char(2));
CREATE TABLE
MogDB=#insert into tab_char values (1,'1');
INSERT 0 1
MogDB=#select id,concat('"',col_char,'"') ,col_char from tab_char;
id | concat | col_char
----+--------+----------
1 | "1 " | 1 >> 多了个空格
(1 row)
列
列类型转换
Oracle | openGauss |
---|---|
SMALLINT(number(*,0)) | bigint |
INTEGER(number(*,0)) | bigint |
NUMBER(8,5) | numeric(8,5) |
NUMBER(*,5) | numeric(38,5) |
NUMBER(38,127) | numeric(127) |
NUMBER(38,-64) | numeric(102) |
NUMBER | numeric |
DECIMAL(8,5) | numeric(8,5) |
NUMERIC(8,5) | numeric(8,5) |
REAL(float(64)) | numeric |
FLOAT(20) | numeric |
BINARY_FLOAT | numeric |
BINARY_DOUBLE | numeric |
CHAR(8) | character(8) |
NCHAR(8) | character(8) |
VARCHAR(8) | character varying(8) |
VARCHAR2(8) | character varying(8) |
NVARCHAR2(8) | character varying(8) |
DATE | timestamp(0) without time zone |
TIMESTAMP | timestamp without time zone |
TIMESTAMP WITH LOCAL TIME ZONE | timestamp with time zone |
TIMESTAMP WITH TIME ZONE | TIMESTAMP WITH TIME ZONE |
INTERVAL YEAR TO MONTH | interval |
ITERVAL DAY TO SECOND | interval |
LONG | text |
RAW(111) | RAW(111) |
LONG RAW | bytea |
CLOB | text/CLOB |
BLOB | bytea/BLOB |
NCLOB | text/CLOB |
BFILE | Not Support |
User-Defined Types | Not Support |
Any Types | Not Support |
URI Data Types | Not Support |
URIFactory Package | Not Support |
SDO_GEOMETRY | Partially Supported See : Spatial |
ST_GEOMETRY | Partially Supported See : Spatial |
SDO_TOPO_GEOMETRY | Not Support |
SDO_GEORASTER | Not Support |
列默认值
-
sys_guid
SQL> SELECT sys_guid() FROM dual; SYS_GUID() -------------------------------- B2CBE5EE3AB4032BE053030011AC6BD3
CREATE or replace FUNCTION pg_catalog.sys_guid() RETURNS varchar AS $$ BEGIN RETURN md5(random()::text || clock_timestamp()::text); END; $$ LANGUAGE plpgsql;
-
TO_CHAR(SYSTIMESTAMP, 'TZR') from dual;
Number
-
number(38,127) --> numeric(127, 127)
当 p < s的时候,使用numeric(s, s)。此时,Oracle可以控制小数点后0的个数
create table o_test3(value number(38,127)); INSERT INTO o_test3 VALUES (00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012345678901234567890123456890123456789012345678901234567890123456789); SELECT * FROM o_test3;
-
number(38,-64) --> numeric(102)
create table o_test4(value number(38,-64)); INSERT INTO o_test4 VALUES(12345678901234567890123456789012345678901234567890123456789012345678900000000000000000000000000000000); INSERT INTO o_test4 VALUES(123456789012345678901234567890123456789012345678901234567890123456789000000000000000000000000000000000); INSERT INTO o_test4 VALUES(123456789012345678901234567890123456789012345678901234567890123456789000000000000000000000000000000001); SELECT * FROM o_test4;
Timestamp
- Timestamp
- Oracle Timestamp 精度最大为9, openGauss/mogdb
- Timestamp with local time zone Oracle 会转换插入时间为数据库时区时间. openGauss/mogdb 使用 Timestamp local time zone
- Timestamp local time zone Oracle 不转换时区. openGauss/mogdb 暂时不支持. openGauss/mogdb 使用 Timestamp local time zone 会丢失原有客户端时区信息
列名
openGauss数据库系统列:
- "CMAX"
- "CMIN"
- "CTID"
- "TABLEOID"
- "TID"
- "XMAX"
- "XMIN"
以上列名用户不能进行列名定义.
约束
- Oracle主键约束和表名一致,在openGauss会报错。程序自动后名称后面增加_PK。
- C - Check constraint on a table
- P - Primary key
- U - Unique key
- R - Referential integrity
- V - With check option, on a view -- 不支持
- O - With read only, on a view -- 不支持
- H - Hash expression
- F - Constraint that involves a REF column
- S - Supplemental logging -- 不支持
约束使用索引前导列
- Oracle
create index idx_test_01 on test_01(id,col1,col2);
alter table test_01 add constraint pk_test_01 primary key (id) using index idx_test_01;
- MogDB
-- mtk 正常转换
create unique index idx_test_01 on test_01(id,col1,col2);
alter table test_01 add constraint pk_test_01 primary key using index idx_test_01;
-- 以上结果是错误的
-- 正常
create unique index idx_test_01 on test_01(id,col1,col2);
create unique index idx_pk_test_01 on test_01(id);
alter table test_01 add constraint pk_test_01 primary key using index idx_pk_test_01;
-- 会比原库多一个唯一索引
索引
- bitmap索引不支持
视图
-
Select语句部分列别名问题
select name name from dual -- rewrite name as name
-
Oracle TRANSLATE(xx USING NCHAR_CS) 函数
select TRANSLATE(col1 USING NCHAR_CS) from ( select 1 as col1 from dual; )
同义词
不迁移DBLink下的同义词
SELECT OWNER,SYNONYM_NAME,TABLE_OWNER,TABLE_NAME FROM DBA_SYNONYMS WHERE DB_LINK IS NULL;
Spatial
迁移 Oracle Spatial 以下参数可用
迁移 Oracle Spatial 数据会查询pg_extension判断数据库是否安装postgis
- postgis安装则迁移为geometry
- postgis未安装则迁移为text
支持情况如下:
- SDO_GTYPE
- [2,3,4]0[0-7] Support
- [2,3,4]0[8-9] No Support
- SDO_ETYPE
- 1, 2, 1003, 2003, 4,1005, 2005 Support
- [2006,1007]: Not Supprt
其他问题
ORA-29275: partial multibyte character
- AL32UTF8 TO UTF8
在
source
-parameter
下配置参数charAppendEmptyString 为 true - ZHS16GBK TO UTF8
-
方法一 在
source
-parameter
下配置参数charAppendEmptyString 为 true -
方法二 在
source
和target
下的connect
下配置参数clientCharset 为GBK
在
target
-parameter
下配置参数igErrorData 为 true
-
ORA-01805 msg:possible error in date/time operation
-
查询 timezone_file
-
query oracle database server timezone_file version
sqlplus "/ as sysdba" SQL> select * from v$timezone_file; FILENAME VERSION CON_ID -------------------- ---------- ---------- timezlrg_34.dat 34 0
-
query oracle client timezone_file version
genezi -v Client Shared Library 64-bit - 19.3.0.0.0 System name: Darwin Release: 19.6.0 Version: Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64 Machine: x86_64 TIMEZONE INFORMATION -------------------- Operating in Instant Client mode. Small timezone file = /opt/client_19/oracore/zoneinfo/timezone_32.dat Large timezone file = /opt/client_19/oracore/zoneinfo/timezlrg_32.dat
如果客户端版本和服务器端版本不一致,请升级timezone_file.
服务器端版 : timezlrg_34.dat
客户端版本 : timezlrg_32.dat
-
-
解决方案:
-
安装Oracle客户端。
-
升级timezone_file。具体查看Updated DST Transitions and New Time Zones in Oracle RDBMS and OJVM Time Zone File Patches (Doc ID 412160.1)
# for oracle Instant client # 设置环境变量ORA_TZFILE export ORA_TZFILE=timezlrg_34.dat # 从其他已安装补丁的机器复制过来. cp timezlrg_34.dat $ORACLE_HOME/oracore/zoneinfo/ genezi -v Client Shared Library 64-bit - 19.3.0.0.0 System name: Darwin Release: 19.6.0 Version: Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64 Machine: x86_64 TIMEZONE INFORMATION -------------------- Operating in Instant Client mode. Time zone file timezlrg_34.dat set in ORA_TZFILE environment variable will be used. Small timezone file = /opt/client_19/oracore/zoneinfo/timezlrg_34.dat Large timezone file = /opt/client_19/oracore/zoneinfo/timezlrg_34.dat
-
Segmentation Fault on some requests handling ROWID
https://github.com/oracle/python-cx_Oracle/issues/315
Try setting the environment variable ORA_OCI_NO_OPTIMIZED_FETCH to the value 1 before you run the query to avoid the issue
乱码问题
-
存储过程里中文乱码.
MTK报告里显示乱码. 基本出现在AL32UTF8的数据库里出现了非UTF8编码的数据. 如GBK编码
-- 使用Oracle Dump函数进行确定 -- 从DBA_SOURCE查询对应的SQL 文本 select line,text,dump(text,1016),dump(CONVERT(text, 'AL32UTF8'),1016) from dba_source where name='xxx'; /* -- 模拟故障 SELECT dump(CONVERT('请求系统响应', 'ZHS16GBK'),1016), -- 正常UTF8编码数据转为GBK dump(CONVERT(CONVERT('请求系统响应', 'ZHS16GBK'),'AL32UTF8','ZHS16GBK'),1016) -- 正常UTF8编码数据转为GBK在转为UTF8 FROM dual; */
-
invalid byte sequence for encoding
此问题一般为源数据库存在乱码. 可以配置参数igErrorData 为 true,先跳过错误数据,然后在处理错误数据.
找到报告里提示的错误数据文件. 参考如下操作
此CSV通过DBeaver/Mogeaver 会正常导入,因为进行转码操作
gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:29:12 commit 0 last mr release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. -- 使用CTAS创建临时表. 注意后面的表明修改为真实表明 omm=# create table copy_table as select * from XXX.TABLE where 1=0; INSERT 0 0 omm=# \COPY TABLE FROM 'xxx_table_0.csv' WITH csv header DELIMITER ',' encoding 'UTF8'; ERROR: invalid byte sequence for encoding "UTF8": 0xe7 0x31 0x31 CONTEXT: COPY TABLE, line 18750
根据报错信息找到有问题行的,去源数据库查询数据,发现乱码请尝试修复.
Oracle
select dump(col_name,1016) from table_name t WHERE t.col_name='xxx';
openGauss/MogDB/PostgreSQL
select upper(encode(col_name::bytea, 'hex')) from table_name t WHERE t.col_name='xxx'
迁移US7ASCII
Oracle Client NLS_LANG 和 数据库字符集设置为一样不会进行转编码操作. 所以中文汉字编码看客户端应用生成的编码
查看中文在数据库里的编码. 查询带中文数据的表. 如
SELECT col_name,dump(col_name,1016) FROM tab_ascii
COL2 DUMP_NAME
----- ------------------------------------------------------------------------------------------
中国人 Typ=1 Len=9 CharacterSet=US7ASCII: e4,b8,ad,e5,9b,bd,e4,ba,ba
打开网站查看汉字编码输入汉字查看编码.和数据库DUMP查询出来结果进行对比. 如上面的是UTF8编码
配置MTK配置文件里的clientCharset
.参考如下
{
"source": {
"type": "oracle",
"connect": {
"clientCharset": "ASCII",
}
},
"target": {
"type": "opengauss",
"connect": {
"clientCharset": "UTF8"
}
}
}
部分SQL语句
Sequence
11G
SELECT SEQUENCE_OWNER,SEQUENCE_NAME, MIN_VALUE, MAX_VALUE, INCREMENT_BY,
ORDER_FLAG,
CYCLE_FLAG,
CACHE_SIZE,
LAST_NUMBER,
LAST_NUMBER + CACHE_SIZE AS STARTVAL
FROM
DBA_SEQUENCES S
WHERE 1=1
12C+
SELECT SEQUENCE_OWNER,SEQUENCE_NAME, MIN_VALUE, MAX_VALUE, INCREMENT_BY,
ORDER_FLAG,
CYCLE_FLAG,
CACHE_SIZE,
LAST_NUMBER,
LAST_NUMBER + CACHE_SIZE AS STARTVAL
FROM
DBA_SEQUENCES S
WHERE
NOT EXISTS (
SELECT
1
FROM
DBA_TAB_IDENTITY_COLS C
WHERE
S.SEQUENCE_OWNER = C.OWNER
AND S.SEQUENCE_NAME = C.SEQUENCE_NAME ) AND SEQUENCE_OWNER='ORA_MTK'
取序列最后值
declare
v_sequence_owner varchar2(100) := 'ORA_MTK'; ---大小写无关
v_start_with number;
v_ddl varchar2(4000);
v_setval varchar2(4000);
begin
for x in (select sequence_owner,
sequence_name,
min_value,
max_value,
increment_by,
case when cache_size= 0 then 1 else cache_size end cache_size,
cycle_flag,
last_number --Oracle 最后值是最后一次cache值
from dba_sequences where sequence_owner = upper(v_sequence_owner)) loop
-- 通过xx.nextval查询可以保证在单节点下是最后值,无法保证在rac节点下是最后值. 因为是内存数据
execute immediate 'select ' || x.sequence_owner || '.' || x.sequence_name ||'.nextval from dual' into v_start_with;
-- v_ddl:= case when x.max_value>9223372036854775807 then 'create large sequence ' else 'create sequence ' end
-- || lower(x.sequence_owner) || '.' || lower(x.sequence_name) || ' minvalue ' || x.min_value || ' maxvalue '
-- || x.max_value || ' increment by ' || x.increment_by || ' start with ' || v_start_with || ' cache '
-- || x.cache_size || case when x.cycle_flag='N' then ' nocycle' else ' cycle' end ||';' ;
-- dbms_output.put_line(v_ddl);
v_setval :='SELECT setval('||''''||x.sequence_owner || '.' || x.sequence_name||''''||', '||v_start_with||');';
dbms_output.put_line(v_setval);
end loop;
end;
Type
SELECT
o.object_type,
s.owner,
s.name,
s.line,
s.text,
t.typecode,
o.timestamp,
h.lvl
FROM
DBA_SOURCE s,
DBA_TYPES t,
DBA_OBJECTS o,
(
SELECT
NAME,
MAX(LEVEL) lvl
FROM
(
SELECT
*
FROM
DBA_DEPENDENCIES
WHERE
TYPE = 'TYPE'
AND owner = 'ORA_MTK')
CONNECT BY
nocycle referenced_name = PRIOR name
GROUP BY
name) h
WHERE
s.type = 'TYPE'
AND o.object_type = 'TYPE'
AND s.owner = 'ORA_MTK'
AND h.name = s.name
AND s.owner = t.owner
AND s.name = t.type_name
AND s.owner = o.owner
AND s.name = o.object_name
AND o.status = 'VALID'
UNION ALL
SELECT
o.object_type,
s.owner,
s.name,
s.line,
s.text,
t.typecode,
o.timestamp,
h.lvl
FROM
DBA_SOURCE s,
DBA_TYPES t,
DBA_OBJECTS o,
(
SELECT
NAME,
MAX(LEVEL) lvl
FROM
(
SELECT
*
FROM
DBA_DEPENDENCIES
WHERE
TYPE = 'TYPE'
AND owner = 'ORA_MTK')
CONNECT BY
nocycle referenced_name = PRIOR name
GROUP BY
name) h
WHERE
s.type = 'TYPE BODY'
AND o.object_type = 'TYPE BODY'
AND s.owner = 'ORA_MTK'
AND h.name = s.name
AND s.owner = t.owner
AND s.name = t.type_name
AND s.owner = o.owner
AND s.name = o.object_name
AND o.status = 'VALID'
ORDER BY
lvl,
OWNER,
NAME,
object_type,
LINE
Queue
SELECT
Q.OWNER,
NAME,
QUEUE_TYPE,
Q.QUEUE_TABLE,
QT.OBJECT_TYPE
FROM
DBA_QUEUES Q,
DBA_QUEUE_TABLES QT
WHERE
Q.QUEUE_TABLE = QT.QUEUE_TABLE
AND Q.OWNER = QT.OWNER AND
Table
SELECT A.OWNER,A.TABLE_NAME,A.TABLESPACE_NAME,A.CLUSTER_NAME,A.IOT_NAME,A.LOGGING,A.PARTITIONED,A.IOT_TYPE,
A.TEMPORARY,
A.SECONDARY,
A.NESTED,
A.COMPRESSION,
A.COMPRESS_FOR,
B.COMMENTS,
A.DURATION ,
A.NUM_ROWS ,
A.BLOCKS,
A.AVG_ROW_LEN,
A.TABLE_TYPE,
A.TABLE_TYPE_OWNER
FROM
DBA_ALL_TABLES A,
DBA_OBJECTS O,
DBA_TAB_COMMENTS B
WHERE NOT EXISTS (SELECT 1 FROM DBA_SNAPSHOTS S WHERE S.OWNER = A.OWNER AND S.TABLE_NAME=A.TABLE_NAME)
AND A.OWNER=B.OWNER(+)
AND A.TABLE_NAME=B.TABLE_NAME(+)
AND A.OWNER=O.OWNER
AND A.TABLE_NAME=O.OBJECT_NAME
AND O.OBJECT_TYPE='TABLE'
Column
11G
SELECT
/*+ RULE */
C.OWNER,
C.TABLE_NAME,
C.COLUMN_NAME,
COLUMN_ID,
DATA_DEFAULT,
DATA_TYPE,
DATA_TYPE_OWNER,
DATA_LENGTH,
CHAR_LENGTH,
DATA_PRECISION,
DATA_SCALE,
CHAR_USED,
HIDDEN_COLUMN,
VIRTUAL_COLUMN,
NULLABLE,
NULL COMMENTS,
NULL AS IDENTITY_COLUMN
FROM
DBA_TAB_COLS C
WHERE 1=1 AND HIDDEN_COLUMN='NO' AND UPPER(C.OWNER) = 'ORA_MTK' AND (UPPER(C.TABLE_NAME) = 'T3' OR UPPER(C.TABLE_NAME) = 'T2') ORDER BY c.OWNER,c.TABLE_NAME,c.COLUMN_ID
12C
SELECT
/*+ RULE */
C.OWNER,
C.TABLE_NAME,
C.COLUMN_NAME,
COLUMN_ID,
DATA_DEFAULT,
DATA_TYPE,
DATA_TYPE_OWNER,
DATA_LENGTH,
CHAR_LENGTH,
DATA_PRECISION,
DATA_SCALE,
CHAR_USED,
HIDDEN_COLUMN,
VIRTUAL_COLUMN,
NULLABLE,
NULL COMMENTS,
C.IDENTITY_COLUMN -- 12.1
FROM
DBA_TAB_COLS C
WHERE 1=1 AND HIDDEN_COLUMN='NO' AND UPPER(C.OWNER) = 'ORA_MTK' AND (UPPER(C.TABLE_NAME) = 'T3' OR UPPER(C.TABLE_NAME) = 'T2') ORDER BY c.OWNER,c.TABLE_NAME,c.COLUMN_ID
Column Comment
SELECT c.owner, c.table_name, c.column_name, comments FROM DBA_COL_COMMENTS c WHERE c.comments IS NOT null
Column Identity
12C+
SELECT
C.OWNER,
C.TABLE_NAME,
C.COLUMN_NAME,
C.SEQUENCE_NAME,
C.GENERATION_TYPE,
S.MIN_VALUE,
S.MAX_VALUE,
S.INCREMENT_BY,
S.ORDER_FLAG,
S.CYCLE_FLAG,
S.CACHE_SIZE,
S.LAST_NUMBER,
S.LAST_NUMBER + S.CACHE_SIZE AS STARTVAL
FROM
DBA_TAB_IDENTITY_COLS C,
DBA_SEQUENCES S
WHERE
S.SEQUENCE_OWNER = C.OWNER
AND S.SEQUENCE_NAME = C.SEQUENCE_NAME
CONSTRAINT
Constraint Basic Info
SELECT C.OWNER,
C.CONSTRAINT_NAME,
C.CONSTRAINT_TYPE,
C.TABLE_NAME,
C.SEARCH_CONDITION,
C.R_OWNER,
C.R_CONSTRAINT_NAME,
C.DELETE_RULE,
C.STATUS,
C.DEFERRABLE,
C.DEFERRED,
C.VALIDATED,
C.INDEX_OWNER,
C.INDEX_NAME
FROM
DBA_CONSTRAINTS C
WHERE
1 = 1 AND UPPER(C.OWNER) = 'ORA_MTK' AND (UPPER(C.TABLE_NAME) = 'T3' OR UPPER(C.TABLE_NAME) = 'T2')
UNION ALL
SELECT
R.OWNER,
R.CONSTRAINT_NAME,
R.CONSTRAINT_TYPE,
R.TABLE_NAME,
NULL AS SEARCH_CONDITION,
R.R_OWNER,
R.R_CONSTRAINT_NAME,
R.DELETE_RULE,
R.STATUS,
R.DEFERRABLE,
R.DEFERRED,
R.VALIDATED,
R.INDEX_OWNER,
R.INDEX_NAME
FROM
DBA_CONSTRAINTS C
LEFT JOIN DBA_CONSTRAINTS R ON C.R_OWNER = R.OWNER AND C.R_CONSTRAINT_NAME = R.CONSTRAINT_NAME
WHERE
1 = 1
AND C.CONSTRAINT_TYPE='R'
AND UPPER(C.OWNER) = 'ORA_MTK' AND (UPPER(C.TABLE_NAME) = 'T3' OR UPPER(C.TABLE_NAME) = 'T2')
Constraint Column
SELECT
COLS.OWNER,
COLS.CONSTRAINT_NAME,
COLS.TABLE_NAME,
COLS.COLUMN_NAME,
COLS.POSITION ,
TC.NULLABLE
FROM
DBA_CONS_COLUMNS COLS ,
DBA_TAB_COLS TC
WHERE
COLS.TABLE_NAME = TC.TABLE_NAME
AND COLS.OWNER = TC.OWNER
AND COLS.COLUMN_NAME = TC.COLUMN_NAME
AND UPPER(COLS.OWNER) = 'ORA_MTK' AND (UPPER(COLS.TABLE_NAME) = 'T3' OR UPPER(COLS.TABLE_NAME) = 'T2')
UNION
SELECT DISTINCT COLS.OWNER,
COLS.CONSTRAINT_NAME,
COLS.TABLE_NAME,
COLS.COLUMN_NAME,
COLS.POSITION ,
TC.NULLABLE
FROM
DBA_CONSTRAINTS CONS,
DBA_CONSTRAINTS CONS_R,
DBA_CONS_COLUMNS COLS,
DBA_TAB_COLS TC
WHERE
1 = 1
AND CONS.R_OWNER = CONS_R.OWNER
AND CONS.R_CONSTRAINT_NAME = CONS_R.CONSTRAINT_NAME
AND CONS_R.TABLE_NAME = COLS.TABLE_NAME
AND CONS_R.CONSTRAINT_NAME = COLS.CONSTRAINT_NAME
AND CONS_R.OWNER = COLS.OWNER
AND CONS_R.TABLE_NAME = TC.TABLE_NAME
AND CONS_R.OWNER = TC.OWNER
AND COLS.OWNER = TC.OWNER
AND COLS.TABLE_NAME = TC.TABLE_NAME
AND COLS.COLUMN_NAME = TC.COLUMN_NAME
AND CONS.CONSTRAINT_TYPE ='R'
AND UPPER(COLS.OWNER) = 'ORA_MTK' AND (UPPER(COLS.TABLE_NAME) = 'T3' OR UPPER(COLS.TABLE_NAME) = 'T2')
ORDER BY OWNER,TABLE_NAME,CONSTRAINT_NAME,POSITION
Constraint Index
SELECT
S.INDEX_NAME,
S.TABLE_NAME,
S.UNIQUENESS,
S.INDEX_TYPE,
S.TABLE_OWNER,
S.PARTITIONED,
S.TABLESPACE_NAME,
Q.QUEUE_TABLE,
S.JOIN_INDEX
FROM
DBA_INDEXES S
LEFT OUTER JOIN DBA_QUEUE_TABLES Q ON
Q.QUEUE_TABLE = S.TABLE_NAME
AND Q.OWNER = S.TABLE_OWNER
WHERE EXISTS (
SELECT
AC.INDEX_NAME
FROM
DBA_CONSTRAINTS AC
WHERE
AC.CONSTRAINT_TYPE IN ('P', 'U')
AND AC.TABLE_NAME = S.TABLE_NAME
AND AC.OWNER = S.TABLE_OWNER
AND AC.INDEX_NAME = S.INDEX_NAME
)
AND S.TEMPORARY = 'N'
AND (FUNCIDX_STATUS IS NULL
OR FUNCIDX_STATUS != 'DISABLED')
AND UPPER(S.TABLE_OWNER) = 'ORA_MTK' AND UPPER(S.TABLE_NAME) = 'PROMOTIONS_VAR3'
Constraint Index Column
SELECT IC.INDEX_OWNER,IC.INDEX_NAME,IC.COLUMN_NAME,IE.COLUMN_EXPRESSION,IC.COLUMN_POSITION,IC.TABLE_NAME,IC.TABLE_OWNER,IC.DESCEND FROM DBA_IND_COLUMNS IC, DBA_IND_EXPRESSIONS IE WHERE IC.INDEX_OWNER = IE.INDEX_OWNER(+) AND IC.INDEX_NAME = IE.INDEX_NAME(+) AND IC.COLUMN_POSITION=IE.COLUMN_POSITION(+)
AND UPPER(IC.TABLE_OWNER) = 'ORA_MTK' AND UPPER(IC.TABLE_NAME) = 'PROMOTIONS_VAR3'
ORDER BY IC.TABLE_OWNER,IC.TABLE_NAME,IC.INDEX_NAME,IC.COLUMN_POSITION
Index Column
Index Basic Info
SELECT
S.INDEX_NAME,
S.TABLE_NAME,
S.UNIQUENESS,
S.INDEX_TYPE,
S.TABLE_OWNER,
S.PARTITIONED,
S.TABLESPACE_NAME,
Q.QUEUE_TABLE,
S.JOIN_INDEX
FROM
DBA_INDEXES S
LEFT OUTER JOIN DBA_QUEUE_TABLES Q ON
Q.QUEUE_TABLE = S.TABLE_NAME
AND Q.OWNER = S.TABLE_OWNER
WHERE NOT EXISTS (
SELECT
AC.INDEX_NAME
FROM
DBA_CONSTRAINTS AC
WHERE
AC.CONSTRAINT_TYPE IN ('P', 'U')
AND AC.TABLE_NAME = S.TABLE_NAME
AND AC.OWNER = S.TABLE_OWNER
AND AC.INDEX_NAME = S.INDEX_NAME
)
AND S.TEMPORARY = 'N'
AND (FUNCIDX_STATUS IS NULL
OR FUNCIDX_STATUS != 'DISABLED')
AND UPPER(S.TABLE_OWNER) = 'ORA_MTK' AND UPPER(S.TABLE_NAME) = 'PROMOTIONS_VAR3'
Index Column
SELECT IC.INDEX_OWNER,IC.INDEX_NAME,IC.COLUMN_NAME,IE.COLUMN_EXPRESSION,IC.COLUMN_POSITION,IC.TABLE_NAME,IC.TABLE_OWNER,IC.DESCEND FROM DBA_IND_COLUMNS IC, DBA_IND_EXPRESSIONS IE WHERE IC.INDEX_OWNER = IE.INDEX_OWNER(+) AND IC.INDEX_NAME = IE.INDEX_NAME(+) AND IC.COLUMN_POSITION=IE.COLUMN_POSITION(+)
AND UPPER(IC.TABLE_OWNER) = 'ORA_MTK' AND UPPER(IC.TABLE_NAME) = 'PROMOTIONS_VAR3'
ORDER BY IC.TABLE_OWNER,IC.TABLE_NAME,IC.INDEX_NAME,IC.COLUMN_POSITION
DBLink
SELECT OWNER, DB_LINK, USERNAME,HOST FROM DBA_DB_LINKS WHERE 1=1
View
SELECT V.OWNER,V.VIEW_NAME,V.TEXT,V.TEXT_VC ,O.STATUS
FROM DBA_VIEWS V,DBA_OBJECTS O
WHERE V.OWNER = O.OWNER AND V.VIEW_NAME = O.OBJECT_NAME
Materialized View
SELECT
MV.OWNER,
MV.MVIEW_NAME,
MV.BUILD_MODE,
MV.REFRESH_METHOD,
MV.REFRESH_MODE,
MV.REWRITE_ENABLED,
MV.QUERY,
O.STATUS,
R.INTERVAL
FROM
DBA_MVIEWS MV,
DBA_OBJECTS O,
DBA_REFRESH R
WHERE
O.OBJECT_TYPE = 'MATERIALIZED VIEW'
AND MV.OWNER = O.OWNER
AND MV.MVIEW_NAME = O.OBJECT_NAME
AND O.STATUS = 'VALID'
AND MV.OWNER = R.ROWNER(+)
AND MV.MVIEW_NAME = R.RNAME(+) AND UPPER(MV.OWNER) = 'ORA_MTK' AND (UPPER(MV.MVIEW_NAME) = 'T3' OR UPPER(MV.MVIEW_NAME) = 'T2')
Function
SELECT
S.NAME,
S.LINE,
S.TEXT
FROM
DBA_SOURCE S,
DBA_OBJECTS O
WHERE
1=1
AND S.TYPE = 'FUNCTION'
AND S.OWNER = O.OWNER
AND S.TYPE = O.OBJECT_TYPE
AND S.NAME = O.OBJECT_NAME
Procedure
SELECT
S.NAME,
S.LINE,
S.TEXT
FROM
DBA_SOURCE S,
DBA_OBJECTS O
WHERE
1=1
AND S.TYPE = 'PROCEDURE'
AND S.OWNER = O.OWNER
AND S.TYPE = O.OBJECT_TYPE
AND S.NAME = O.OBJECT_NAME
Package
SELECT
S.NAME,
S.TYPE,
S.LINE,
S.TEXT
FROM
DBA_SOURCE S,
DBA_OBJECTS O
WHERE
1=1
AND (S.TYPE = 'PACKAGE' OR S.TYPE = 'PACKAGE BODY')
AND S.OWNER = O.OWNER
AND S.TYPE = O.OBJECT_TYPE
AND S.NAME = O.OBJECT_NAME
Trigger
SELECT
T.TRIGGER_NAME,
T.OWNER,
T.TABLE_OWNER,
T.TRIGGER_TYPE,
T.TRIGGERING_EVENT,
T.TABLE_NAME,
T.TRIGGER_BODY,
T.WHEN_CLAUSE,
T.DESCRIPTION,
T.STATUS,
T.BASE_OBJECT_TYPE,
T.ACTION_TYPE
FROM
DBA_TRIGGERS T,
DBA_OBJECTS O
WHERE
O.OBJECT_NAME = T.TRIGGER_NAME
AND O.OWNER = T.TABLE_OWNER
-- AND o.status = 'VALID'
AND O.OBJECT_TYPE = 'TRIGGER'
Synonym
SELECT OWNER,SYNONYM_NAME,TABLE_OWNER,TABLE_NAME FROM DBA_SYNONYMS WHERE DB_LINK IS NULL