6

我有一个表女巫包含许多名称,格式如下:

Max.Example

我想更换 . 有一个空间,但我不小心把它换成了什么,所以它们都像:MaxMuster

我无法恢复备份或回滚。我发现的唯一方法是在大写字母之后的任何地方插入一个空格。但是,它的命令是什么?

4

6 回答 6

2

试试这个程序...

create procedure updateName()
begin
  declare cnt, len, val, flag int;
  declare newName, oldName varchar(30);
  select count(*) into cnt from tbl;
  set cnt =cnt-1;
  while cnt >= 0 do
     set flag=0;
     select details into oldName from tbl limit cnt, 1;
     select length(oldname) into len;
     while flag=0 and len > 0 do
        select ascii(substring(oldname, len)) into val;
        if val < 90 then 
          select concat(substring(oldname, 1, len-1), ' ', substring(oldname,len)) into newname;
          update tbl set details = newName where details  = oldname;
          set flag=1;
        end if;
        set len = len - 1;
     end while;
     set cnt = cnt-1;
  end while;

end//

小提琴

编辑

For multiple caps char 解决多个大写字符的问题

create procedure updateName()
begin
  declare cnt, len, val, flag int;
  declare newName, oldName varchar(30);
  select count(*) into cnt from tbl;
  set cnt =cnt-1;
  while cnt >= 0 do
     set flag=0;
     select details into oldName from tbl limit cnt, 1;
     select length(oldname) into len;
     while len > 1 do
        select ascii(substring(oldname, len)) into val;
        if val < 90 then 
          select concat(substring(oldname, 1, len-1), ' ', substring(oldname,len)) into newname;
          update tbl set details = newName where details  = oldname;
          set oldname=newname;
        end if;
        set len = len - 1;
     end while;
     set cnt = cnt-1;
  end while;

end//

小提琴

在运行此过程之前备份您的表..

希望这可以帮助....

于 2013-05-30T10:54:38.500 回答
2

这是一种蛮力方法:

select ltrim(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(myColumn
                     ,'A',' A')
                     ,'B',' B')
                     ,'C',' C')
                     ,'D',' D')
                     ,'E',' E')
                     ,'F',' F')
                     ,'G',' G')
                     ,'H',' H')
                     ,'I',' I')
                     ,'J',' J')
                     ,'K',' K')
                     ,'L',' L')
                     ,'M',' M')
                     ,'N',' N')
                     ,'O',' O')
                     ,'P',' P')
                     ,'Q',' Q')
                     ,'R',' R')
                     ,'S',' S')
                     ,'T',' T')
                     ,'U',' U')
                     ,'V',' V')
                     ,'W',' W')
                     ,'X',' X')
                     ,'Y',' Y')
                     ,'Z',' Z')
            )
from myTable
于 2013-05-30T11:01:31.473 回答
1

这是一种不同的方法。将 UNION 查询增强到您列的最大长度。它也有改进的空间。

select details, group_concat(t2.c1) as new_value  from (

Select details, 
case 
  when n = 1 then substr(details,n,1)
  when ascii(substr(details,n,1)) between ascii ('A') and ascii ('Z') 
      then concat (' ', substr(details,n,1))
  else substr(details,n,1)
end as c1

,n
FROM tbl, 

  (select 1 as n union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7 union all
select 8 union all
select 9 union all
select 10
    )
  as tbl_1 

where substr(details,n,1) is not null

) as t2
group by details
于 2013-05-30T12:53:25.170 回答
1

我根据 Mark Ba​​nnister 的 Bruteforce 脚本找到了答案

UPDATE TABLE
SET COLUMN = ltrim(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(
             replace(COLUMN
                      ,'zA','z A')
                     ,'zB','z B')
                     ,'zC','z C')
                     ,'zD','z D')
                     ,'zE','z E')
                     ,'zF','z F')
                     ,'zG','z G')
                     ,'zH','z H')
                     ,'zI','z I')
                     ,'zJ','z J')
                     ,'zK','z K')
                     ,'zL','z L')
                     ,'zM','z M')
                     ,'zN','z N')
                     ,'zO','z O')
                     ,'zP','z P')
                     ,'zQ','z Q')
                     ,'zR','z R')
                     ,'zS','z S')
                     ,'zT','z T')
                     ,'zU','z U')
                     ,'zV','z V')
                     ,'zW','z W')
                     ,'zX','z X')
                     ,'zY','z Y')
                     ,'zZ','z Z')
            );

这适用于一切。

MaxExample = Max Example
MaxExampleTest = Max Example Test
MaxExampleTestTT = Max Example Test TT

只需对所有字母重复 26 次。

于 2013-05-30T13:24:02.733 回答
0

一个小的开始是使用 REGEXP 检查一个字母后跟大写字母(将其移动到 WHERE):

SELECT field REGEXP BINARY '[a-z]{1}[A-Z]{1}' FROM test

但同样,这不是一个完整的答案,而只是一个想法。

于 2013-05-30T10:35:33.713 回答
0

在这种情况下,一种非常暴力的方法可能会有所帮助。使用大写字母查找第一个大写字母的位置:

select (case when pos is null then field
             else concat(substr(field, 1, pos - 1), '.', substr(field, pos))
from (select (case when ascii(substr(col, 2, 1)) between ascii('A') and ascii('Z') then 2
                   when ascii(substr(col, 3, 1)) between ascii('A') and ascii('Z') then 3
                   when ascii(substr(col, 4, 1)) between ascii('A') and ascii('Z') then 4
                   when ascii(substr(col, 5, 1)) between ascii('A') and ascii('Z') then 5
                   when ascii(substr(col, 6, 1)) between ascii('A') and ascii('Z') then 6
                   when ascii(substr(col, 7, 1)) between ascii('A') and ascii('Z') then 7
                   when ascii(substr(col, 8, 1)) between ascii('A') and ascii('Z') then 8
                   when ascii(substr(col, 9, 1)) between ascii('A') and ascii('Z') then 9
                   when ascii(substr(col, 10, 1)) between ascii('A') and ascii('Z') then 10
              end) as pos, field
      from t
     ) t

我不确定您是否需要相应的update声明,或者只是查找该期间职位的逻辑。

于 2013-05-30T10:47:25.560 回答