MySQL 中怎么通過(guò)SUBSTRING_INDEX函數(shù)拆分字符串為數(shù)組單元,相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。
創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站建設(shè)、成都做網(wǎng)站、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)廣陵,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專(zhuān)業(yè),歡迎來(lái)電咨詢(xún)建站服務(wù):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 | +--------+--------+--------+--------+--------+--------+--------+
看完上述內(nèi)容,你們掌握MySQL 中怎么通過(guò)SUBSTRING_INDEX函數(shù)拆分字符串為數(shù)組單元的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!