Oracle 10 Gb provides a way to use external tables to extract data.
First, you need a directory (here we will continue to use the previously created directory)
- SQL> showUser
- USERIs"SYS"
- SQL>Select*FromDba_directoriesWhereDIRECTORY_NAMELike '% SYS %';
- OWNER DIRECTORY_NAME DIRECTORY_PATH
- --------------------------------------------------------------------------------------------------------------
- SYS SYS_SQLLDR_XT_TMPDIR_00000/u01/sqlldr
Then execute the command
- SQL> showUser
- USERIs"ING"
- SQL>DescSYS_SQLLDR_X_EXT_DEPT
- Is the name empty? Type
- -----------------------------------------------------------------------------
- Deptno number (10)
- DNAME VARCHAR2 (20)
- LOC VARCHAR2 (20)
- SQL>Create TableSYS_SQLLDR_X_EXT_DEPT_UNLOAD
- 2 organization external
- 3 (type oracle_datapump
- 4DefaultDirectory SYS_SQLLDR_XT_TMPDIR_00000
- 5 location ('Sys _ SQLLDR_X_EXT_DEPT_UNLOAD.dat')
- 6)As
- 7Select*FromSYS_SQLLDR_X_EXT_DEPT;
- The table has been created.
A SYS_SQLLDR_X_EXT_DEPT_UNLOAD table will be created in the database. Two more files will be created in the directory.
- [Oracle @ linux sqlldr] $ ll | grep SYS
- -Rw-r-- R -- 1 oracle oinstall 148 10-04 SYS_SQLLDR_X_EXT_DEPT_UNLOAD_3501.log
- -Rw-r----- 1 oracle oinstall 12288 10-04 SYS_SQLLDR_X_EXT_DEPT_UNLOAD.dat
Finally, copy the SYS_SQLLDR_X_EXT_DEPT_UNLOAD.dat file to the corresponding directory of other databases, and extract the External table creation script.
- SQL>SetLong 1, 20000
- SQL>SetPagesize 99
- SQL>SelectDbms_metadata.get_ddl ('Table','Sys _ SQLLDR_X_EXT_DEPT_UNLOAD')FromDual;
- DBMS_METADATA.GET_DDL ('Table','Sys _ SQLLDR_X_EXT_DEPT_UNLOAD')
- --------------------------------------------------------------------------------
- CREATE TABLE "ING"."SYS_SQLLDR_X_EXT_DEPT_UNLOAD"
- ("DEPTNO"NUMBER (10, 0 ),
- "DNAME"VARCHAR2 (20 ),
- "LOC"VARCHAR2 (20)
- )
- ORGANIZATION EXTERNAL
- (TYPE ORACLE_DATAPUMP
- DEFAULTDIRECTORY"SYS_SQLLDR_XT_TMPDIR_00000"
- LOCATION
- ('Sys _ SQLLDR_X_EXT_DEPT_UNLOAD.dat'
- )
- )
You can even load data directly from an outsourcing table.
- SQL>Insert/* + Append */IntoDeptSelect*FromSYS_SQLLDR_X_EXT_DEPT_UNLOAD;
- Four rows have been created.
- SQL>Commit;
- Submitted.
- SQL>Select*FromDept;
- DEPTNO DNAME LOC
- --------------------------------------------------
- 50 Sales Virginia
- 60 Accounting Virginia
- 70 Consulting Virginia
- 80 Finance Virginia