Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to split a string into array units by SUBSTRING_INDEX function in MySQL

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

MySQL how to split strings into array units through the SUBSTRING_INDEX function, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Vim test.sh#Define variablesMYSQL_HOME=/usrSQL_SCRIPT_DB_CONNECTION_STRING='-uroot-paired rootstocks SQL scripts ParametersList = "'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 | +- -+ finish reading the above content Have you mastered the method of splitting strings into array units through the SUBSTRING_INDEX function in MySQL? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report