如何删除列字段之间的所有空格?空格出现在文本的中间,因此修剪不起作用,并且替换不起作用。 我的代码是
UPDATE temp_emp t1, master_employee t2
SET t1.lm= t2.emp_id
where REPLACE(t1.lm, ' ', '') = REPLACE(CONCAT(t2.first_name,'',t2.last_name), ' ', '');
例如,当我运行查询时,
select REPLACE(lm, ' ', '') AS concat from temp_emp1
我得到如下输出
concat
----------------------------------------
rick joe
james cole
albert Th
我想要输出;像这样
concat
----------------------------------------
rickjoe
jamescole
albertTh
答案 0 :(得分:0)
在不知道表结构和数据的情况下,我很难跟踪你正在做的事情。但是,完成两个连接列的输出非常简单。
假设您有一个只有两列的表master_employee,并且您希望输出连接的FIRST和LAST名称,其间没有空格。您只需使用函数concat()for MySQL:
SELECT CONCAT(first_name, last_name)
from master_employee;
在Oracle中,串联是两个管道(||):
SELECT first_name || last_name
from master_employee;
希望这会有所帮助。
答案 1 :(得分:0)
如果您要将具有多个空格的现有列更新为一个,那么此更新查询将很有帮助:
更新your_table SET column_that_you_want_to_change = REGEXP_REPLACE(column_that_you_want_to_change,'[[:space:]] +','');
如果您不希望有任何空格,那么应该可以:
更新your_table SET column_that_you_want_to_change = REGEXP_REPLACE(column_that_you_want_to_change,'[[:space:]] +','');