How do I increase a field by +1 that was previously 0001 and then should be 0002?
I am currently using the following command:
SELECT fieldA+1
FROM table
WHERE ID = 1234;
But this only turns 0001 into 2
Its a very basic question but i dont get it
2
Answers
A field of type
INT
must first be converted to a string (orCHAR
) in order to perform string-based operations, such as a pad.For example:
Where the
LPAD
parameters are as follows:LPAD(str, len [,padstr])
. If the field is already ofCHAR
orVARCHAR
type, theCAST()
function is not required.Related documentation:
CAST
LPAD
Aside:
Use ZEROFILL column attribute accompanied by definite column length.
fiddle