The ||
operator is "concatenate" - it joins together the two strings of its operands.
De http://www.sqlite.org/lang_expr.html
Para el relleno, la forma aparentemente tramposo I' Si lo usas es para comenzar con tu cadena objetivo, di '0000', concatenar '0000423', luego substr (resultado, -4, 4) para '0423'.
Actualización: Parece que no hay una implementación nativa de "lpad" o "RPAD" en SQLite, pero se puede seguir a lo largo (básicamente lo que he propuesto) aquí: http://verysimple.com/2010/01/12/sqlite-lpad-rpad-function/
-- 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
Así es como Apariencia:
SELECT col1 || '-' || substr('00'||col2, -2, 2) || '-' || substr('0000'||col3, -4, 4)
se produce
"A-01-0001"
"A-01-0002"
"A-12-0002"
"C-13-0002"
"B-11-0002"
Posible duplicado: http://stackoverflow.com/q/3568779/2291 –