IBM Support

DB2 Load with cursor fails with SQL0104N error

Troubleshooting


Problem

Load from a remote table using cursors with the WITH UR clause fails with SQL0104n error. $ db2 "declare myCursor cursor database user db2inst1 for SELECT * FROM WITH UR" Enter current password for : DB20000I The SQL command completed successfully. $ db2 "load from myCursor of cursor messages attr.log replace into .

SQL0104N An unexpected token "UR" was found following "" with". Expected tokens may include: "". SQLSTATE=42601

Symptom

SQL0104N error received while executing a load command.

Cause

When doing remote fetch LOAD (LOAD from CURSOR with DATABASE), LOAD sometimes need to rewrite the input SQL (from the DECLARE CURSOR) when fetching the source data, depending on the complexity of the situation.  LOAD code does not have a full SQL parser that can fully understand the input SQL.
For example:
breaking down the read-only / update / optimize-for / isolation clauses when doing the rewrite of the SQL statement.

In the above example, LOAD detects that the input SQL is not a plain "select * from tablename", and the input/output columns are not direct 1-to-1 mapping, and decides it need to construct the complex version of statement:

WITH db2temporarytableforinternalexportandimportandloadprocessingdonotusethisname (C0, C1, C2, C3, C4) AS ( select * from s5 with ur) SELECT C0, C1, C2, C3 FROM db2temporarytableforinternalexportandimportandloadprocessingdonotusethisname

Unfortunately the above SQL is invalid according to SQL grammar.
The isolation clause with UR is not allowed at that location of the SQL statement.
Thus the SQL0104 error message is returned.

Resolving The Problem

You may use one of these two solutions:

  • Do not use the WITH UR clause in the declaration of the cursor.
OR
  • Make sure the number of columns are the same on source and target tables.

[{"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"OTHER - Uncategorised","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"9.7;9.5;9.1;8.2","Edition":"Enterprise Server;Express;Personal;Personal Developer's;Workgroup Server","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
16 June 2018

UID

swg21430155