MySQL - explode/split input to stored procedure

别说谁变了你拦得住时间么 提交于 2020-01-30 08:50:05

问题


I have problem, I need to explode my input to my stored procedure, but don't know how I can do it.

My stored procedure has a VARCHAR(256) input which I need to split and generate insert statements.

i what to explode this varchar "1,2,3,7,8,9" so I need to split that string on "," and iterate through the result


回答1:


Yes, please see this forum thread on replicating the functionality in mysql that tsql provides.

That thread also discusses some of the downfalls of this method. Also, I think you want to be using VARCHAR(255) or just VARCHAR(MAX) because there is no benefit to a 256, it uses a 2 byte size prefix and yet only stores 256 characters.

Have you considered using xml and xpath syntax to extract the values instead? I think going forward this will become a more readable and maintainable method.




回答2:


Here is a split_string() function http://forge.mysql.com/tools/tool.php?id=4




回答3:


Try my SQL Library: http://ondra.zizka.cz/stranky/programovani/sql/mysql_stored_procedures.texy



来源:https://stackoverflow.com/questions/1742728/mysql-explode-split-input-to-stored-procedure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!