运算符是“||
连接” - 它将其操作数的两个字符串连接在一起。
来自http://www.sqlite.org/lang_expr.html
对于填充,我使用的看似作弊的方法是从目标字符串开始,例如“0000”,连接“0000423”,然后使用 substr(result, -4, 4) 表示“0423”。
更新:看起来 SQLite 中没有“lpad”或“rpad”的本机实现,但您可以在此处遵循(基本上是我建议的):http: //verysimple.com/2010/01/12/sqlite-lpad -rpad 功能/
-- the statement below is almost the same as
-- select lpad(mycolumn,'0',10) from mytable
select substr('0000000000' || mycolumn, -10, 10) from mytable
-- the statement below is almost the same as
-- select rpad(mycolumn,'0',10) from mytable
select 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"