Sie sind auf Seite 1von 2

CREATE TABLE emp (

empno
NUMBER(4) NOT NULL CONSTRAINT emp_pk PRIMARY KEY,
ename
VARCHAR2(10),
job
VARCHAR2(9),
mgr
NUMBER(4),
hiredate
DATE,
sal
NUMBER(7,2) CONSTRAINT emp_sal_ck CHECK (sal > 0),
comm
NUMBER(7,2),
deptno
NUMBER(2)
)
PARTITION BY RANGE (deptno)
(PARTITION employees_part1 VALUES LESS THAN (11) ,
PARTITION employees_part2 VALUES LESS THAN (21) ,
PARTITION employees_part3 VALUES LESS THAN (31) );
update emp set deptno=20 where deptno=30;
update emp partition(employees_part3) set deptno=20; will cause the following er
ror:
ORA-14402: updating partition key column would cause a partition change
An UPDATE statement attempted to change the value of a partition
key column causing migration of the row to another partition
Solution:
alter table emp ENABLE ROW MOVEMENT;
to compress the table rows into less data blocks, and Oracle moves down the high
water mark to release the space. This makes full-table scans run faster. Flashb
ack table - Using the flashback table features requires "enable row movement".
To Update a partiton key value and to flashback the data.

Now update will works fine and data will be noved to other partiton:
Move = Delete from current + Insert into other
update emp set deptno=21 where deptno=30; This works fine and changes the rowid.
later operation will move the data into corrosponding partiitons.
Note: you're not just updating a single column and leaving the row in place, you
're actually moving the row to a new block. You're also requiring that two parti
tions of every local index be modified .
if any partition is used we can see it in PLAN_TABLE under operation/options col
umns or PARTITION_START/PARTITION _STOP Columns.
Partition pruning is an essential performance feature for data warehouses. In pa
rtition pruning, the optimizer analyzes FROM and WHERE clauses in SQL statements
to eliminate unneeded partitions when building the partition access list. This
functionality enables Oracle Database to perform operations only on those partit
ions that are relevant to the SQL statement.
Partition pruning dramatically reduces the amount of data retrieved from disk an
d shortens processing time, thus improving query performance and optimizing reso
urce utilization.

For many cases, Oracle determines the partitions to be accessed at compile time.
Static partition pruning occurs if you use static predicates, except for the fo
llowing cases:
Partition pruning occurs using the result of a subquery.
The optimizer rewrites the query with a star transformation and pruning occurs af
ter the star transformation.
The most efficient execution plan is a nested loop.
The Query uses bind variables.

If You want to do the exchange partition the following should be met:


1.
The destination table should have partitions(TB_TEMP).
2.
The Source table shouldn t have partitions(TB_ORIG). It should be a non-c
lustered and non-partitioned table.
For your questions:
1.
Yes it must swap the data to destination table/partition.
2.
You have partition on source table but on the destination table. That is
why you are not able to see any partition on TB_TEMP.
3.
Exchange partition is to copy/swap the data from a non-partitioned table
to the partition table, in simple terms to partition the existing table, which
can be used later to split into multiple partitions or add more partitions.
Eg:
create table emp_temp partition by range(deptno) (partition emp_part1 values les
s than(maxvalue)) as select * from emp; -- An empty table with a partition
create table emp_temp1 as select * from emp; -- Source table with out partition
alter table emp_temp exchange partition emp_part1 with table emp_temp1 without v
alidation; -- exchanging data with dest table using parttion
drop the original table and rename the dest table as original table.
ALTER TABLE emp_temp SPLIT PARTITION emp_temp1 AT (30)
INTO (PARTITION my_table_part_1,
PARTITION my_table_part_2);
EXEC DBMS_STATS.gather_table_stats(USER, 'MY_TABLE', cascade => TRUE);

-- To retirve the data deleted by mistake


FLASHBACK TABLE EMP TO TIMESTAMP (SYSTIMESTAMP - INTERVAL '05' minute);
**Truncated data cannot be recollcted.

Das könnte Ihnen auch gefallen