mysql create stored functions split_string

1, create a function

- Create a stored function 
the DROP  the FUNCTION  the IF  EXISTS SPLIT_STR; - determining whether there exists delete 
the CREATE  the FUNCTION SPLIT_STR ( 
X VARCHAR ( 255 ), 
  the delim VARCHAR ( 12 is ), 
  POS the INT 
) the RETURNS  VARCHAR ( 255 ) 
DETERMINISTIC 
the BEGIN 
   the RETURN  the REPLACE ( the SUBSTRING (SUBSTRING_INDEX (X, the delim, POS), 
       the LENGTH (SUBSTRING_INDEX (X, the delim, POS - . 1 )) +  . 1 ),
       share, '' );
END ;

2, call the method

SELECT split_str('7654,7698,7782,7788',',',1) as one,
split_str('7654,7698,7782,7788',',',2) as two,
split_str('7654,7698,7782,7788',',',3) as three,
split_str('7654,7698,7782,7788',',',4) as forms

 

Guess you like

Origin www.cnblogs.com/wuzaipei/p/12663922.html