Given a database table TABLE1 with column COLUMN1 of type VARCHAR(1020).
I need to reformat some data from variable length format into a new fixed length format (The hashes are removed, the numbers are left padded with zeros until length of 10):

e.g: from "123#456#789" into "000000012300000004560000000789".

Executing the given sql-statement leads to the following error-message, which is not that helpful and only points to a broken connection:

> 
> Error occurred during SQL query execution
> 
> 
> Ursache:
>  SQL-Fehler [08001]: [jcc][t4][2030][11211][4.22.29]
>  Bei Operationen auf dem der Verbindung zugrunde liegendem Socket, im Socketeingabedatenstrom oder Socketausgabedatenstrom ist ein Kommunikationsfehler aufgetreten.
> 
> 
> Fehlerposition: Reply.fill() - insufficient data (-1). Nachricht: Unzureichende Daten. ERRORCODE=-4499, SQLSTATE=08001
> 
> 
> 

I am working on a DB2-LUW 11.1 v10.5.0.5 database, where regular expressions are not supported except in xmlqueries.

When i am replacing the second return statement with "return xs:string($COLUMN1)" the statement executes fine. So this does not look like a syntax error.

I found some informaton stating that the order of the let statements is not fixed. So i tried removing the if/then/else-logic and this resulted always in same results, so does not seem to be an issue either.

```sql
UPDATE TABLE1
SET COLUMN1 = xmlcast(xmlquery(
        '
        if (fn:matches( $COLUMN1,"(\d{0,10})#(\d{1,10})#(\d{1,10})")) 
            then
                xs:string($COLUMN1)
            else
                let $part1A := fn:replace($COLUMN1, "(\d{0,10})#(\d{1,10})#(\d{1,10})", "$1", "i")
                let $part1B := fn:string-join(("0000000000", $part1A), "")
                let $part1C := fn:substring($part1B, fn:string-length($part1B) - 9)

                let $part2A := fn:replace($COLUMN1, "(\d{0,10})#(\d{1,10})#(\d{1,10})", "$2", "i")
                let $part2B := fn:string-join(("0000000000", $part2A), "")
                let $part2C := fn:substring($part2B, fn:string-length($part2B) - 9)

                let $part3A := fn:replace($COLUMN1, "(\d{0,10})#(\d{1,10})#(\d{1,10})", "$3", "i")
                let $part3B := fn:string-join(("0000000000", $part3A), "")
                let $part3C := fn:substring($part3B, fn:string-length($part3B) - 9)

                let $result := fn:string-join(($part1C, $part2C, $part3C), "")

                return xs:string($result)
        '
        passing COLUMN1 AS "COLUMN1"
    ) AS VARCHAR(1020))
    WHERE COLUMN1 IS NOT NULL AND LENGTH(COLUMN1 ) > 0;

```

Expectation would be to run the sql update successfully, instead of an error which leads to a broken database connection.