Suppose a column contains strings with an odd or even number of characters. I want to add a character “0“ before odd-length strings by using
select Code, iif(Code.strlen() % 2 = 0, Code, `0 + Code) from tmpCode
However, it takes 5GB of memory and a long time to execute the above statement on a 30MB table. Is there a more effective way to achieve this?
You can define a function using the
lpad
function, as shown below:If there are too many strings, you can also refer to the following script, which is 20% faster: