I'm writing a SQL query that updates just only one field of a string (tax_cd) but it doesn't work, I must replace field 12 which is '0' or blank with '1',character 0 is the one you found in the condition where, all other characters in the string should not be changed
TAX_CD is a VARCHAR2(26)
UPDATE doc_table
SET tax_cd=substr(tax_cd,1,11)||'1'||substr(tax_cd,13,26)
WHERE substr(tax_cd,12,1) = 0 ;
Current : "ABC 0 0 L K "
Updated : "ABC 0 1 L K "
any advice?
the string is not always equal as length, for example:
it is written on the table like this
"0 K 1"
so the ideal is to read the record field with a select, make a length and based on that try to write in position 12 the code 1 but I do not know how to do it
Lenght(tax_cd) Count(*)
- 2 3
- 3 376
- 4 32
- 5 22
- 6 16
- 7 1
- 8 2
- 25 6
- null 6
To me, it looks like
so you'd