Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can pass a string as array, using a split separator, and explode it in a function, that will work with the results.</p> <p>For a trivial example, if you have a string array like this: 'one|two|tree|four|five', and want to know if two is in the array, you can do this way:</p> <pre><code>create function str_in_array( split_index varchar(10), arr_str varchar(200), compares varchar(20) ) returns boolean begin declare resp boolean default 0; declare arr_data varchar(20); -- While the string is not empty while( length( arr_str ) &gt; 0 ) do -- if the split index is in the string if( locate( split_index, arr_str ) ) then -- get the last data in the string set arr_data = ( select substring_index(arr_str, split_index, -1) ); -- remove the last data in the string set arr_str = ( select replace(arr_str, concat(split_index, substring_index(arr_str, split_index, -1) ) ,'') ); -- if the split index is not in the string else -- get the unique data in the string set arr_data = arr_str; -- empties the string set arr_str = ''; end if; -- in this trivial example, it returns if a string is in the array if arr_data = compares then set resp = 1; end if; end while; return resp; end | delimiter ; </code></pre> <p>I want to create a set of usefull mysql functions to work with this method. Anyone interested please contact me.</p> <p>For more examples, visit <a href="http://blog.idealmind.com.br/mysql/how-to-use-string-as-array-in-mysql-and-work-with/" rel="nofollow">http://blog.idealmind.com.br/mysql/how-to-use-string-as-array-in-mysql-and-work-with/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload