Sql功能动态操作字符串可能传递参数字符串需要在给定位置的字符串中添加任何字符 [英] Sql fuction manipulate string dynamically may passing parameter string needs to add any character in string given position
问题描述
我有字符串',11,22,aa,cc,dd,77'
i会将此字符串传递给此作为第一个参数的函数第二个参数将是我想在字符串之间插入或添加逗号或数字或字母数字字符的位置。
例如'a,b,c ,d,e,1'是字符串
Fucntioninsertstring('a,b,c,d,e,1',3,F)
输出将是'a,b,F c,d,e,1'
我尝试了什么:
i有创建函数获取所有以字符串形式传递的值。
动态如果我想要检查发送位置我想要插入任何字符。
和输出将更新字符串。
i have string ', 11, 22,aa, cc, dd, 77 '
i will pass this string to this function as 1st parameter 2nd parameter would be the position on which i want to insert or add comma or number or alphanumeric character between string.
example ' a, b , c , d ,e ,1 ' is string
Fucntioninsertstring ( ' a, b , c , d ,e ,1 ' , 3, F )
out put would be ' a, b , F c , d ,e ,1 '
What I have tried:
i have create function getting all the values passing in string.
but dynamically if i want check send position at which i want to insert any character.
and output will be updated string.
推荐答案
基本上,你做错了。
不要将CSV数据存储在一个列中,它变成了一场噩梦使用,部分是因为SQL字符串处理是......嗯... 差 * ,但主要是因为它;这是错误的方法。
当你存储CSV数据时,你会阻止SQL做它最擅长的事情:理解和操纵数据之间的关系 - 所有你获得的只是你的演示语言代码中的一小部分简单插入能力。
而不是这样做,设置一个单独的表来分别保存每个CSV项目,外键返回到原始表格行。那样,插入,删除,搜索;它们都变得更加简单,原始的INSERT,UPDATE和SELECT操作变得稍微复杂一点。
*他礼貌地说
Basically, you are doing the wrong thing.
Don't store CSV data in a single column, it becomes a nightmare to work with, partly because SQL string handling is ... um ... poor*, but mostly because it;s the wrong way to do it.
When you store CSV data, you prevent SQL from doing what it does best: understanding and manipulating the relationships between data - all you gain is a small amount of "easy insert" ability in your presentation language code.
Instead of doing that, set up a separate table to hold each CSV item separately, with a foreign key back to the original table row. That way, insert, remove, search; they all become a whole load simpler, and the original INSERT, UPDATE, and SELECT operations become only slightly more complex.
* He said, politely
这篇关于Sql功能动态操作字符串可能传递参数字符串需要在给定位置的字符串中添加任何字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!