Sample Data Preparation
Create a Dept table in Hive
Create Table int by ' \ t ' by ' \ n ' as Textfile;
Import data:
-- Connect JDBC:ORACLE:THIN:@192.168.1.107:1521:ORCL \ -- username SCOTT--password Tiger \ -- table DEPT \--hive-overwrite--hive-import --hive-table DEPT \-- fields-terminated-by ' \ t '--lines-terminated-by ' \ n ' \ - 3;
Hive Export to Oracle
Two steps are required:
First step: Write to HDFs first
Insert ' /user/hadoop/dept_hive_export ' Select * from Dept;
Step two: Export from HDFs to Oracle
When exporting to a database, make sure that the table already exists in the database, or error.
Create TableDept_demo as Select * fromDEPTwhere 1=2;
Sqoop Export--Connect JDBC:ORACLE:THIN:@192.168.1.107:1521:ORCL \--username SCOTT--password Tiger \--table Dept_demo \-- export-dir/user/hadoop/dept_hive_export \-- fields-terminated-by ' \001 ' \-M2;
Note: the delimiter exported from hive to HDFs is not, but \001, if no delimiter is specified: caused by:java.lang.NumberFormatException