ORA-01704错误,插入长度超过4000个字符的字符串
我正在使用 PHP 将数据插入 Oracle 数据库。有一个数据类型为 CLOB 的表字段,但它允许插入最多 4000 个字符。我在 Google 上搜索了一下,发现 PL/SQL 可以向 CLOB 字段插入超过 4000 个字符。然后我打算使用Oracle Trigger来解决我的问题。我的计划是用 PLSQL 插入替换 PHP 插入查询。
create or replace
TRIGGER EXTEND_CLOB
BEFORE INSERT ON T_SESSIONS
for each row
BEGIN
insert into t_sessions (id,data,expires) values ( :new.id, :new.data, :new.expires );
END;
这个触发器可以工作,但它会插入2条记录(触发一次,PHP一次)。有没有办法忽略 PHP 的查询插入?
I am using PHP to insert data to Oracle db. There is a table field with datatype CLOB but it allows to insert upto 4000 characters. I did a bit of searching on Google and found that PL/SQL can insert more than 4000 chars to CLOB field. Then I plan to use Oracle Trigger to solve my problem. My plan is replace the PHP insert query with PLSQL insert.
create or replace
TRIGGER EXTEND_CLOB
BEFORE INSERT ON T_SESSIONS
for each row
BEGIN
insert into t_sessions (id,data,expires) values ( :new.id, :new.data, :new.expires );
END;
This trigger can work but it will insert 2 records (trigger once, PHP once). Is there anyway to ignore the query insert by PHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要插入一个大的 clob,一般需要执行两个步骤。
进行插入操作,将空 clob 插入表中,并将 clob 描述符返回到代码,然后写入该描述符。
我不是 PHP 编码员,但我以前在其他语言中使用过这种模式。
我做了一些搜索,你需要的代码大致类似于我下面给出的代码(我没有对此进行测试,因为我没有 PHP 环境设置)。
To insert a large clob, you need to do two steps in general.
Have an insert that inserts an empty clob into the table, and returns the clob descriptor to your code, and then write to that descriptor.
I am not a PHP coder, but I have used this pattern before in other languages.
I did some searches, and the code you need is roughly like what I have given below (I have not tested this, as I don't have a PHP environment setup).
oracle中的CLOB支持2GB的字符数据。
其他列,例如 varchar2 ,仅支持 4000。
我认为在您的情况下,它不是被填充并有问题的 CLOB,而是您尝试填充的另一列达到了限制。
在上面的插入命令中,您插入了 3 列,我不认为所有列都是 CLOB。
希望这有帮助,
亚历克斯
CLOB in oracle supports 2GB of character data.
Other columns , for example varchar2 , only support 4000.
I think in your case, its not the CLOB that gets filled and has a problem, its another column that you are trying to populate that reaches the limit.
In the insert comand above you are inserting in 3 columns, and i don't think that all are CLOB.
Hope this helps,
Alex