当您尝试在 字符串长度大于 4000 的 CLOB 列中插入 string 值时会出现此问题。
你需要使用TO_CLOB将字符串转换为CLOB,但不幸的是,它也可以接受4000个字符。
要解决此问题,您需要将字符串分成 4000 个字符的块并使用 TO_CLOB,如下例所述:
SQL> CREATE TABLE CLOB_TEST (
2 MY_CLOB CLOB
3 );
Table created.
尝试插入长度为 4282 > 4000 的字符串 -- 错误
SQL> INSERT INTO CLOB_TEST ( MY_CLOB ) -- inserting a string of length 4282 > 4000
2 VALUES ( '0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
3 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
4 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
5 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
6 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
7 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
8 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
9 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
10 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
11 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
12 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
13 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
14 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
15 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
16 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
17 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
18 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
19 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
20 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
21 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
22 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
23 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
24 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
25 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
26 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
28 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
30 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
31 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
32 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
33 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
34 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
35 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
36 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
37 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
38 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
39 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
40 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
41 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
42 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
43 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'
44 );
VALUES ( '0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
*
ERROR at line 2:
ORA-01704: string literal too long
尝试使用 TO_CLOB 插入长度为 4282 的字符串 -- 错误
SQL> INSERT INTO CLOB_TEST ( MY_CLOB ) -- trying to insert the string of length 4282 with TO_CLOB
2 VALUES ( TO_CLOB('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
3 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
4 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
5 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
6 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
7 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
8 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
9 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
10 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
11 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
12 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
13 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
14 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
15 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
16 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
17 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
18 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
19 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
20 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
21 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
22 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
23 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
24 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
25 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
26 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
28 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
30 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
31 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
32 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
33 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
34 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
35 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
36 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
37 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
38 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
39 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
40 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
41 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
42 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
43 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'
44 ) );
VALUES ( TO_CLOB('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
*
ERROR at line 2:
ORA-01704: string literal too long
尝试插入长度为 3670
SQL> INSERT INTO CLOB_TEST ( MY_CLOB ) -- inserting a string of length 3670
2 VALUES ( '0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
3 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
4 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
5 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
6 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
7 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
8 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
9 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
10 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
11 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
12 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
13 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
14 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
15 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
16 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
17 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
18 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
19 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
20 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
21 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
22 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
23 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
24 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
25 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
26 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
28 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
30 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
31 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
32 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
33 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
34 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
35 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
36 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
37 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'
38 );
1 row created.
尝试使用 TO_CLOB 插入长度为 4282 的字符串 -- 错误
SQL> INSERT INTO CLOB_TEST ( MY_CLOB ) -- trying to insert the string of length 4282 with TO_CLOB
2 VALUES ( TO_CLOB('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
3 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
4 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
5 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
6 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
7 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
8 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
9 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
10 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
11 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
12 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
13 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
14 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
15 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
16 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
17 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
18 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
19 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
20 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
21 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
22 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
23 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
24 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
25 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
26 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
28 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
30 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
31 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
32 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
33 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
34 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
35 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
36 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
37 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
38 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
39 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
40 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
41 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
42 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
43 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'
44 ) );
VALUES ( TO_CLOB('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
*
ERROR at line 2:
ORA-01704: string literal too long
尝试用TO_CLOB()将字符串插入长度为(3670,610)的两部分——成功
SQL> INSERT INTO CLOB_TEST ( MY_CLOB ) -- trying to insert the data in two parts(3670,610) with TO_CLOB ()
2 VALUES ( TO_CLOB('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
3 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
4 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
5 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
6 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
7 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
8 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
9 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
10 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
11 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
12 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
13 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
14 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
15 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
16 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
17 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
18 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
19 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
20 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
21 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
22 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
23 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
24 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
25 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
26 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
28 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
30 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
31 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
32 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
33 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
34 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
35 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
36 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
37 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789')
38 --
39 || TO_CLOB('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
40 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
41 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
42 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
43 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
44 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'
45 )
46 );
1 row created.
SQL>
注意:如果你连接两个长度小于 4000 个字符的字符串(导致字符串长度 > 4000),那么它也将不起作用并失败并出现错误:ORA-01489: result of string concatenation is too long
所以结论是使用TO_CLOB 与少于4000 个字符的块并使用连接运算符|| 连接CLOBs
干杯!!