How to insert CLOB data in dashDB

573 Views Asked by At

I am trying to store a base64 encoded string (it contains text plus image - the image size is 555 KB, the text data is of negligible size) into DashDB (DB2) using the CLOB datatype. However though I am able to create a table having a CLOB field.

I am getting error when I try to insert this base64 encoded string into this CLOB field. I have studied whatever information is available in the internet on using CLOB with DB2 or DashDB (not much information is available), but could not find any solution yet. Can you help?

Here is how I am creating my table.

CREATE TABLE "MYDB"."T_RULE_IMPLNOTES_2" (
        "IMPL_NOTES_SURR_ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY ( START WITH 100 INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 NO CYCLE CACHE 20),
        "UC_RULE_SURR_ID" INTEGER NOT NULL,
        "COMPANY_SURR_ID" INTEGER NOT NULL,
        "CLIENT_UC_RULE_IMPLNOTES" CLOB(30000000),
        "CLIENT_UC_RULE_IMPL_MODIFIED_DATE" DATE,
        "CLIENT_UC_RULE_USER_SURR_ID" INTEGER) ORGANIZE BY ROW;

ALTER TABLE "MYDB"."T_RULE_IMPLNOTES_2" ADD CONSTRAINT "PRM_KEY" PRIMARY KEY
    ("IMPL_NOTES_SURR_ID");

Here is how I am inserting the string into the table from my code (Node.js)

INSERT INTO "+schema+"T_RULE_IMPLNOTES_1 (IMPL_NOTES_SURR_ID, UC_RULE_SURR_ID, COMPANY_SURR_ID, CLIENT_UC_RULE_IMPLNOTES,CLIENT_UC_RULE_IMPL_MODIFIED_DATE, CLIENT_UC_RULE_USER_SURR_ID) VALUES (NEXT VALUE FOR "+schema+"SURROGATE_KEY_SEQ, p1 , p2 ,'p3','p4', p5)";

I am getting this error -

SQL0102N  The string constant beginning with \"'<p><img rc=\"data:image/jpeg;base64,/9j/4AAQSkZJRgABAgEAYA
BgAAD/7gAOQ\" is too long.  SQLSTATE=54002\n","state":"54002"}

On reading about this error I got this:

The string constant beginning with string has a length greater than the maximum allowed length. Most strings have these limits: v For a hexadecimal constant (X, GX, or UX), the number of hexadecimal digits must not exceed 32704.
A string that exceeds the limit can be specified only through assignment from a host variable.

However, I did not understand what it means by "only through assignment from a host variable".

Any help on how to use CLOB data type in dashDB and how to insert values in a CLOB data type will be greatly appreciated.

0

There are 0 best solutions below