建立测试表并用proc插入记录:
create table TBL_LV1
(
L LONG,
B VARCHAR2(10),
C VARCHAR2(10)
);
INSERT ... L, B VALUES(:l, :b);
可插入。
INSERT ... L, B, C VALUES(:l, :b, :c);
报错。
create table TBL_LV1
(
L LONG,
B VARCHAR2(10)
);
VARCHAR2(1334)、VARCHAR2(4000)
INSERT ... L, B VALUES(:l, :b);
可插入。
create table TBL_LV1
(
A VARCHAR2(10),
B VARCHAR2(10)
);
INSERT ... A, B VALUES(:a, :b);
报错。
但使用
INSERT ... A, B VALUES('a', 'b');不报错。
即使改为:
create table TBL_LV1
(
A VARCHAR2(4000),
B VARCHAR2(4000)
);
INSERT ... A, B VALUES('a', 'b');也不报错。
总结:
1. 如果使用proc连接9i的库时,由于客户端和服务端的多字节字符问题,插入VARCHAR2类型时会出现ORA-01461: can bind a LONG value only for insert into a LONG column的报错。但使用PLSQL Developer或SQLPLUS这些非OCI驱动,则不会报错。
2. 使用proc绑定变量,根据上面的实验来看,会让ORA-01461这个错误的产生更混淆。
3. 以上问题只在9i及以下版本会出现,10.1.0.1版本中已经修复bug,若仍使用9i及以下版本,Oracle提供了如下四种workaround:
1. Limit the size of the buffer from within the OCI code(使用OCI驱动时限制buffer大小(4000))
2. Use the database character set also as the client character set(数据库端和客户端的字符集保持一致)
3. Decrease the size of the columns(根据字符集的长度限制,减少列长度)
4. Do not use the multibyte character set as the database character set(不要使用多字节字符集作为数据库字符集)