We have a file with some random hex '00' bytes where they should be hex'40' (blank). Is there a way to find and fix these files using SQL or do we need RPG?
Yes, there are some ways with SQL to perform this type of update. V5R3 actually makes this really easy with the new REPLACE function as demonstrated in this example.
Update s1 set c1=REPLACE(c1,X'00',X'40')
On pre-V5R3 releases it's more challenging because you have to use a combination of different functions such as the following:
Update s1 set c1=(substr(c1,1,posstr(c1,X'00')-1) ||X'40'|| substr(c1,posstr(c1,X'00')+1,length(c1)-posstr(c1,X'00') ) ) where posstr(c1,X'00')>0;
MORE INFORMATION ON THIS TOPIC
Check out this Search400.com Featured Topic: Database issues resolved
Search400.com's targeted search engine: Get relevant information on DB2/400.
The Best Web Links: Tips, tutorials and more.
Dig Deeper on DB2 UDB (universal databases)
Related Q&A from Kent Milligan
Create a host variable of the where in statement on the fly with dynamic SQL. Continue Reading
To solve the SQL error -321 on IBM i6.1, use the new values statement to overcome the error. If you are using an older release, declare a cursor ... Continue Reading
When working with DB2 files with columns that have both short and long names, there is no option choose which column names are returned via ODBC ... Continue Reading