MySQL Forums
Forum List  »  InnoDB

Re: String cuts in column data
Posted by: Peter Brawley
Date: February 09, 2017 03:29AM

If you're a regular regex user in a real language (eg Perl, PHP, C), that'll be easier, otherwise it's just a few lines of brute force string parsing ...

set @s = "[CALL DATE : 11/23/2015] [CONTACT NAME : venki palama] [SERVICE REP NAME : sudhakar mare] Please send a picture showing the overlay harness and connections made";

set @stop = locate("]",@s,1);
set @calldate = trim( substr( @s, 14, @stop-14 );

set @start = locate("[",@s,@stop);
set @stop = locate("]",@s,@start);
set @preflen = length(" [CONTACT NAME ");
set @contactname = trim( substr(@s, @start + @preflen, @stop-@start-@preflen) );

set @start = locate("[",@s,@stop);
set @stop = locate("]",@s,@start);
set @preflen = length(" [SERVICE REP NAME ");
set @servicerepname = trim( substr(@s, @start + @preflen, @stop-@start-@preflen) );

set @comment = trim( substring_index(@s,']',-1) );

select @calldate, @contactname, @servicerepname, @comment;

Easy to make a func of it, call it as often as you please.

Options: ReplyQuote


Subject
Views
Written By
Posted
628
February 08, 2017 10:59AM
343
February 08, 2017 01:20PM
332
February 08, 2017 08:05PM
353
February 09, 2017 12:31AM
Re: String cuts in column data
396
February 09, 2017 03:29AM
374
February 09, 2017 05:59AM
305
February 09, 2017 12:43PM
425
February 09, 2017 08:50PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.