oracle oracle中如何导出和导入BLOB数据类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10952414/
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
how to export and import BLOB data type in oracle
提问by Anbu
how to export and import BLOB data type in oracle using any tool. i want to give that as release
如何使用任何工具在 oracle 中导出和导入 BLOB 数据类型。我想把它作为释放
回答by Kris Rice
Answering since it has a decent view count even with it being 5 year old question..
回答是因为它有一个不错的观看次数,即使它是 5 岁的问题..
Since this question was asked 5 years ago there's a new tool named SQLcl ( http://www.oracle.com/technetwork/developer-tools/sqlcl/overview/index.html)
由于这个问题是 5 年前提出的,因此有一个名为 SQLcl 的新工具(http://www.oracle.com/technetwork/developer-tools/sqlcl/overview/index.html)
We factored out the scripting engine out of SQLDEV into cmd line. SQLDev and this are based on java which allows usage of nashorn/javascript engine for client scripting. Here's a short example that is a select of 3 columns. ID just the table PK , name the name of the file to create, and content the BLOB to extract from the db.
我们将 SQLDEV 中的脚本引擎分解为 cmd 行。SQLDev 和它基于 java,它允许使用 nashorn/javascript 引擎进行客户端脚本编写。这是一个选择 3 列的简短示例。ID 只是表 PK ,命名要创建的文件的名称,以及内容要从数据库中提取的 BLOB。
The script command triggers this scripting. I placed this code below into a file named blob2file.sql
脚本命令触发此脚本。我将此代码放在下面的名为 blob2file.sql 的文件中
All this adds up to zero plsql, zero directories instead just some sql scripts with javascript mixed in.
所有这些加起来为零 plsql,零目录,而只是一些混合了 javascript 的 sql 脚本。
script
// issue the sql
// bind if needed but not in this case
var binds = {}
var ret = util.executeReturnList('select id,name,content from images',binds);
// loop the results
for (i = 0; i < ret.length; i++) {
// debug messages
ctx.write( ret[i].ID + "\t" + ret[i].NAME+ "\n");
// get the blob stream
var blobStream = ret[i].CONTENT.getBinaryStream(1);
// get the path/file handle to write to
// replace as need to write file to another location
var path = java.nio.file.FileSystems.getDefault().getPath(ret[i].NAME);
// dump the file stream to the file
java.nio.file.Files.copy(blobStream,path);
}
/
The result is my table emptied into files ( I only had 1 row ). Just run as any plain sql script.
结果是我的表被清空成文件(我只有 1 行)。只需像任何普通的 sql 脚本一样运行。
SQL> @blob2file.sql
1 eclipse.png
blob2file.sql eclipse.png
SQL>