示例数据准备
hive中创建dept表
create table dept( deptno int, dname string, loc string ) row format delimited fields terminated by ' ' lines terminated by ' ' 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 ' ' --lines-terminated-by ' ' -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 ' 01' -m 2;
注:从hive导出到hdfs的分隔符不是,而是 01;如果不指定分隔符,则报错:Caused by: java.lang.NumberFormatException