標籤:style blog color java io strong 資料 for
樣本資料準備
hive中建立dept表
create table dept(deptno int,dname string,loc string)row format delimited fields terminated by ‘\t‘ lines terminated by ‘\n‘ stored as textfile;
匯入資料:
sqoop import --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‘ \-m 3;
HIVE匯出到ORACLE
需要分兩步:
第一步:先寫入到hdfs
insert overwrite directory ‘/user/hadoop/DEPT_HIVE_EXPORT‘ select * from dept;
第二步:由hdfs匯出到oracle
匯出到資料庫時,要確保表已經在資料庫中存在,否則報錯。
create table DEPT_DEMO as select * from DEPT where 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‘ \-m 2;
註:從hive匯出到hdfs的分隔字元不是,而是\001;如果不指定分隔字元,則報錯:Caused by: java.lang.NumberFormatException