|ERROR|ERROR: missing data for column "createtime" (seg3 slice1 192.168.66.23:40001 pid=33370)之mysql换行符或者空格引起的问题

1、最近的kettle的数据交换配置,启动kettle引起的错误,如下所示:

1 |ERROR|ERROR:  missing data for column "createtime"  (seg3 slice1 192.168.66.23:40001 pid=33370)

 引发这个错误,并不是这个字段引起的错误,一般是这个字段临近的字段存在空格或者换行符引发的错误。

2、引发这个错误,并不是这个字段引起的错误,一般是这个字段临近的字段存在空格或者换行符引发的错误。为了问题重现,我新建一个数据库和数据表:

3、准备插入的正常数据,可以执行多条插入数据:

1 insert into user(name,age,birthday,sex) VALUES("张三",22,"2018-08-20","");
2 insert into user(name,age,birthday,sex) VALUES("李四",21,"2018-8-20","");
3 insert into user(name,age,birthday,sex) VALUES("王五",18,"2018-8-20","");
4 insert into user(name,age,birthday,sex) VALUES("赵六",19,"2018-8-20","");
5 insert into user(name,age,birthday,sex) VALUES("李白",20,"2018-8-20","");
6 insert into user(name,age,birthday,sex) VALUES("安琪拉",43,"2018-8-20","");
7 insert into user(name,age,birthday,sex) VALUES("亚瑟",32,"2018-8-20","");
8 insert into user(name,age,birthday,sex) VALUES("鲁班",14,"2018-8-20","");

然后执行查询结果是没有查询结果的:

CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串。

4、然后插入一条换行的数据:

换行的数据可以如下所示造几条,这里造一条。

然后执行

insert into user(name,age,birthday,sex) VALUES("后
裔",14,"2018-8-20","男");

5、然后可以看到已经查询出来了这条换行的数据。

6、mysql函数。replace(string_expression , string_pattern , string_replacement),第一个参数:要查找的字段。第二个参数:要查找的字符。第三个参数:要替换成的字符。char(10)换行键。char(13)回车键。你会发现字段名称like 的concat里面是char(10)和char(13)都可以进行查询出结果的。

7、我要的结果就是将带有换行和回车的字符处理掉,然后执行交换。其他使用情况以后用到再贴。

8、最后说一下,这里是name的字段,本不该出现回车和换行符的,如果是其他长文本字段,可以使用如下命令:

1 -- 将char(10)换行键,char(13)回车键换成@#r;和@#n;
2 select REPLACE(REPLACE(name, char(10), '@#r;'), char(13), '@#n;') as name from user where name like CONCAT("%",char(13),"%")
3 
4 -- 将@#r;和@#换成nchar(10)换行键,char(13)回车键;
5 select REPLACE(REPLACE(name, '@#r;', char(10)), '@#n;', char(13)) as name from user where name like CONCAT("%",char(13),"%")

待续......

原文地址:https://www.cnblogs.com/biehongli/p/9506507.html