update `blogposts`
set `Body2` = substring(`Body`,3000-instr(reverse(left(`Body`,3000)),' ')+1)
,`Body` = left(`Body`,3000-instr(reverse(left(`Body`,3000)),' '))
where char_length(Body) > 3000
;
30 个字符的演示
set @Body = 'My name is Inigo Montoya! You''ve killed my father, prepare to die!';
select left(@Body,30-instr(reverse(left(@Body,30)),' ')) as field_1
,substring(@Body,30-instr(reverse(left(@Body,30)),' ')+1) as field_2
;
+---------------------------+------------------------------------------+
| field_1 | field_2 |
+---------------------------+------------------------------------------+
| My name is Inigo Montoya! | You've killed my father, prepare to die! |
+---------------------------+------------------------------------------+
完整示例
create table `blogposts` (`Body` varchar(3000),`Body2` varchar(3000));
insert into blogposts (`Body`) values
('Hello darkness, my old friend' )
,('I''ve come to talk with you again' )
,('Because a vision softly creeping' )
,('Left its seeds while I was sleeping' )
,('And the vision that was planted in my brain' )
,('Still remains' )
,('Within the sound of silence' )
,('In restless dreams I walked alone' )
,('Narrow streets of cobblestone' )
,('''Neath the halo of a street lamp' )
,('I turned my collar to the cold and damp' )
,('When my eyes were stabbed by the flash of a neon light' )
,('That split the night' )
,('And touched the sound of silence' )
,('And in the naked light I saw' )
,('Ten thousand people, maybe more' )
,('People talking without speaking' )
,('People hearing without listening' )
,('People writing songs that voices never share' )
,('And no one dared' )
,('Disturb the sound of silence' )
;
select left(`Body`,30-instr(reverse(left(`Body`,30)),' ')) as Body
,substring(`Body`,30-instr(reverse(left(`Body`,30)),' ')+1) as Body2
from `blogposts`
where char_length(Body) > 30
;
+------------------------------+---------------------------+
| Body | Body2 |
+------------------------------+---------------------------+
| I've come to talk with you | again |
+------------------------------+---------------------------+
| Because a vision softly | creeping |
+------------------------------+---------------------------+
| Left its seeds while I was | sleeping |
+------------------------------+---------------------------+
| And the vision that was | planted in my brain |
+------------------------------+---------------------------+
| In restless dreams I walked | alone |
+------------------------------+---------------------------+
| 'Neath the halo of a street | lamp |
+------------------------------+---------------------------+
| I turned my collar to the | cold and damp |
+------------------------------+---------------------------+
| When my eyes were stabbed by | the flash of a neon light |
+------------------------------+---------------------------+
| And touched the sound of | silence |
+------------------------------+---------------------------+
| Ten thousand people, maybe | more |
+------------------------------+---------------------------+
| People talking without | speaking |
+------------------------------+---------------------------+
| People hearing without | listening |
+------------------------------+---------------------------+
| People writing songs that | voices never share |
+------------------------------+---------------------------+
update `blogposts`
set `Body2` = substring(`Body`,30-instr(reverse(left(`Body`,30)),' ')+1)
,`Body` = left(`Body`,30-instr(reverse(left(`Body`,30)),' '))
where char_length(`Body`) > 30
;
select `Body`
,`Body2`
from `blogposts`
where `Body2` is not null
;
+------------------------------+---------------------------+
| Body | Body2 |
+------------------------------+---------------------------+
| I've come to talk with you | again |
+------------------------------+---------------------------+
| Because a vision softly | creeping |
+------------------------------+---------------------------+
| Left its seeds while I was | sleeping |
+------------------------------+---------------------------+
| And the vision that was | planted in my brain |
+------------------------------+---------------------------+
| In restless dreams I walked | alone |
+------------------------------+---------------------------+
| 'Neath the halo of a street | lamp |
+------------------------------+---------------------------+
| I turned my collar to the | cold and damp |
+------------------------------+---------------------------+
| When my eyes were stabbed by | the flash of a neon light |
+------------------------------+---------------------------+
| And touched the sound of | silence |
+------------------------------+---------------------------+
| Ten thousand people, maybe | more |
+------------------------------+---------------------------+
| People talking without | speaking |
+------------------------------+---------------------------+
| People hearing without | listening |
+------------------------------+---------------------------+
| People writing songs that | voices never share |
+------------------------------+---------------------------+