- 浏览: 659359 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
HkEndless:
不好意思,请问这确定是回调机制吗。你的例子中只是将接口的实现类 ...
Spring CallBack回调机制介绍 -
hanmiao:
写的真乱啊,完全不知所云...
Java如何调用可执行文件和批处理命令 -
junia_1:
junia_1 写道 shock: ...
为什么要使用EJB -
junia_1:
shock:
为什么要使用EJB -
coollifer:
不错
SQL Server数据导入到Oracle中的方法
Tables can be reorganized and redefined (evolved) on-line with the DBMS_REDEFINITION package. The process is similar to on-line rebuilds of indexes, in that the original table is left on-line, while a new copy of the table is built. However, an index index-rebuild is a singular operation, while table redefinition is a multi-step process.
Table redefinition is started by the DBA creating an interim table based on the original table. The interim table can have a different structure than the original table, and will eventually take the original table's place in the database. While the table is redefined, DML operations on the original table are captured in a Materialized View Log table (MLOG$_%). These changes are eventually transformed and merged into the interim table. When done, the names of the original and the interim tables are swapped in the data dictionary. At this point all users will be working on the new table and the old table can be dropped.
Possible applications:
On-line Table Redefinition can be used for:
- Add, remove, or rename columns from a table
- Converting a non-partitioned table to a partitioned table and vice versa
- Switching a heap table to an index organized and vice versa
- Modifying storage parameters
- Adding or removing parallel support
- Reorganize (defragmenting) a table
- Transform data in a table
Restrictions:
- One cannot redefine Materialized Views (MViews) and tables with MViews or MView Logs defined on them.
- One cannot redefine Temporary and Clustered Tables
- One cannot redefine tables with BFILE, LONG or LONG RAW columns
- One cannot redefine tables belonging to SYS or SYSTEM
- One cannot redefine Object tables
- Table redefinition cannot be done in NOLOGGING mode (watch out for heavy archiving)
- Cannot be used to add or remove rows from a table
Using On-line Redefinition from Enterprise Manager:
Oracle Enterprise Manager's REORG Wizard (part of the Tuning pack) allows DBAs to reorganize tables off-line or on-line. If on-line reorganization is chosen, Oracle will make use of the DBMS_REDEFINITION package. Off-line reorganization is quicker than on-line reorganization, but if the system cannot go down, the on-line method will prove valuable.
Execute the following steps to start the REORG Wizard: Start OEM. Click on TOOLS -> TUNING PACK -> REORG WIZARD.
Using On-line Redefinition from SQL*Plus:
A table can be redefined in 7 easy steps from SQL*Plus.
Step 1: Grant privileges:
Grant EXECUTE ON DBMS_REDEFINITION and the following privileges to the user that will do the redefinition: CREATE ANY TABLE, ALTER ANY TABLE, DROP ANY TABLE, LOCK ANY TABLE, SELECT ANY TABLE. Look at this example:
SQL> grant execute on dbms_redefinition to scott; SQL> grant dba to scott;
Note: These are powerful privileges, so remember to revoke them afterwards.
Step 2: Test if the table can be redefined:
Execute the DBMS_REDEFINITION.CAN_REDEF_TABLE procedure to test if a table can be redefined or not. A table qualifies for redefinition if no exceptions are raised. Possible errors:
- ORA-12089 cannot online redefine table with no primary key
- ORA-12091: cannot online redefine table "SCOTT"."EMP" with materialized views
- ORA-00942: table or view does not exist
SQL> EXEC DBMS_REDEFINITION.CAN_REDEF_TABLE('scott', 'emp', DBMS_REDEFINITION.CONS_USE_PK);
Note: The redefinition process can be based on a Primary Key or ROWID. Two constants are defined for this purpose: DBMS_REDEFINITION.CONS_USE_PK (the default) and DBMS_REDEFINITION.CONS_USE_ROWID. One can also use the value "1" for the primary key method, and "2" to indicate the rowid method. This is required so Oracle will know how to create the mview log: WITH ROWID, or WITH PRIMARY KEY.
Step 3: Create an interim table with new structure
Create an interim table with the new table structure. Define a primary key if you want to use the primary key method (DBMS_REDEFINITION.CONS_USE_PK). This is not required for the rowid method.
Oracle will TRUNCATE the interim table in step 4; so, do not add any data to it yet. Avoid adding constraints and indexes at this stage (for best performance).
Step 4: Start the redefinition
During this phase Oracle will copy (and transform) the data from the production table to the interim table. Oracle will also create a materialized view (snapshot) log on the table to track DML changes.
SQL> exec dbms_redefinition.start_redef_table('scott', 'emp', 'emp_work', - > 'emp_id emp_id, ename ename, salary salary', - > DBMS_REDEFINITION.CONS_USE_PK);
Note parameter 4: mapping for the old table's columns to the new table's columns. This can be left out if the columns are the same.
Step 5: Sync intermediate changes to interim table (optional)
This step will apply changes captured in the materialized view log to the interim table. Perform this step frequently for high transaction tables.
SQL> exec dbms_redefinition.sync_interim_table('scott', 'emp', 'emp_work');
Step 6: Create indexes, constraints and triggers on the interim table
Note that you cannot use the same names for indexes and constraints. Foreign key constraints must be created DISABLED (Oracle will enable them in step 6).
Step 7: Complete the redefinition process
During this step Oracle will lock both tables in exclusive mode, swap the names of the two tables in the data dictionary, and enable all foreign key constraints. Remember to drop the original table afterwards. One can also consider renaming the constraints back to their original names (e.g.: alter table EMP rename constraint SYS_C001806 to emp_fk).
SQL> exec dbms_redefinition.finish_redef_table('scott', 'emp', 'emp_work');
Optional step to Abort Redefinition:
Redefinition can be aborted at any stage by calling the DBMS_REDEFINITION.ABORT_REDEF_TABLE procedure. This will drop the mview log on the production table. Note that you need to abort before trying again, otherwise you will get an ORA-12091 error as described in step 2.
Examples:
Example 1: On-line Table Reorg using the rowid method
EXEC DBMS_REDEFINITION.CAN_REDEF_TABLE('scott', 'emp', 2); -- 2=rowid CREATE TABLE emp_work AS SELECT * FROM emp WHERE 1=2; EXEC DBMS_REDEFINITION.START_REDEF_TABLE('scott', 'emp', 'emp_work', NULL, 2); ALTER TABLE emp ADD PRIMARY KEY (empno); EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE('scott', 'emp', 'emp_work'); DROP TABLE emp_work;
Example 2: Redefine a table using the primary key method
-- Create a new table with primary key... CREATE TABLE myemp ( empid NUMBER PRIMARY KEY, ename VARCHAR2(30), salary NUMBER(8,2), deptno NUMBER); insert into myemp values (1, 'Frank', 15000, 10); insert into myemp values (2, 'Willie', 10000, 20); create index myemp_idx on myemp (ename); -- Test if redefinition is possible... EXEC DBMS_REDEFINITION.CAN_REDEF_TABLE('scott', 'myemp'); -- Create new empty interim table... CREATE TABLE myemp_work ( emp# NUMBER PRIMARY KEY, -- Change emp_id to emp# ename VARCHAR2(30), salary NUMBER(8,2), -- We will increase salary by 10% deptno NUMBER) PARTITION BY LIST (deptno) ( -- Add list partitioning PARTITION p10 VALUES (10), PARTITION p20 VALUES (20), PARTITION p30 VALUES (30,40)); -- Create a transformation function... CREATE FUNCTION raise_sal (salary NUMBER) RETURN NUMBER AS BEGIN return salary + salary*0.10; END; / -- Start the redefinition process EXEC DBMS_REDEFINITION.START_REDEF_TABLE('scott', 'myemp', 'myemp_work', - 'empid emp#, ename ename, raise_sal(salary) salary, deptno deptno', - DBMS_REDEFINITION.CONS_USE_PK); -- Apply captured changed to interim table EXEC DBMS_REDEFINITION.SYNC_INTERIM_TABLE('scott', 'myemp', 'myemp_work'); -- Add constraints, indexes, triggers, grants on interim table... create index myempidx2 on myemp_work (ename); -- Finish the redefinition process... EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE('scott', 'myemp', 'myemp_work'); -- Cleanup DROP TABLE myemp_work; DROP FUNCTION raise_sal;
发表评论
-
ORA-14551: 无法在查询中执行 DML 操作
2013-11-30 13:45 1364最近在调试一个带DML操作的函数时,一直不成功,在PL/SQ ... -
Oracle Recursive Calls 说明
2013-04-09 23:11 1492一. Recursive Calls 说明 在执行计划 ... -
consistent gets db block gets
2013-04-09 19:58 1440consistent gets :consistent_ge ... -
SQL Server数据导入到Oracle中的方法
2012-07-17 17:09 1597在我们使用SQL Server数据库的过程中,有时需要将SQL ... -
更改ORACLE归档路径及归档模式
2012-07-16 18:23 1868在ORACLE10g和11g版本,ORAC ... -
disable/enable validate/novalidate 的区别
2012-01-08 11:41 1235启用约束: enable( validate) :启用约束,创 ... -
linux用dd测试磁盘速度
2012-01-07 21:58 1013首先要了解两个特殊的设备: /dev/null:回收站、 ... -
在数据分布严重不均的列上使用绑定变量容易错过更好的执行计划
2012-01-07 20:49 1034在数据分布严重不均的列上使用绑定变量容易错过更好的执行计划,原 ... -
Oracle hash join
2012-01-07 17:00 953hash join是oracle里面一个非常强悍的功能 ... -
恢复被rm意外删除数据文件
2012-01-05 12:30 1266一.模拟数据文件删除 [oracle ... -
oracle 块延迟清除(delayed block cleanout)
2012-01-04 22:47 1361为了保证事务的回退和满足多用户的 CR , orac ... -
Oracle数据库SCN号详解
2012-01-04 19:25 1542Oracle数据库SCN号详解: 系统检查点scn(v$da ... -
oracle常见问题与解答
2012-01-03 20:22 16911.对于sql,有几种方法查看执行计划,每种方法有什么区别,对 ... -
Oracle虚拟私有数据库(VPD)概述及简单举例
2011-12-23 12:35 1567Oracle虚拟私有数据库(VPD)概述及简单举例 1、Ora ... -
alter table move跟shrink space的区别
2011-12-17 15:02 1296都知道alter table move 或shrink spa ... -
How to dump Oracle Data Block?
2011-12-16 15:22 999Often while doing instance tuni ... -
oracle索引的5种使用模式
2011-12-14 21:19 1080索引的使用对数据库的性能有巨大的影响。 共有五类不同的使用模式 ... -
HP Unix中的dba MLOCK
2011-12-14 19:14 2235最近在HP平台上遇到两次跟dba MLOCK权限相关的错误: ... -
NESTED LOOP、HASH JOIN、SORT MERGE JOIN
2011-12-13 23:18 1378表连接方式及使用场合 ... -
Oracle用户权限
2011-12-12 19:48 1514系统权限: 1、使用GRANT语句向用户赋予系统权限: ...
相关推荐
《FAQ_Function_Reorganization_chs.zip》是一个压缩包文件,其中包含了一份名为《FAQ_Function_Reorganization_chs.pdf》的文档。这份文档很可能详细介绍了某个IT项目或系统中的功能重组常见问题与解答。考虑到...
- 外部表不能作为online reorganization的目标。 综上所述,基于Informix+External+Table的技术,为数据处理领域带来了革命性的变化,特别是在数据导入导出、在线数据加载以及数据迁移等方面,展现出卓越的性能和...
Additional cleanup and optimizations for the new Table Manager code. AcpiEnable will now fail if all of the required ACPI tables are not loaded (FADT, FACS, DSDT). BZ 477 Added #pragma pack(8/4) to ...
In this work, a model based on the optical rectification effect and the photocurrent surge effect is proposed to describe the terahertz emission mechanism of the layered GaTe crystal. As a ...
The number of levels in an index will vary depending on the number of rows in the table and the size of the key column or columns for the index. If you create an index using a large key, fewer ...
Reorganization是PCS7中的一项关键功能,用于项目文件的整理和优化,以确保系统的稳定运行和维护。 一、项目文件结构与管理 在PCS7系统中,一个完整的项目包含了大量文件,包括数据库、组态信息等。这些文件由...
标题中的“MFA-reorganization-scripts”指的是一个专门设计的脚本集,用于整理语料库,以便能够与“蒙特利尔强制对准器”(Montreal Forced Aligner,简称MFA)顺利配合使用。MFA是一款强大的开源工具,它允许用户...
以前和大家分享过SIGMOD2009的论文,朋友们都很感兴趣,现手里有SIGMOD211的全部论文,再次和大家分享~ 一个包放不下,一共分成了3个包,包含百余篇论文,朋友们可以挑选...Online Reorganization in Read Optimized...
文档中提到了访问A&D Service and Support in China的网上课堂,以及相关网站,这些资源为用户提供了进一步的学习和解决PCS7问题的途径。 知识点八:常见问题解答 文档中通过一个实际问题案例,详细介绍了在遇到...
The third edition, consisting of 15 chapters, includes a number of new additions and changes that were incorporated in response to suggestions and requests made by professors, students, and ...
Financial leverage refers to the use of debt financing to amplify the returns on equity, while capital structure encompasses the mix of debt and equity a company employs to fund its operations. ...
- **Online Data and Schema Reorganization**:支持在线数据重组织和模式更改,提高了维护工作的灵活性和效率。 - **Maximum Availability Architecture – Best Practices**:通过最佳实践指南帮助用户构建最高...
This guide to JavaScript builds on the success of previous editions and introduces you to many new advances in JavaScript development. The reorganization of the chapters helps streamline your ...
Today, several methods are available for performing database reorganization and restructuring. Among these methods, reorganization inside the database, using native SQL and PL/SQL scripts, has ...
5. **Library Enhancements and Reorganization:** Many modules were updated, removed, or merged into other packages to improve efficiency and maintainability. In conclusion, Python 3 introduced ...
With these schemes, the pixel division/reorganization is avoided and the encryption/decryption is performed on the cover pixels directly, so that the amount of encrypted data and the computational ...
This book is designed for developers that have to use jPOS for a given project and have to learn how to use it very quickly. Although many old-timers from the financial interchange arena are using ...
- **Clearing and Settlement**: 交易完成后的清算和结算流程,确保资金和证券的正确转移。 最后,证券市场涉及各种参与者: - **Retail/Private Investor**: 个人投资者,通常是散户。 - **Institutional ...
* 表重组时需要使用 /oracle/DEV/sapreorg,必须注意这个目录的大小, Generally being reorganized table size and disk space should be greater than 1:3. * 重组速度大约是 400M/小时。 * 重组的脚本放在/oracle...