Oracle Database Administration/Moving Data
< Oracle Database Administration
This lesson introduces moving data.
Objectives and Skills
Objectives and skills for the moving portion of Oracle Database Administration I certification include:[1]
- Moving Data
- Describe and use methods to move data (Directory objects, SQL*Loader, External Tables)
- Explain the general architecture of Oracle Data Pump
- Use Data Pump Export and Import to move data between Oracle databases
Readings
Multimedia
Activities
SQL*Loader
- Use SQL*Loader.
- Create a text file with the following information. Save the file as
regions.txt.ID, REGION101, Eastern Europe102, Western Europe103, North America104, Central America105, South America106, Central Asia107, Eastern Asia108, Southern Asia109, Southeastern Asia110, Western Asia111, Eastern Africa112, Central Africa113, Northern Africa114, Southern Africa115, Western Africa - Create an SQL*Loader control file with the following information. Save the file as
regions.ctl.OPTIONS (SKIP=1)LOAD DATAINFILE 'regions.txt'BADFILE 'regions.bad'DISCARDFILE 'regions.dsc'APPENDINTO TABLE HR.REGIONSFIELDS TERMINATED BY ','TRAILING NULLCOLS(REGION_ID INTEGER EXTERNAL(3),REGION_NAME) - Use SQL*Loader to load the data using the following command:
sqlldr userid=system/<password> control=regions.ctl - Verify the import using the following query:
SELECT * FROM HR.REGIONS - Clean up using the following query:
DELETE FROM HR.REGIONS WHERE REGION_ID >= 101;
- Create a text file with the following information. Save the file as
External Tables
- Use an external table.
- Create a directory object pointing to an existing operating system directory using the following query:
CREATE DIRECTORY external_files AS '<path>'; - Put the
regions.txttext file from above in the specified directory. - Create an external table referencing the text file using the following query:
CREATE TABLE HR.REGIONS_FILE(REGION_ID NUMBER(3),REGION_NAME VARCHAR2(25))ORGANIZATION EXTERNAL(TYPE ORACLE_LOADERDEFAULT DIRECTORY external_filesACCESS PARAMETERS(RECORDS DELIMITED BY NEWLINESKIP 1FIELDS TERMINATED BY ',')LOCATION ('regions.txt')) - Select data from the external table using the following query:
SELECT * FROM HR.REGIONS_FILE - Use the following query to load the data into the REGIONS table:
INSERT INTO HR.REGIONS(REGION_ID, REGION_NAME)(SELECT REGION_ID, REGION_NAME FROM HR.REGIONS_FILE); - Verify the import using the following query:
SELECT * FROM HR.REGIONS - Clean up using the following queries:
DELETE FROM HR.REGIONS WHERE REGION_ID >= 101;DROP TABLE HR.REGIONS_FILE;DROP DIRECTORY external_files;
- Create a directory object pointing to an existing operating system directory using the following query:
Spool
- Use spool to export a comma-separated-values copy of the REGIONS table.
- Review Charito: How to Write to a CSV File Using Oracle SQL*Plus.
- Use SQL*PLUS and run the following commands:
set colsep ,set pagesize 0set trimspool onspool regions.csvSELECT * FROM HR.REGIONS;spool off - Exit SQL*PLUS and list the files in the current directory (DIR or LS). Open the regions.csv file and view the results.
SQL Developer
- Use SQL Developer to export a comma-separated-values copy of the REGIONS table.
- Review Oracle: Using SQL Developer for Importing and Exporting.
- Follow the instructions for the Oracle: Example: Exporting Data to a Microsoft Excel File
Oracle Data Pump
- Identify the data pump directory using the following query:
SELECT * FROM DBA_DIRECTORIES; - Use Enterprise Manager Data Pump Export.
- Use Enterprise Manager Database Control / Data Movement / Export to Export Files to export the HR.REGIONS table.
- Navigate to the directory specified in the export and open the exported file using a text editor. Observe the file format and contents.
- Use command-line Data Pump Export.
- Use the following command to export the HR schema:
expdp system/<password> schemas=hr dumpfile=hr.dmp
- Use the following command to export the HR schema:
- Use command-line Data Pump Import.
- Use the following command to import HR.REGIONS into the OE schema:
impdp system/<password> dumpfile=hr.dmp remap_schema=hr:oe tables=hr.regions - Use the following query to verify the import:
SELECT * FROM OE.REGIONS; - use the following query to clean up the import:
DROP TABLE OE.REGIONS;
- Use the following command to import HR.REGIONS into the OE schema: