本文介绍如何将Oracle数据库中的数据迁移到TimesTen。可以使用的方法如下:
1. 建立Cache Group
2. ttisql Utility: createandloadfromoraquery
3. ttisql Utility: ttLoadFromOracle
4. ttImportFromOracle
5. SQLDeveloper
6. ttBulkCp
以下的例子都基于Oracle数据库的Sample Schema,因此我们需要先建立Sample Schema。
使用DBCA创建一个新的PDB,选择Create Pluggable Database using PDB File Set,选择sampleschema.xml
详见Oracle Knowledge Table: Create PDB with Sample schemas in DB12c
解锁用户hr,设置口令
SQL> alter session set container = pdbsample;
Session altered.
SQL> show con_name;
CON_NAME
------------------------------
PDBSAMPLE
SQL> alter user hr account unlock identified by oracle;
User altered.
SQL> alter user oe account unlock identified by oracle;
User altered.
SQL> grant select on oe.orders to hr;
Grant succeeded.
SQL> grant select on inventories to hr;
Grant succeeded.
SQL> col username format a20
SQL> select * from ( select username, account_status from dba_users order by created desc) where rownum <=7;
USERNAME ACCOUNT_STATUS
-------------------- --------------------------------
SCOTT EXPIRED & LOCKED
BI EXPIRED & LOCKED
SH EXPIRED & LOCKED
IX EXPIRED & LOCKED
PM EXPIRED & LOCKED
OE OPEN
HR OPEN
7 rows selected.
SQL> alter user sh account unlock identified by oracle;
User altered.
select * from (
select username, account_status from dba_users order by created desc)
where rownum <=7;
tnsnames.ora中添加服务PDBSAMPLE
PDBSAMPLE = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pdbsample)
确认HR schema中表已经建立
$ sqlplus hr/oracle@pdbsample
SQL> select table_name from user_tables;
TABLE_NAME --------------------------------------------------------------------------------
REGIONS
LOCATIONS
DEPARTMENTS
JOBS
EMPLOYEES
JOB_HISTORY COUNTRIES 7 rows selected.
SQL> SELECT value FROM nls_database_parameters WHERE parameter='NLS_CHARACTERSET';
VALUE --------------------------------------------------------------------------------
AL32UTF8
在TimesTen数据库中创建相同的用户hr,口令为timesten
$ ttisql sampledb_1122
Command> create user hr identified by timesten;
User created.
Command> grant create session, create table to hr;
建立Cache Group的方法比较复杂,前面也有很多例子介绍过了,这里就不赘述了。
建立Cache Group要求:
* Oracle和TimesTen的字符集一致
* Oracle和TimesTen具有相同的Schema用户
* Oracle中的表有Primary Key或唯一索引
建立Cache Group后,可以使用手工的Load命令加载数据
第二种方法是使用ttisql Utility: createandloadfromoraquery, 如下面的演示:
[oracle@tt12c admin]$ ttisql "dsn=sampledb_1122;uid=hr;pwd=timesten;OracleNetServiceName=pdbsample;OraclePWD=oracle"
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.
connect "dsn=sampledb_1122;uid=hr;pwd=********;OracleNetServiceName=pdbsample;OraclePWD=********";
Connection successful: DSN=sampledb_1122;UID=hr;DataStore=/home/oracle/TimesTen/tt1122/info/DemoDataStore/sampledb_1122;DatabaseCharacterSet=AL32UTF8;ConnectionCharacterSet=US7ASCII;DRIVER=/home/oracle/TimesTen/tt1122/lib/libtten.so;PermSize=40;TempSize=32;TypeMode=0;OracleNetServiceName=pdbsample;
(Default setting AutoCommit=1)
Command> createandloadfromoraquery employees 2 SELECT * FROM hr.employees;
Mapping query to this table:
CREATE TABLE "HR"."EMPLOYEES" (
"EMPLOYEE_ID" number(6,0) NOT NULL,
"FIRST_NAME" varchar2(20 byte),
"LAST_NAME" varchar2(25 byte) NOT NULL,
"EMAIL" varchar2(25 byte) NOT NULL,
"PHONE_NUMBER" varchar2(20 byte),
"HIRE_DATE" date NOT NULL,
"JOB_ID" varchar2(10 byte) NOT NULL,
"SALARY" number(8,2),
"COMMISSION_PCT" number(2,2),
"MANAGER_ID" number(6,0),
"DEPARTMENT_ID" number(4,0)
)
Table employees created
107 rows loaded from oracle.
Command> tables
HR.EMPLOYEES
1 table found.
Command> select count(*) from employees;
< 107 >
1 row found.
下面这个例子说明TimesTen和Oracle之间必须数据类型必须可以转换。
Command> createandloadfromoraquery orders 2 SELECT * FROM oe.orders;
Warning 5115: Unsupported type mapping for column ORDER_DATE
Unsupported type found, unable to create table
< CREATE TABLE "HR"."ORDERS" (
"ORDER_ID" number(12,0) NOT NULL
>>>> "ORDER_DATE" TIMESTAMP WITH LOCAL TIME ZONE /* Unsupported Oracle type-cannot be converted to Timesten type */ NOT NULL,
"ORDER_MODE" varchar2(8 byte),
"CUSTOMER_ID" number(6,0) NOT NULL,
"ORDER_STATUS" number(2,0),
"ORDER_TOTAL" number(8,2),
"SALES_REP_ID" number(6,0),
"PROMOTION_ID" number(6,0)
) >
1 row found.
The command failed.
Any unsupported column types result in a warning being logged. The output issues a comment for the unsupported column data type.
下例说明可以访问其他Schema的表(hr访问oe的表)
Command> createandloadfromoraquery inventories 2 SELECT * FROM oe.inventories;
Mapping query to this table:
CREATE TABLE "HR"."INVENTORIES" (
"PRODUCT_ID" number(6,0) NOT NULL,
"WAREHOUSE_ID" number(3,0) NOT NULL,
"QUANTITY_ON_HAND" number(8,0) NOT NULL
)
Table inventories created
1112 rows loaded from oracle.
Command> tables
HR.EMPLOYEES
HR.INVENTORIES
2 tables found.
下例说明TimesTen和Oracle的字符集必须一致,我重建TimesTen数据库,修改字符集为US7ASCII,报错如下:
Command> createandloadfromoraquery inventories 2 SELECT * FROM oe.inventories;
createandloadfromoraquery a 2 SELECT * FROM a;
8296: TimesTen and Oracle database character sets do not match. TimesTen: US7ASCII, Oracle: AL32UTF8
5109: Cache Connect general error: BDB connection not open.
The command failed.
下例说明Oracle中的表无需索引,并且createandloadfromoraquery可自动建表,如果表已存在也没有关系。
SQL> show con_name
CON_NAME
------------------------------
PDBSAMPLE
SQL> create table a(a int);
Table created.
Command> createandloadfromoraquery a 2 SELECT * FROM a;
Mapping query to this table:
CREATE TABLE "HR"."A" (
"A" number(38,0)
)
Table a created
0 rows loaded from oracle.
Command> select * from a;
0 rows found.
Command> createandloadfromoraquery a 2 SELECT * FROM a;
Warning 2207: Table HR.A already exists
13 rows loaded from oracle.
通过以上的实验,可以总结出createandloadfromoraquery的特性为:
* 如果TimesTen中的表不存在, createandloadfromoraquery可以自动建表,可以并行加载数据(上面示例中的2表示两个线程,缺省是4个线程)。
* 要求TimesTen和Oracle的字符集一致
* 不要求Oracle中的表有索引
* 只是加载数据,不会建立源表的索引。
* 只是追加/插入数据,不会删除已有的数据
* 可以加载其它schema的数据
第二种方法是使用ttisql Utility: ttLoadFromOracle, 语法如下:
ttLoadFromOracle([‘tblOwner’], ‘tblName’, ‘QueryInOracle’ [,numThreads])
就是将在Oracle中执行的查询的结果加载到TimesTen的表中,支持多线程。
由于SQL的合法性和权限是在Oracle中执行的,因此也可以访问其他Schema的数据或DB Link都是支持的, 看一下TimesTen 11.2.2.8.6 release notes中的描述:
With this release, the ttLoadFromOracle built-in procedure can load data from different Oracle servers to a single TimesTen database by supplying an OracleNetServiceName attribute directly in the connection string. The value in the connection string overrides the same attribute supplied in the DSN configuration.
The ttLoadfromOracle built-in procedure also can load remote Oracle tables accessed through a database link. For example: call ttLoadFromOracle(‘SCOTT’, ‘MY_TIGER’, ‘SELECT * FROM SCOTT.MY_TIGER@zoo’)
用法比较简单,如下面的演示:
Command> call ttloadfromoracle('hr','a', 'select * from a');
< 13 >
1 row found.
Command> call ttloadfromoracle('hr','a', 'select * from a');
< 13 >
1 row found.
Command> select count(*) from a;
< 39 >
1 row found.
Command> call ttloadfromoracle('hr','b', 'select * from a');
2206: Table HR.B not found The command failed.
可以看出,数据是追加模式的,也不需要源表有索引,但要求TimesTen中的表存在。如果不存在,可以借助于ttTableSchemaFromOraQueryGet
来得到DDL,例如:
Command> call ttTableSchemaFromOraQueryGet('hr','employees', 'SELECT * FROM oe.inventories');
< CREATE TABLE "HR"."EMPLOYEES" (
"PRODUCT_ID" number(6,0) NOT NULL,
"WAREHOUSE_ID" number(3,0) NOT NULL,
"QUANTITY_ON_HAND" number(8,0) NOT NULL
) >
1 row found.
但字符集还是必须一致的,甚至ttTableSchemaFromOraQueryGet也要求字符集一致,例如:
Command> call ttTableSchemaFromOraQueryGet('hr','employees', 'SELECT * FROM oe.inventories');
8296: TimesTen and Oracle database character sets do not match. TimesTen: US7ASCII, Oracle: AL32UTF8
5109: Cache Connect general error: BDB connection not open.
ttloadCommand> call ttloadfromoracle('hr','a', 'select * from a');
8296: TimesTen and Oracle database character sets do not match. TimesTen: US7ASCII, Oracle: AL32UTF8
5109: Cache Connect general error: BDB connection not open.
The command failed.
总结ttloadfromoracle的特性如下:
* 数据追加模式
* 字符集必须一致
* 不要求源表的唯一索引
* 支持加载DBLINK和其它Schema的数据
* 要求TimesTen中的表已经存在,如果不存在,可以用ttTableSchemaFromOraQueryGet得到DDL建立
ttImportFromOracle 是Oracle提供的Sample Utilities系列之一,官方并不提供支持。你需要从Oracle TimesTen Sample Utilities Downloads下载,通常安装在$TT_HOME/support目录下。
这时一个功能丰富的应用,详细的帮助可参见:README
我们先通过一个示例了解他用于数据迁移的用法,下例演示了将Oracle HR Schema的DDL和数据导出:
[oracle@tt12c test]$ ttImportFromOracle -oraconn hr/oracle@pdbsample
Beginning processing
No tables specified, loading list from source
Getting metadata from source
Warning: Constraint 'EMP_DEPT_FK' on table 'HR.EMPLOYEES' is a circular foreign key and will be treated as a non-unique index
Warning: Constraint 'EMP_MANAGER_FK' on table 'HR.EMPLOYEES' is a self referencing foreign key and will be treated as a non-unique index
Generating database user list
Assigning TimesTen datatypes
Analyzing source tables
Analyzing table 'HR.REGIONS' ...
Analyzing table 'HR.COUNTRIES' ...
Analyzing table 'HR.JOBS' ...
Analyzing table 'HR.EMPLOYEES' ...
Analyzing table 'HR.LOCATIONS' ...
Analyzing table 'HR.DEPARTMENTS' ...
Analyzing table 'HR.JOB_HISTORY' ...
Estimating table sizes
Estimating index sizes
Evaluating parallel data load
Generating output files
Finished processing
[oracle@tt12c test]$
ttImportFromOracle只与Oracle交互,并产生中间数据文件,DDL文件,随后在TimesTen中执行这些文件即可。
TableList.txt显示了表的概况
[oracle@tt12c test]$ cat TableList.txt
############################################################################
## Generated by ttImportFromOracle 3.7.0 - Fri Apr 29 10:27:16 2016
############################################################################
HR.REGIONS:rows=4:ttwriters=3:oradop=1:orapar=none
HR.COUNTRIES:rows=25:ttwriters=3:oradop=1:orapar=none
HR.JOBS:rows=19:ttwriters=3:oradop=1:orapar=none
HR.EMPLOYEES:rows=107:ttwriters=3:oradop=1:orapar=none
HR.LOCATIONS:rows=23:ttwriters=3:oradop=1:orapar=none
HR.DEPARTMENTS:rows=27:ttwriters=3:oradop=1:orapar=none
HR.A:rows=13:ttwriters=3:oradop=1:orapar=none
HR.JOB_HISTORY:rows=10:ttwriters=3:oradop=1:orapar=none
然后我们可以建用户,建表,索引,导入数据。
建用户,这个挺贴心的。注意将口令改成你所需要的。
[oracle@tt12c test]$ ttisql sampledb_1122
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.
connect "DSN=sampledb_1122";
dConnection successful: DSN=sampledb_1122;UID=oracle;DataStore=/home/oracle/TimesTen/tt1122/info/DemoDataStore/sampledb_1122;DatabaseCharacterSet=US7ASCII;ConnectionCharacterSet=US7ASCII;DRIVER=/home/oracle/TimesTen/tt1122/lib/libtten.so;PermSize=40;TempSize=32;TypeMode=0;
(Default setting AutoCommit=1)
Command> host ls;
CreateIndexes.sql DropIndexes.sql TableList.txt
CreateTables.sql DropTables.sql ttPDL.sh
CreateUsers.sql LoadData.sql UpdateStats.sql
Command> @CreateUsers.sql
----------------------------------------------------------------------------
-- Generated by ttImportFromOracle 3.7.0 - Fri Apr 29 10:27:16 2016
----------------------------------------------------------------------------
CREATE USER HR IDENTIFIED BY 'hr';
User created.
GRANT CREATE SESSION, CREATE TABLE TO HR;
-- GRANT CREATE VIEW, CREATE SEQUENCE, CREATE SYNONYM
-- TO HR;
建表
Command> @CreateTables.sql
---------------------------------------------------------------------------- -- Generated by ttImportFromOracle 3.7.0 - Fri Apr 29 10:27:16 2016 ---------------------------------------------------------------------------- -- -- See end of file for table size totals -- -- Source is Oracle Database 12.1.0.2.0 -- -- Character set is AL32UTF8 -- ---------------------------------------------------------------------------- -- -- Type mapping modes: -- Numeric: 1 - STANDARD -- Varlen: 0 - NONE -- RAW/LONG/LONG RAW: 1 - YES -- LOBs: 1 - YES -- TIMESTAMP WITH TZ: 1 - YES -- -- Compression mode: 0 - NONE -- ----------------------------------------------------------------------------
-- ************************************************************ -- Rows: 4 -- Bytes per row: Oracle - max 47 -- TimesTen - inline 55, not inline max 0, total 55 -- Estimated table size = 22650 bytes CREATE TABLE HR.REGIONS
(
REGION_ID NUMBER NOT NULL,
-- Oracle type: NUMBER
REGION_NAME VARCHAR2(25 BYTE) INLINE
-- Oracle type: VARCHAR2(25 BYTE) );
-- ************************************************************ -- Rows: 25 -- Bytes per row: Oracle - max 64 -- TimesTen - inline 72, not inline max 0, total 72 -- Estimated table size = 27061 bytes CREATE TABLE HR.COUNTRIES
(
COUNTRY_ID CHAR(2 BYTE) NOT NULL,
-- Oracle type: CHAR(2 BYTE)
COUNTRY_NAME VARCHAR2(40 BYTE) INLINE,
-- Oracle type: VARCHAR2(40 BYTE)
REGION_ID NUMBER
-- Oracle type: NUMBER );
-- ************************************************************ -- Rows: 19 -- Bytes per row: Oracle - max 89 -- TimesTen - inline 69, not inline max 0, total 69 -- Estimated table size = 29424 bytes CREATE TABLE HR.JOBS
(
JOB_ID VARCHAR2(10 BYTE) INLINE NOT NULL,
-- Oracle type: VARCHAR2(10 BYTE)
JOB_TITLE VARCHAR2(35 BYTE) INLINE NOT NULL,
-- Oracle type: VARCHAR2(35 BYTE)
MIN_SALARY TT_INTEGER,
-- Oracle type: NUMBER(6,0)
MAX_SALARY TT_INTEGER
-- Oracle type: NUMBER(6,0) );
-- ************************************************************ -- Rows: 107 -- Bytes per row: Oracle - max 217 -- TimesTen - inline 172, not inline max 0, total 172 -- Estimated table size = 62349 bytes CREATE TABLE HR.EMPLOYEES
(
EMPLOYEE_ID TT_INTEGER NOT NULL,
-- Oracle type: NUMBER(6,0)
FIRST_NAME VARCHAR2(20 BYTE) INLINE,
-- Oracle type: VARCHAR2(20 BYTE)
LAST_NAME VARCHAR2(25 BYTE) INLINE NOT NULL,
-- Oracle type: VARCHAR2(25 BYTE)
EMAIL VARCHAR2(25 BYTE) INLINE NOT NULL,
-- Oracle type: VARCHAR2(25 BYTE)
PHONE_NUMBER VARCHAR2(20 BYTE) INLINE,
-- Oracle type: VARCHAR2(20 BYTE)
HIRE_DATE DATE NOT NULL,
-- Oracle type: DATE
JOB_ID VARCHAR2(10 BYTE) INLINE NOT NULL,
-- Oracle type: VARCHAR2(10 BYTE)
SALARY NUMBER(8,2),
-- Oracle type: NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2),
-- Oracle type: NUMBER(2,2)
MANAGER_ID TT_INTEGER,
-- Oracle type: NUMBER(6,0)
DEPARTMENT_ID TT_SMALLINT
-- Oracle type: NUMBER(4,0) );
-- ************************************************************ -- Rows: 23 -- Bytes per row: Oracle - max 131 -- TimesTen - inline 143, not inline max 0, total 143 -- Estimated table size = 48486 bytes CREATE TABLE HR.LOCATIONS
(
LOCATION_ID TT_SMALLINT NOT NULL,
-- Oracle type: NUMBER(4,0)
STREET_ADDRESS VARCHAR2(40 BYTE) INLINE,
-- Oracle type: VARCHAR2(40 BYTE)
POSTAL_CODE VARCHAR2(12 BYTE) INLINE,
-- Oracle type: VARCHAR2(12 BYTE)
CITY VARCHAR2(30 BYTE) INLINE NOT NULL,
-- Oracle type: VARCHAR2(30 BYTE)
STATE_PROVINCE VARCHAR2(25 BYTE) INLINE,
-- Oracle type: VARCHAR2(25 BYTE)
COUNTRY_ID CHAR(2 BYTE)
-- Oracle type: CHAR(2 BYTE) );
-- ************************************************************ -- Rows: 27 -- Bytes per row: Oracle - max 96 -- TimesTen - inline 46, not inline max 0, total 46 -- Estimated table size = 21232 bytes CREATE TABLE HR.DEPARTMENTS
(
DEPARTMENT_ID TT_SMALLINT NOT NULL,
-- Oracle type: NUMBER(4,0)
DEPARTMENT_NAME VARCHAR2(30 BYTE) INLINE NOT NULL,
-- Oracle type: VARCHAR2(30 BYTE)
MANAGER_ID TT_INTEGER,
-- Oracle type: NUMBER(6,0)
LOCATION_ID TT_SMALLINT
-- Oracle type: NUMBER(4,0) );
-- ************************************************************ -- Rows: 13 -- Bytes per row: Oracle - max 22 -- TimesTen - inline 22, not inline max 0, total 22 -- Estimated table size = 14143 bytes CREATE TABLE HR.A
(
A NUMBER(38,0)
-- Oracle type: NUMBER(38,0) );
-- ************************************************************ -- Rows: 10 -- Bytes per row: Oracle - max 68 -- TimesTen - inline 38, not inline max 0, total 38 -- Estimated table size = 19499 bytes CREATE TABLE HR.JOB_HISTORY
(
EMPLOYEE_ID TT_INTEGER NOT NULL,
-- Oracle type: NUMBER(6,0)
START_DATE DATE NOT NULL,
-- Oracle type: DATE
END_DATE DATE NOT NULL,
-- Oracle type: DATE
JOB_ID VARCHAR2(10 BYTE) INLINE NOT NULL,
-- Oracle type: VARCHAR2(10 BYTE)
DEPARTMENT_ID TT_SMALLINT
-- Oracle type: NUMBER(4,0) );
---------------------------------------------------------------------------- -- Estimated total size for all tables: 244844 bytes ----------------------------------------------------------------------------; Command> tables;
HR.A
HR.COUNTRIES
HR.DEPARTMENTS
HR.EMPLOYEES
HR.JOBS
HR.JOB_HISTORY
HR.LOCATIONS
HR.REGIONS
8 tables found.
加载数据使用的是ttLoadFromOracle,因此也要求字符集一致,而且需要通过OraclePWD连接到后端Oracle
[oracle@tt12c test]$ ttisql "dsn=sampledb_1122;uid=hr;pwd=timesten;OracleNetServiceName=pdbsample;OraclePWD=oracle"
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.
connect "dsn=sampledb_1122;uid=hr;pwd=********;OracleNetServiceName=pdbsample;OraclePWD=********";
Connection successful: DSN=sampledb_1122;UID=hr;DataStore=/home/oracle/TimesTen/tt1122/info/DemoDataStore/sampledb_1122;DatabaseCharacterSet=AL32UTF8;ConnectionCharacterSet=US7ASCII;DRIVER=/home/oracle/TimesTen/tt1122/lib/libtten.so;PermSize=40;TempSize=32;TypeMode=0;OracleNetServiceName=pdbsample;
(Default setting AutoCommit=1)
Command> host ls
CreateIndexes.sql DropIndexes.sql TableList.txt
CreateTables.sql DropTables.sql ttPDL.sh
CreateUsers.sql LoadData.sql UpdateStats.sql
Command> @LoadData
----------------------------------------------------------------------------
-- Generated by ttImportFromOracle 3.7.0 - Fri Apr 29 10:27:16 2016
----------------------------------------------------------------------------
-- timing 1;
call ttLoadFromOracle('HR', 'REGIONS', 'SELECT REGION_ID, REGION_NAME FROM HR.REGIONS');
< 4 >
1 row found.
call ttLoadFromOracle('HR', 'COUNTRIES', 'SELECT COUNTRY_ID, COUNTRY_NAME, REGION_ID FROM HR.COUNTRIES');
< 25 >
1 row found.
call ttLoadFromOracle('HR', 'JOBS', 'SELECT JOB_ID, JOB_TITLE, MIN_SALARY, MAX_SALARY FROM HR.JOBS');
< 19 >
1 row found.
call ttLoadFromOracle('HR', 'EMPLOYEES', 'SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE, JOB_ID, SALARY, COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID FROM HR.EMPLOYEES');
< 107 >
1 row found.
call ttLoadFromOracle('HR', 'LOCATIONS', 'SELECT LOCATION_ID, STREET_ADDRESS, POSTAL_CODE, CITY, STATE_PROVINCE, COUNTRY_ID FROM HR.LOCATIONS');
< 23 >
1 row found.
call ttLoadFromOracle('HR', 'DEPARTMENTS', 'SELECT DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID FROM HR.DEPARTMENTS');
< 27 >
1 row found.
call ttLoadFromOracle('HR', 'A', 'SELECT A FROM HR.A');
< 13 >
1 row found.
call ttLoadFromOracle('HR', 'JOB_HISTORY', 'SELECT EMPLOYEE_ID, START_DATE, END_DATE, JOB_ID, DEPARTMENT_ID FROM HR.JOB_HISTORY');
< 10 >
1 row found.
Command>
建立索引,更新统计信息
Command> @CreateIndexes;
Command> @UpdateStats ---------------------------------------------------------------------------- -- Generated by ttImportFromOracle 3.7.0 - Fri Apr 29 10:27:16 2016 ---------------------------------------------------------------------------- -- timing 1;
call ttOptUpdateStats('HR.REGIONS',1);
call ttOptUpdateStats('HR.COUNTRIES',1);
call ttOptUpdateStats('HR.JOBS',1);
call ttOptUpdateStats('HR.EMPLOYEES',1);
call ttOptUpdateStats('HR.LOCATIONS',1);
call ttOptUpdateStats('HR.DEPARTMENTS',1);
call ttOptUpdateStats('HR.A',1);
call ttOptUpdateStats('HR.JOB_HISTORY',1);
由于TimesTen不支持drop user cascade,因此DropTables.sql很有用
再看一个失败的例子, 原因是TimesTen中没有对应于Oracle中的自定义数据类型
[oracle@tt12c test]$ ttImportFromOracle -oraconn oe/oracle@pdbsample
Beginning processing
No tables specified, loading list from source
Getting metadata from source
Warning: Unsupported data type 'CUST_ADDRESS_TYP' for 'OE.CUSTOMERS.CUST_ADDRESS' - skipping column
Warning: Unsupported data type 'PHONE_LIST_TYP' for 'OE.CUSTOMERS.PHONE_NUMBERS' - skipping column
Warning: Unsupported data type 'SDO_GEOMETRY' for 'OE.CUSTOMERS.CUST_GEO_LOCATION' - skipping column
Warning: Unsupported index type for index 'OE.CUST_UPPER_NAME_IX' on table 'OE.CUSTOMERS' - ignoring
Warning: Unable to resolve primary key for table 'OE.INVENTORIES'
Warning: Unsupported data type 'INTERVAL YEAR' for 'OE.PRODUCT_INFORMATION.WARRANTY_PERIOD' - skipping column
Error: Table 'OE.PRODUCT_REF_LIST_NESTEDTAB' not found or no permission
Finished processing
总结ttImportFromOracle的特点:
* 适合于批量处理,可以生成整个Schema的建用户,DDL,数据导入等一系列脚本
* 脚本生成时字符集可以不一致,导入数据时要求字符集一致,这还是比较灵活的
* 可以通过指定-ttOwner ttuser参数,来替换schema
在SQL Developer中,支持将Oracle的数据加载到TimesTen中,无论TimesTen中这个表是否存在。
实际是将2. ttisql 中的两个Utility: createandloadfromoraquery 和ttisql Utility: ttLoadFromOracle 做成了界面。
如果TimesTen中表不存在,则使用createandloadfromoraquery
如果TimesTen中表存在,则使用ttLoadFromOracle
SQLDeveloper还可以使用Table的Export菜单或Cart功能导出DDL和DML(数据的insert语句),然后在TimesTen中执行即可,如下:
也可以使用Table的Export菜单或Cart功能导出数据为文本文件。
ttBulkCp可以将TimesTen中的表导出为文本,也可以将文本数据导入TimesTen。
SQLDeveloper中Table的Export功能中,已经集成了对ttBulkCp的支持,如下图:
以下为导出的ttBulkcp格式的文本文件:
[oracle@tt12c ~]$ cat export.dump
##ttBulkCp:FSEP=,:QUOTES=1:TSFORMAT=Oracle
##ttBulkCp:CHARACTERSET=AL32UTF8
##ttBulkCp:NCHARENCODING=UTF-8
#Generated at : 2016-05-01 21:36:12.255
#end
# 1. REGION_ID
# 2. REGION_NAME
1,"Europe"
2,"Americas"
3,"Asia"
4,"Middle East and Africa"
然后可以借助ttTableSchemaFromOraQueryGet和SQLDeveloper生成DDL:
[oracle@tt12c ~]$ ttisql "dsn=sampledb_1122;uid=hr;pwd=timesten;OracleNetServiceName=pdbsample;OraclePWD=oracle"
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.
connect "dsn=sampledb_1122;uid=hr;pwd=********;OracleNetServiceName=pdbsample;OraclePWD=********";
Connection successful: DSN=sampledb_1122;UID=hr;DataStore=/home/oracle/TimesTen/tt1122/info/DemoDataStore/sampledb_1122;DatabaseCharacterSet=AL32UTF8;ConnectionCharacterSet=US7ASCII;DRIVER=/home/oracle/TimesTen/tt1122/lib/libtten.so;PermSize=40;TempSize=32;TypeMode=0;OracleNetServiceName=pdbsample;
(Default setting AutoCommit=1)
Command> select * from regions;
2206: Table HR.REGIONS not found
The command failed.
Command> call ttTableSchemaFromOraQueryGet('hr','regions', 'SELECT * FROM hr.regions');
< CREATE TABLE "HR"."REGIONS" (
"REGION_ID" number NOT NULL,
"REGION_NAME" varchar2(25 byte)
) >
1 row found.
Command> CREATE TABLE "HR"."REGIONS" (
> "REGION_ID" number NOT NULL,
> "REGION_NAME" varchar2(25 byte)
> ) ;
Command> desc regions;
Table HR.REGIONS:
Columns:
REGION_ID NUMBER NOT NULL
REGION_NAME VARCHAR2 (25) INLINE
1 table found.
最后使用ttbulkcp导入数据
[oracle@tt12c ~]$ ttbulkcp -connstr "dsn=sampledb_1122;uid=hr;pwd=timesten" -i hr.regions export.dump
export.dump:
4 rows inserted
4 rows total
[oracle@tt12c ~]$ ttisql "dsn=sampledb_1122;uid=hr;pwd=timesten"
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.
connect "dsn=sampledb_1122;uid=hr;pwd=********";
Connection successful: DSN=sampledb_1122;UID=hr;DataStore=/home/oracle/TimesTen/tt1122/info/DemoDataStore/sampledb_1122;DatabaseCharacterSet=AL32UTF8;ConnectionCharacterSet=US7ASCII;DRIVER=/home/oracle/TimesTen/tt1122/lib/libtten.so;PermSize=40;TempSize=32;TypeMode=0;
(Default setting AutoCommit=1)
Command> select * from regions;
< 1, Europe >
< 2, Americas >
< 3, Asia >
< 4, Middle East and Africa >
4 rows found.
Command>