从 SQL Developer 将 CLOB 插入 Oracle 数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22788024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Insert CLOB into Oracle database from SQL Developer
提问by StaNov
I want to insert the same long string into all cells in certain column, which is CLOB type.
我想将相同的长字符串插入特定列的所有单元格中,这是 CLOB 类型。
It said I should use "bind variables" to do it. So i Googled this:
它说我应该使用“绑定变量”来做到这一点。所以我用谷歌搜索了这个:
variable xmlstuff CLOB;
exec :xmlstuff := '<?xml version="1.0"?> ... really long xml...';
UPDATE TABLE_NAME SET COLUMN_NAME = '&&xmlstuff';
Now it still says
现在它仍然说
The string literal is longer than 4000 characters.
What is the proper use of bind variable in this case?
在这种情况下,绑定变量的正确用法是什么?
回答by evenro
If you are programming using C# or Java - just use the OracleCLOB object, and it will do all the necessary steps.
如果您使用 C# 或 Java 进行编程 - 只需使用 OracleCLOB 对象,它将完成所有必要的步骤。
If you want to use a CLOB in SQL or PL/SQL,
you need to allocate it, and release it after using.
search for DBMS_LOB information.
如果要在 SQL 或 PL/SQL 中使用 CLOB,则需要对其进行分配,并在使用后释放。
搜索 DBMS_LOB 信息。
Regarding the 4000 bytes limit - this is a varchar2 limit within SQL.
to bypass this - you can use PL/SQL - which limits you to a varchar of 32KB, which is not as near to the 4GB that you can hold in a CLOB, but that is the limit for "automatic" creation of a CLOB.
if your string is longer than 32K - you'll have to use a DBMS_LOB to load the data into the clog object, by using append on the clob object.
关于 4000 字节限制 - 这是 SQL 中的 varchar2 限制。
要绕过这个 - 您可以使用 PL/SQL - 它将您限制为 32KB 的 varchar,这与您可以在 CLOB 中容纳的 4GB 不太接近,但这是“自动”创建 CLOB 的限制。
如果您的字符串长于 32K - 您将必须使用 DBMS_LOB 通过在 clob 对象上使用 append 将数据加载到 clog 对象中。
this is the fastest link I found about how to do it: http://geekswithblogs.net/robertphyatt/archive/2010/03/24/write-read-and-update-oracle-clobs-with-plsql.aspx
这是我找到的有关如何执行此操作的最快链接:http: //geekswithblogs.net/robertphyatt/archive/2010/03/24/write-read-and-update-oracle-clos-with-plsql.aspx
I wanted to answer fast, so please let me know if you cannot solve your issue after getting this information - and I'll try to explain it better.
我想快速回答,所以如果您在获得此信息后无法解决您的问题,请告诉我 - 我会尝试更好地解释它。