Column1 Column2 Column3 A 1 1 A 1 2 A 12 2 C 13 2 B 11 2
我需要选择Column1-Column2-Column3(例如A-01-0001)。我想用每个列填充 –
我是一个初学者关于sqlite,任何帮助将不胜感激
The
||
operator is “concatenate” – it joins together the two strings of
its operands.
从http://www.sqlite.org/lang_expr.html
对于填充,我使用的似乎骗子的方法是开始与你的目标字符串,说’0000’,连接’0000423’,然后substr(结果,-4,4)为’0423’。
更新:看起来在sqlite没有本机实现“lpad”或“rpad”,但你可以跟着(基本上我提出)在这里:http://verysimple.com/2010/01/12/sqlite-lpad-rpad-function/
-- the statement below is almost the same as-- select lpad(mycolumn,'0',10) from mytableselect substr('0000000000' || mycolumn,-10,10) from mytable-- the statement below is almost the same as-- select rpad(mycolumn,10) from mytableselect substr(mycolumn || '0000000000',1,10) from mytable
下面是它的外观:
SELECT col1 || '-' || substr('00'||col2,-2,2) || '-' || substr('0000'||col3,-4,4)
它产生
"A-01-0001""A-01-0002""A-12-0002""C-13-0002""B-11-0002"总结
以上是内存溢出为你收集整理的如何在sqlite中连接字符串和padding全部内容,希望文章能够帮你解决如何在sqlite中连接字符串和padding所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)