测试环境是:DB: 11.2.0.3 ,10.2.0.4 OS:RHEL 4.8

   把10G中的stored outline数据迁移到11G中

1,导出测试表中的数据

 
  
  1. [oracle10g@rhel4 sql]$ expdp  scott/oracle tables=test1  directory=test dumpfile=test1.dmp; 
  2.  
  3. Export: Release 10.2.0.4.0 - 64bit Production on Saturday, 06 April, 2013 21:14:00 
  4.  
  5. Copyright (c) 2003, 2007, Oracle.  All rights reserved. 
  6.  
  7. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production 
  8. With the Partitioning, OLAP, Data Mining and Real Application Testing options 
  9. Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** tables=test1 directory=test dumpfile=test1.dmp  
  10. Estimate in progress using BLOCKS method... 
  11. Processing object type TABLE_EXPORT/TABLE/TABLE_DATA 
  12. Total estimation using BLOCKS method: 2.875 GB 
  13. Processing object type TABLE_EXPORT/TABLE/TABLE 
  14. Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX 
  15. Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS 
  16. Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS 
  17. . . exported "SCOTT"."TEST1"                             4.636 MB   50091 rows 
  18. Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded 
  19. ****************************************************************************** 
  20. Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is: 
  21.   /tmp/test1.dmp 
  22. Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 21:14:18 

2,导出stored outline,name为new_outline_1

 
  
  1. [oracle10g@rhel4 tmp]$ expdp outln/oracle directory=test TABLES=(OL\$,OL\$HINTS,OL\$NODES) dumpfile=outln.dmp  parfile=query.par 
  2.  
  3. Export: Release 10.2.0.4.0 - 64bit Production on Saturday, 06 April, 2013 21:46:18 
  4.  
  5. Copyright (c) 2003, 2007, Oracle.  All rights reserved. 
  6.  
  7. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production 
  8. With the Partitioning, OLAP, Data Mining and Real Application Testing options 
  9. Starting "OUTLN"."SYS_EXPORT_TABLE_02":  outln/******** directory=test TABLES=(OL$,OL$HINTS,OL$NODES) dumpfile=outln.dmp parfile=query.par  
  10. Estimate in progress using BLOCKS method... 
  11. Processing object type TABLE_EXPORT/TABLE/TABLE_DATA 
  12. Total estimation using BLOCKS method: 640 KB 
  13. Processing object type TABLE_EXPORT/TABLE/TABLE 
  14. Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT 
  15. Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX 
  16. Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS 
  17. Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS 
  18. Processing object type TABLE_EXPORT/TABLE/POST_TABLE_ACTION 
  19. . . exported "OUTLN"."OL$HINTS"                          11.59 KB       5 rows 
  20. . . exported "OUTLN"."OL$"                               9.070 KB       1 rows 
  21. . . exported "OUTLN"."OL$NODES"                          7.078 KB       1 rows 
  22. Master table "OUTLN"."SYS_EXPORT_TABLE_02" successfully loaded/unloaded 
  23. ****************************************************************************** 
  24. Dump file set for OUTLN.SYS_EXPORT_TABLE_02 is: 
  25.   /tmp/outln.dmp 
  26. Job "OUTLN"."SYS_EXPORT_TABLE_02" successfully completed at 21:46:23 
  27.  
  28. [oracle10g@rhel4 tmp]$ cat query.par 
  29. query=ol$:"where ol_name=upper('new_outline_1')",OL$HINTS:"where ol_name=upper('new_outline_1')",OL$NODES:"where ol_name=upper('new_outline_1')" 
  30. [oracle10g@rhel4 tmp]$  

3,把测试数据导入到11G SCOTT用户下面

 
  
  1. [oracle11g@rhel4 sql]$ impdp scott/oracle directory=dump dumpfile=test1.dmp TABLE_EXISTS_ACTION=append logfile=imdp.log 
  2.  
  3. Import: Release 11.2.0.3.0 - Production on Sat Apr 6 21:51:08 2013 
  4.  
  5. Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved. 
  6.  
  7. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production 
  8. With the Partitioning, OLAP, Data Mining and Real Application Testing options 
  9. Master table "SCOTT"."SYS_IMPORT_FULL_01" successfully loaded/unloaded 
  10. Starting "SCOTT"."SYS_IMPORT_FULL_01":  scott/******** directory=dump dumpfile=test1.dmp TABLE_EXISTS_ACTION=append logfile=imdp.log  
  11. Processing object type TABLE_EXPORT/TABLE/TABLE 
  12. Processing object type TABLE_EXPORT/TABLE/TABLE_DATA 
  13. . . imported "SCOTT"."TEST1"                             4.636 MB   50091 rows 
  14. Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX 
  15. Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS 
  16. Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS 
  17. Job "SCOTT"."SYS_IMPORT_FULL_01" successfully completed at 21:51:12 

4,把stored outline数据导入到11G OUTLN用户中

 
  
  1. [oracle11g@rhel4 sql]$ impdp outln/oracle directory=dump dumpfile=outln.dmp TABLE_EXISTS_ACTION=append 
  2.  
  3. Import: Release 11.2.0.3.0 - Production on Sat Apr 6 21:51:52 2013 
  4.  
  5. Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved. 
  6.  
  7. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production 
  8. With the Partitioning, OLAP, Data Mining and Real Application Testing options 
  9. Master table "OUTLN"."SYS_IMPORT_FULL_01" successfully loaded/unloaded 
  10. Starting "OUTLN"."SYS_IMPORT_FULL_01":  outln/******** directory=dump dumpfile=outln.dmp TABLE_EXISTS_ACTION=append  
  11. Processing object type TABLE_EXPORT/TABLE/TABLE 
  12. Table "OUTLN"."OL$" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append 
  13. Table "OUTLN"."OL$NODES" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append 
  14. Table "OUTLN"."OL$HINTS" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append 
  15. Processing object type TABLE_EXPORT/TABLE/TABLE_DATA 
  16. . . imported "OUTLN"."OL$HINTS"                          11.59 KB       5 rows 
  17. . . imported "OUTLN"."OL$"                               9.070 KB       1 rows 
  18. . . imported "OUTLN"."OL$NODES"                          7.078 KB       1 rows 
  19. Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT 
  20. Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX 
  21. Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS 
  22. Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS 
  23. Processing object type TABLE_EXPORT/TABLE/POST_TABLE_ACTION 
  24. Job "OUTLN"."SYS_IMPORT_FULL_01" successfully completed at 21:52:00 
  25.  
  26.  
  27. 查看是否已经生成new_outline_1 
  28. SQL> @sql_outline 
  29. Wrote file sqlplusset 
  30.  
  31. CATEGORY 
  32. --------------- 
  33. DEFAULT 
  34. Enter value for owner: scott 
  35. Enter value for category: default 
  36. Enter value for used:  
  37.  
  38.                                                                      CREATE 
  39. NAME                          OWNER           CATEGORY        USED   TIME     COMPATIBLE   ENABLED  FORMAT SQL_TEXT 
  40. ----------------------------- --------------- --------------- ------ -------- ------------ -------- ------ ---------------------------------------------------------------------- 
  41. NEW_OUTLINE_1                 SCOTT           DEFAULT         USED   13 04-06 COMPATIBLE   ENABLED  NORMAL select /*+ full(t)*/ count(*) from test1 t where object_id=1 

5,测试是否生产

 
  
  1. 修改参数 
  2. SQL> ALTER SYSTEM SET USE_STORED_OUTLINES = TRUE
  3.  
  4. System altered. 
  5.  
  6. SQL> conn scott/oracle 
  7. Connected. 
  8. SQL> set autotrace traceonly; 
  9. 测试是否生效 
  10. SQL> select /*+ full(t)*/ count(*) from test1 t where object_id=1
  11.  
  12.  
  13. Execution Plan 
  14. ---------------------------------------------------------- 
  15. Plan hash value: 4017242292 
  16.  
  17. ------------------------------------------------------------------------------ 
  18. | Id  | Operation         | Name     | Rows  | Bytes | Cost (%CPU)| Time     | 
  19. ------------------------------------------------------------------------------ 
  20. |   0 | SELECT STATEMENT  |          |     1 |     3 |     1   (0)| 00:00:01 | 
  21. |   1 |  SORT AGGREGATE   |          |     1 |     3 |            |          | 
  22. |*  2 |   INDEX RANGE SCAN| TEST1_ID |     1 |     3 |     1   (0)| 00:00:01 | 
  23. ------------------------------------------------------------------------------ 
  24.  
  25. Predicate Information (identified by operation id): 
  26. --------------------------------------------------- 
  27.  
  28.    2 - access("OBJECT_ID"=1) 
  29.  
  30. Note 
  31. ----- 
  32.    - outline "NEW_OUTLINE_1" used for this statement 
  33.  
  34.  
  35. Statistics 
  36. ---------------------------------------------------------- 
  37.         222  recursive calls 
  38.         130  db block gets 
  39.         199  consistent gets 
  40.           2  physical reads 
  41.         116  redo size 
  42.         526  bytes sent via SQL*Net to client 
  43.         520  bytes received via SQL*Net from client 
  44.           2  SQL*Net roundtrips to/from client 
  45.          27  sorts (memory) 
  46.           0  sorts (disk) 
  47.           1  rows processed 
  48.  
  49. 已经成功