简体   繁体   中英

How to import selective rows from a table into an oracle database?

I have a database which has a table named 'X' and I have another database which is almost similar to the database 'X' (having exactly same tables and the schema of all tables also being same). Only data in the tables are different. Now I want to copy a few selective rows from a table. Is there a provision by which I can put a 'where' clause in the import statement so that only those rows are imported which satisfy the 'where' condition.

Yeah sure we can do it..See below its just an example

INSERT INTO destTable
SELECT Field1,Field2,Field3,... 
FROM srcTable
WHERE NOT EXISTS(SELECT * 
                 FROM destTable 
                 WHERE (srcTable.Field1=destTable.Field1 and
                       SrcTable.Field2=DestTable.Field2...etc.)
                 )

You can use the optional QUERY parameter to exp, eg:

exp scott/tiger TABLES=emp QUERY=\"WHERE job=\'SALESMAN\' and sal \<1600\"

http://docs.oracle.com/cd/B28359_01/server.111/b28319/exp_imp.htm#i1005842

I don't think you can filter it on import, though. You could import into a staging schema, then copy the data across with SQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM