MySQL 中怎么通过SUBSTRING_INDEX函数拆分字符串为数组单元,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
创新互联公司主要从事成都网站建设、成都做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务广陵,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220
vim test.sh #Define variables MYSQL_HOME=/usr SQL_SCRIPT_DB_CONNECTION_STRING='-uroot -p'root'' SQL_SCRIPT_PARAMETERS_LIST="'PARAM1 PARAM2 PARAM3'" #Execute the command #CMD_SQL_SCRIPT_EXECUTION=${MYSQL_HOME}/bin/mysql ${SQL_SCRIPT_DB_CONNECTION_STRING} -e "set @VAR1=$SQL_SCRIPT_PARAMETERS_LIST ; source ${SQL_SCRIPT_FILE_LOCATION}/${SQL_SCRIPT_NAME}.sql ;" >> ${myLogFile} ${MYSQL_HOME}/bin/mysql ${SQL_SCRIPT_DB_CONNECTION_STRING} -e "set @VAR=$SQL_SCRIPT_PARAMETERS_LIST; set @VAR_NUM=length(@VAR)-length(REPLACE(@VAR,' ',''))+1; /* define the total number of the variables */ set @VAR_POS=0; /* define the variable position in the string */ /* define the variables' value, if the the variable doesn't exist, its value is null */ set @VAR_1 = if(@VAR_POS < @VAR_NUM,SUBSTRING_INDEX(SUBSTRING_INDEX(@VAR, ' ', @VAR_POS:=@VAR_POS+1),' ',-1),null); set @VAR_2 = if(@VAR_POS < @VAR_NUM,SUBSTRING_INDEX(SUBSTRING_INDEX(@VAR, ' ', @VAR_POS:=@VAR_POS+1),' ',-1),null); set @VAR_3 = if(@VAR_POS < @VAR_NUM,SUBSTRING_INDEX(SUBSTRING_INDEX(@VAR, ' ', @VAR_POS:=@VAR_POS+1),' ',-1),null); set @VAR_4 = if(@VAR_POS < @VAR_NUM,SUBSTRING_INDEX(SUBSTRING_INDEX(@VAR, ' ', @VAR_POS:=@VAR_POS+1),' ',-1),null); set @VAR_5 = if(@VAR_POS < @VAR_NUM,SUBSTRING_INDEX(SUBSTRING_INDEX(@VAR, ' ', @VAR_POS:=@VAR_POS+1),' ',-1),null); set @VAR_6 = if(@VAR_POS < @VAR_NUM,SUBSTRING_INDEX(SUBSTRING_INDEX(@VAR, ' ', @VAR_POS:=@VAR_POS+1),' ',-1),null); set @VAR_7 = if(@VAR_POS < @VAR_NUM,SUBSTRING_INDEX(SUBSTRING_INDEX(@VAR, ' ', @VAR_POS:=@VAR_POS+1),' ',-1),null); select @VAR_1, @VAR_2, @VAR_3, @VAR_4, @VAR_5, @VAR_6, @VAR_7;" sh test.sh Warning: Using a password on the command line interface can be insecure. +--------+--------+--------+--------+--------+--------+--------+ | @VAR_1 | @VAR_2 | @VAR_3 | @VAR_4 | @VAR_5 | @VAR_6 | @VAR_7 | +--------+--------+--------+--------+--------+--------+--------+ | PARAM1 | PARAM2 | PARAM3 | NULL | NULL | NULL | NULL | +--------+--------+--------+--------+--------+--------+--------+
看完上述内容,你们掌握MySQL 中怎么通过SUBSTRING_INDEX函数拆分字符串为数组单元的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
标题名称:MySQL中怎么通过SUBSTRING_INDEX函数拆分字符串为数组单元
转载源于:https://www.cdcxhl.com/article24/gcdece.html
成都网站建设公司_创新互联,为您提供企业网站制作、用户体验、全网营销推广、网站建设、定制开发、Google
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联