Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

Using SQL to update files

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;


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)

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.