首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sqoop:从MySQL导入到配置单元时替换字符?

Sqoop:从MySQL导入到配置单元时替换字符?
EN

Stack Overflow用户
提问于 2014-03-18 15:49:00
回答 2查看 3.4K关注 0票数 1

当从MySQL导入数据到配置单元时,我需要在电话号码中删除两个字符的+7。以下请求返回SQL错误。我应该使用的正确replace命令是什么?

sqoop import --connect jdbc:mysql://server/db --username xxxx --password yyyy --query 'select name, last_name, email, second_name, Replace(personal_phone, '+7', ''), Replace(mobile, '+7', ''), Replace(phone, '+7', '') from user where $CONDITIONS' --target-dir /data/test -m 1 --null-string '\\N' --null-non-string '\\N' --hive-import --hive-table user_inf

EN

回答 2

Stack Overflow用户

发布于 2014-03-18 20:37:18

这一条对我很有效:

sqoop import --connect jdbc:mysql://server/db --username xxxx --password yyyy --query "select name, last_name, email, second_name, Replace(phone, "+7", '') as phone, Replace(mobile, "+7", '') as mobile from test where \$CONDITIONS" --target-dir /data/test -m 1 --null-string '\\N' --null-non-string '\\N' --hive-import --hive-table info

票数 1
EN

Stack Overflow用户

发布于 2014-03-18 15:57:55

REPLACE命令看起来是正确的。错误可能是由于引号导致的,因为您在开头使用了单引号。在SQL查询中,我已将其更改为双引号。它现在应该可以工作了:

sqoop import --connect jdbc:mysql://server/db --username xxxx --password yyyy --query "select name, last_name, email, second_name, Replace(personal_phone, '+7', ''), Replace(mobile, '+7', ''), Replace(phone, '+7', '') from user where $CONDITIONS" --target-dir /data/test -m 1 --null-string '\\N' --null-non-string '\\N' --hive-import --hive-table user_inf

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22473221

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档