Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005
CHAPTER 3 ■ FILES 111 IMPDP, however, just has to apply a simple XML transformation to accomplish the same—FOO, when it refers to a TABLESPACE, would be surrounded by FOO tags (or some other representation). The fact that XML is used has allowed the EXPDP and IMPDP tools to literally leapfrog the old EXP and IMP tools with regard to their capabilities. In Chapter 15, we’ll take a closer look at these tools in general. Before we get there, however, let’s see how we can use this Data Pump format to quickly extract some data from database A and move it to database B. We’ll be using an “external table in reverse” here. External tables, originally introduced in Oracle9i Release 1, gave us the ability to read flat files—plain old text files—as if they were database tables. We had the full power of SQL to process them. They were read-only and designed to get data from outside Oracle in. External tables in Oracle 10g Release 1 and above can go the other way: they can be used to get data out of the database in the Data Pump format to facilitate moving the data to another machine, another platform. To start this exercise, we’ll need a DIRECTORY object, telling Oracle the location to unload to: ops$tkyte@ORA10G> create or replace directory tmp as '/tmp' 2 / Directory created. Next, we’ll unload the data from the ALL_OBJECTS view. It could be from any arbitrary query, involving any set of tables or SQL constructs we want: ops$tkyte@ORA10G> create table all_objects_unload 2 organization external 3 ( type oracle_datapump 4 default directory TMP 5 location( 'allobjects.dat' ) 6 ) 7 as 8 select * from all_objects 9 / Table created. And that literally is all there is to it: we have a file in /tmp named allobjects.dat that contains the contents of the query select * from all_objects. We can peek at this information: ops$tkyte@ORA10G> !head /tmp/allobjects.dat ..........Linuxi386/Linux-2.0.34-8.1.0WE8ISO8859P1.......... 1 0 3 0 WE8ISO8859P1
112 CHAPTER 3 ■ FILES That is just the head, or top, of the file; binary data is represented by the ....... (don’t be surprised if your terminal “beeps” at you when you look at this data). Now, using a binary FTP (same caveat as for a DMP file!), I moved this allobject.dat file to a Windows XP server and created a directory object to map to it: tkyte@ORA10G> create or replace directory TMP as 'c:\temp\' 2 / Directory created. Then I created a table that points to it: tkyte@ORA10G> create table t 2 ( OWNER VARCHAR2(30), 3 OBJECT_NAME VARCHAR2(30), 4 SUBOBJECT_NAME VARCHAR2(30), 5 OBJECT_ID NUMBER, 6 DATA_OBJECT_ID NUMBER, 7 OBJECT_TYPE VARCHAR2(19), 8 CREATED DATE, 9 LAST_DDL_TIME DATE, 10 TIMESTAMP VARCHAR2(19), 11 STATUS VARCHAR2(7), 12 TEMPORARY VARCHAR2(1), 13 GENERATED VARCHAR2(1), 14 SECONDARY VARCHAR2(1) 15 ) 16 organization external 17 ( type oracle_datapump 18 default directory TMP 19 location( 'allobjects.dat' ) 20 ) 21 / Table created. And now I’m able to query the data unloaded from the other database immediately: tkyte@ORA10G> select count(*) from t; COUNT(*) ---------- 48018 That is the power of the Data Pump file format: immediate transfer of data from system to system over “sneaker net” if need be. Think about that the next time you’d like to take a subset of data home to work with over the weekend while testing. One thing that wasn’t obvious here was that the character sets were different between these two databases. If you notice in the preceding head output, the character set of my Linux database WE8ISO8859P1 was encoded into the file. My Windows server has this:
- Page 105 and 106: 60 CHAPTER 2 ■ ARCHITECTURE OVERV
- Page 107 and 108: 62 CHAPTER 2 ■ ARCHITECTURE OVERV
- Page 110 and 111: CHAPTER 3 ■ ■ ■ Files In this
- Page 112 and 113: CHAPTER 3 ■ FILES 67 Without a pa
- Page 114 and 115: CHAPTER 3 ■ FILES 69 and even dat
- Page 116 and 117: CHAPTER 3 ■ FILES 71 all operatio
- Page 118 and 119: CHAPTER 3 ■ FILES 73 *.cluster_da
- Page 120 and 121: CHAPTER 3 ■ FILES 75 ops$tkyte@OR
- Page 122 and 123: CHAPTER 3 ■ FILES 77 • To maint
- Page 124 and 125: CHAPTER 3 ■ FILES 79 • Resource
- Page 126 and 127: CHAPTER 3 ■ FILES 81 3 l_dummy nu
- Page 128 and 129: CHAPTER 3 ■ FILES 83 Trace Files
- Page 130 and 131: CHAPTER 3 ■ FILES 85 _qerixAlloca
- Page 132 and 133: CHAPTER 3 ■ FILES 87 6 ( 7 TYPE O
- Page 134 and 135: CHAPTER 3 ■ FILES 89 A Brief Revi
- Page 136 and 137: CHAPTER 3 ■ FILES 91 Redundant Ar
- Page 138 and 139: CHAPTER 3 ■ FILES 93 (data from m
- Page 140 and 141: CHAPTER 3 ■ FILES 95 dictionary t
- Page 142 and 143: CHAPTER 3 ■ FILES 97 ■Note df i
- Page 144 and 145: CHAPTER 3 ■ FILES 99 “accidenta
- Page 146 and 147: CHAPTER 3 ■ FILES 101 So, at the
- Page 148 and 149: CHAPTER 3 ■ FILES 103 Password Fi
- Page 150 and 151: CHAPTER 3 ■ FILES 105 USER is "SY
- Page 152 and 153: CHAPTER 3 ■ FILES 107 Flashback L
- Page 154 and 155: CHAPTER 3 ■ FILES 109 of the requ
- Page 158 and 159: CHAPTER 3 ■ FILES 113 tkyte@ORA10
- Page 160 and 161: CHAPTER 4 ■ ■ ■ Memory Struct
- Page 162 and 163: CHAPTER 4 ■ MEMORY STRUCTURES 117
- Page 164 and 165: CHAPTER 4 ■ MEMORY STRUCTURES 119
- Page 166 and 167: CHAPTER 4 ■ MEMORY STRUCTURES 121
- Page 168 and 169: CHAPTER 4 ■ MEMORY STRUCTURES 123
- Page 170 and 171: CHAPTER 4 ■ MEMORY STRUCTURES 125
- Page 172 and 173: CHAPTER 4 ■ MEMORY STRUCTURES 127
- Page 174 and 175: CHAPTER 4 ■ MEMORY STRUCTURES 129
- Page 176 and 177: CHAPTER 4 ■ MEMORY STRUCTURES 131
- Page 178 and 179: CHAPTER 4 ■ MEMORY STRUCTURES 133
- Page 180 and 181: CHAPTER 4 ■ MEMORY STRUCTURES 135
- Page 182 and 183: CHAPTER 4 ■ MEMORY STRUCTURES 137
- Page 184 and 185: CHAPTER 4 ■ MEMORY STRUCTURES 139
- Page 186 and 187: CHAPTER 4 ■ MEMORY STRUCTURES 141
- Page 188 and 189: CHAPTER 4 ■ MEMORY STRUCTURES 143
- Page 190 and 191: CHAPTER 4 ■ MEMORY STRUCTURES 145
- Page 192 and 193: CHAPTER 4 ■ MEMORY STRUCTURES 147
- Page 194 and 195: CHAPTER 4 ■ MEMORY STRUCTURES 149
- Page 196 and 197: CHAPTER 4 ■ MEMORY STRUCTURES 151
- Page 198 and 199: CHAPTER 4 ■ MEMORY STRUCTURES 153
- Page 200 and 201: CHAPTER 5 ■ ■ ■ Oracle Proces
- Page 202 and 203: CHAPTER 5 ■ ORACLE PROCESSES 157
- Page 204 and 205: CHAPTER 5 ■ ORACLE PROCESSES 159
112<br />
CHAPTER 3 ■ FILES<br />
That is just the head, or top, of the file; binary data is represented by the ....... (don’t be<br />
surprised if your terminal “beeps” at you when you look at this data). Now, using a binary FTP<br />
(same caveat as for a DMP file!), I moved this allobject.dat file to a Windows XP server <strong>and</strong><br />
created a directory object to map to it:<br />
tkyte@ORA10G> create or replace directory TMP as 'c:\temp\'<br />
2 /<br />
Directory created.<br />
Then I created a table that points to it:<br />
tkyte@ORA10G> create table t<br />
2 ( OWNER VARCHAR2(30),<br />
3 OBJECT_NAME VARCHAR2(30),<br />
4 SUBOBJECT_NAME VARCHAR2(30),<br />
5 OBJECT_ID NUMBER,<br />
6 DATA_OBJECT_ID NUMBER,<br />
7 OBJECT_TYPE VARCHAR2(19),<br />
8 CREATED DATE,<br />
9 LAST_DDL_TIME DATE,<br />
10 TIMESTAMP VARCHAR2(19),<br />
11 STATUS VARCHAR2(7),<br />
12 TEMPORARY VARCHAR2(1),<br />
13 GENERATED VARCHAR2(1),<br />
14 SECONDARY VARCHAR2(1)<br />
15 )<br />
16 organization external<br />
17 ( type oracle_datapump<br />
18 default directory TMP<br />
19 location( 'allobjects.dat' )<br />
20 )<br />
21 /<br />
Table created.<br />
And now I’m able to query the data unloaded from the other database immediately:<br />
tkyte@ORA10G> select count(*) from t;<br />
COUNT(*)<br />
----------<br />
48018<br />
That is the power of the Data Pump file format: immediate transfer of data from system to<br />
system over “sneaker net” if need be. Think about that the next time you’d like to take a subset<br />
of data home to work with over the weekend while testing.<br />
One thing that wasn’t obvious here was that the character sets were different between<br />
these two databases. If you notice in the preceding head output, the character set of my Linux<br />
database WE8ISO8859P1 was encoded into the file. My Windows server has this: