我们需要更新启用的 BLOB 列(存储 JSON 数据并具有 JSON 约束)。问题在于 BLOB 数据需要更新的数据长度。它的长度超过 80,000 个字符。
CREATE TABLE GLOBAL_TRAIL
(
CODE VARCHAR2(32 BYTE) NOT NULL,
json_column BLOB
);
ALTER TABLE GLOBAL_TRAIL ADD CONSTRAINT CNS_JS
CHECK (json_column IS JSON (STRICT))
ENABLE VALIDATE;
UPDATE GLOBAL_TRAIL
SET json_column =
utl_i18n.string_to_raw( '....................80,000 character long text................', 'AL32UTF8' )
where code = '798798798';
第 1 行错误 ORA-01704: 字符串文字太长
然后我尝试在网上找到可用的选项。
我已经尝试了多个页面中提供的替代方案,将它们分成批次并将它们连接在一起,但我收到以下错误:
ORA-01489: 字符串连接结果太长 ORA-06512: 在第 11 行
示例:chunk1和chunk 2的长度为30k,chunk 3的长度为20k。
DECLARE
chunk1 blob; chunk2 blob; chunk3 blob;
BEGIN
chunk1 := utl_i18n.string_to_raw( '{"tementeations":[{"tetestReference":{"tetestnotif":"AdHoctestnotif","testocknotif":"AdHoc934rentnotif"},"nesteationredframe":"202445054501","testoc":"Trail"}},{"accumulationpinkno":.............................{"no":"eATIONGreySTEP"},"accumulationno":{"no":"subjectWages"},"accumulatedtrluepinkno":{"no":"chair"},"accumulatedtrlue":{"chair":090,"934trainno":"Trail"}},{"accumulationpinkno":{"no":"eATIONGreySTEP"},"accumulationno":{"no":"subjectMaximumWages"},', 'AL32UTF8' );
chunk2 := utl_i18n.string_to_raw('"accumulatedtrluepinkno":{"no":"chair"},"accumulatedtrlue":{"chair":090,"934trainno":"Trail"}},{"accumulationpinkno":{"no:090,"934trainno":"Trail"}}]}]}],"eationOrder":1,"chemicyPackageVersion":"1909362","eationStatTrailerno":{"no":"SUCCEEDED","effectiveframeTime":"202445044526T16:09:57908Z"},"primaryLivedIneletrtors":[{"eletrtornotif":"eb9aeafa4556e1454e764587e645b2cc4a2368cf","eletrtorLevelno":{"no":"native"}},..................................................{"eletrtornotif":"76a7aa9e45bafc45410a45b0ef45b2535b6990be","eletrtorLevelno":{"no":"tent"}}],"primaryWorkedIneletrtors":', 'AL32UTF8' );
chunk3 := utl_i18n.string_to_raw( '[{"eletrtornotif":"eb9aeafa4556e1454e764587e645b2cc4a2368cf","eletrtorLevelno":{"no":"native"}},{"eletrtornotif":"76a7aa9e45bafc45410a45b0ef45b2535b6990be","eletrtorLevelno":{"no":"tent"}}],"tementchair":{"chair":090,"934trainno":"Trail"},"totals":......................................[{"totalno":"TOTALGreyEARNINGS","totaltrl"accumulationstockpinkno":"tesla","accumulationStartframe":"202445044501","accumulationEndframe":"202445064530","accumulatedtrluepinkno":{"no":"c"tementeationnotif":"1ef03e7645cceb45076745813045ffe4e0e14753"}]}', 'AL32UTF8' );
UPDATE GLOBAL_TRAIL
SET json_column =
chunk1 || chunk2 || chunk3 where code = '798798798';
END;
**ORA4501489: 字符串连接结果太长
以下方法也出现同样的错误:
UPDATE GLOBAL_TRAIL
SET json_column =
utl_i18n.string_to_raw( '..............30k long...............', 'AL32UTF8' )
||
utl_i18n.string_to_raw( '..............30k long...............', 'AL32UTF8' )
||
utl_i18n.string_to_raw( '..............20k long...............', 'AL32UTF8' )
WHERE code = '798798798';
如果我尝试仅更新一个块,则会抛出 JSON 约束错误。 [错误]执行(11:2):ORA-02290:违反检查约束(CNS_JS)
所以所有的块需要同时更新。
请建议解决此问题的最佳方法。
您可以使用:
UPDATE GLOBAL_TRAIL
SET json_column =
utl_i18n.string_to_raw('First 4,000 bytes', 'AL32UTF8')
|| utl_i18n.string_to_raw('Second 4,000 bytes', 'AL32UTF8')
|| utl_i18n.string_to_raw('...', 'AL32UTF8')
|| utl_i18n.string_to_raw('20th 4,000 bytes', 'AL32UTF8')
|| utl_i18n.string_to_raw('21st 4,000 bytes (note: bytes not characters)', 'AL32UTF8')
where code = '798798798';
或:
UPDATE GLOBAL_TRAIL
SET json_column = :1
where code = '798798798';
并通过支持绑定变量的客户端的绑定变量传递
json_column
。