Saturday, July 12, 2008

Using import and export command on oracle.

to export and import one schema to another schema.(All schemas should be present already. It will not create new schema, it will create only schema objects and fill their data into objects.)

1. open cmd and type
EXP {schema you want to export from} FILE=exp_database.dmp COMPRESS=N CONSISTENT=N CONSTRAINTS=Y GRANTS=Y INDEXES=Y RECORD=Y ROWS=Y Feedback=1000 LOG=exp_database.log

for example
EXP ahsan_apr/welcome@adapp FILE=exp_database.dmp COMPRESS=N CONSISTENT=N CONSTRAINTS=Y GRANTS=Y INDEXES=Y RECORD=Y ROWS=Y Feedback=1000 LOG=exp_database.log

This will export all tables to a new dump file called exp_database.dmp

To export the selected tables to dump file
EXP {schema you want to export from} FILE=exp_database.dmp tables=TFR_MEDIA_DIM,TFR_SITE_DIM COMPRESS=N CONSISTENT=N CONSTRAINTS=Y GRANTS=Y INDEXES=Y RECORD=Y ROWS=Y Feedback=1000 LOG=exp_database.log

This will export selected tables TFR_MEDIA_DIM and TFR_SITE_DIM to a new dump file called exp_database.dmp

To export only a subset of rows use
EXP {schema you want to export from} FILE=exp_database.dmp tables=TFR_MEDIA_DIM COMPRESS=N CONSISTENT=N CONSTRAINTS=Y GRANTS=Y INDEXES=Y RECORD=Y ROWS=Y Feedback=1000 LOG=exp_database.log QUERY=\"WHERE id \> 13\".

Make sure you escape special char properly with \ because this will be translated into
SELECT * FROM TFR_MEDIA_DIM WHERE id > 13

2. open cmd and type
IMP userid={schema you want to import data to} fromuser={schema you exported data from} touser={schema you want to import data to} file=exp_database.dmp

for example
IMP userid=ahsan_report/welcome@orcl fromuser=ahsan_apr touser=ahsan_report file=exp_database.dmp

Sphere: Related Content

0 comments: