How to use output of select as input to function in MySQL? -


i use function have in mysql. function used split string, , takes string, delimiter , element number want output based on delimiter.

create function split_str( x varchar(255), delim varchar(12), pos int ) returns varchar(255) return replace(substring(substring_index(x, delim, pos), length(substring_index(x, delim, pos -1)) + 1), delim, ''); 

i can use function in following way:

select split_str('a:b', ':', 1); 

which output "a".

however, have in order use output of following mysql command input string function?

select gene enhancer limit 1; 

any appreciated!

first, don't need own split string function in mysql. function substring_index() built-in.

if want pass column string, can do:

select substring_index(gene, ':', 1) enhancer limit 1; 

to nth value:

select substring_index(substring_index(gene, ':', <n>), ':', -1) enhancer limit 1; 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -