我尝试在Clob数据类型中插入超过32k字节的数据,但出现错误:-
语句执行失败:[IBM] [CLI驱动程序] [DB2 / LINUXX8664] SQL0102N以“嗨,早安团队:我们被要求向所有人添加安妮尔”开头的字符串常量太长。 SQLSTATE = 54002 SQLCODE = -102
请找到我的DDL语句:-
CREATE TABLE "DB2IDEV "."CHANGE" (
"TICKET_ID" INTEGER NOT NULL ,
"SHORTDESC" VARCHAR(5000 OCTETS) NOT NULL ,
"LONGDESC" CLOB(2147483647 OCTETS) LOGGED NOT COMPACT ,
"RELEASENUM" VARCHAR(12 OCTETS) WITH DEFAULT NULL ,
"ISSOFTDELETED" INTEGER NOT NULL WITH DEFAULT 0 ,
"CREATETIMESTAMP" TIMESTAMP NOT NULL WITH DEFAULT CURRENT TIMESTAMP ,
"LASTUPDATETIMESTAMP" TIMESTAMP WITH DEFAULT NULL )
IN "TABLESPACE"
ORGANIZE BY ROW ;
INSERT INTO DB2IDEV.Change (
Ticket_ID,shortDesc,longDesc,releaseNum,isSoftDeleted,
createTimeStamp,lastUpdateTimeStamp)
VALUES (
'296129',
'High Cisco Adaptive Security Appliance Remote Code Execution and Denial of Service Vulnerabilit',
'<Some long data around 50KB in size>',
NULL, '0','2018-02-07 02:11:50',NULL
)
答案 0 :(得分:2)
说明
发生以下情况之一:
... 以string开头的字符串常量的长度大于32672个字节。长度大于32672的字符串 长度大于16336个字符的字节或图形字符串 只能通过从主机变量赋值来指定。注意 DB2产品家族中的其他服务器可能会指定一个 字符串的大小限制不同。查阅文档 有关适当的数据库产品的详细信息。
对于如此长的常数,必须使用相应的变量。 像这样:
ibm_db_conn = ibm_db.connect(...)
sql = """INSERT INTO DB2IDEV.Change (
Ticket_ID,shortDesc,longDesc,releaseNum,isSoftDeleted,
createTimeStamp,lastUpdateTimeStamp)
VALUES (
'296129',
'High Cisco Adaptive Security Appliance Remote Code Execution and Denial of Service Vulnerabilit',
?,
NULL, '0','2018-02-07 02:11:50',NULL
)"""
stmt = ibm_db.prepare(ibm_db_conn, sql)
clob='<Some long data around 50KB in size>'
ibm_db.bind_param(stmt, 1, clob)
ibm_db.execute(stmt)