使用 Oracle 存储过程压缩

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4405676/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:09:36  来源:igfitidea点击:

Zip using Oracle Stored Procedure

oraclestored-proceduresplsqlziputility

提问by Adeel Ansari

Right now I am using Oracle utility procedure, UTL_COMPRESS.LZ_COMPRESS(), to compress some data. But the problem is it compresses the thing using GZIP compatible format, which is not also ZIP compatible unfortunately. Therefore, the Windows XP native decompression utility can not open it (you know that compressed folder thingie). And user have to use some other utility, like 7Zip, Winzip, or Filzipetc., in order to decompress that.

现在我正在使用 Oracle 实用程序UTL_COMPRESS.LZ_COMPRESS()来压缩一些数据。但问题是它使用 GZIP 兼容格式压缩东西,不幸的是,它也不兼容 ZIP。因此,Windows XP 本机解压实用程序无法打开它(您知道压缩文件夹的东西)。而且用户必须使用一些其他的工具,如7ZipWinzipFilzip等,以解压缩。

So, we end up having a plan of retrieving GZIP data from Oracle, uncompress it using Java, and compress it back to ZIP (something that can be decompressed by Windows utility). It sounds ridiculous to compress-in-gzip -> decompress -> compress-again-in-zip.

因此,我们最终制定了从 Oracle 检索 GZIP 数据的计划,使用 Java 对其进行解压缩,然后将其压缩回 ZIP(可以通过 Windows 实用程序解压缩的内容)。听起来很可笑compress-in-gzip -> decompress -> compress-again-in-zip

Any idea how can we compress it in the desirable format in the first place, to avoid all this extra computation?

知道我们如何首先将其压缩为所需的格式,以避免所有这些额外的计算吗?

回答by APC

There is a Java package java.util.zipwhich supports the WinZip format. And in Oracle we can build java stored procedures which present Java classes in a form which can be called by native PL/SQL programs. Find out more.

有一个java.util.zip支持 WinZip 格式的 Java 包。而在 Oracle 中,我们可以构建 Java 存储过程,这些过程以一种可由本机 PL/SQL 程序调用的形式呈现 Java 类。 了解更多

So what you need to do is write out a file containing the data in its uncompressed state and then feed it through a JSP to zip it. If you don't want to write your own implementation then check out this article by Vadim Loevski. It includes a Java Stored Procedure for zipping OS files.

因此,您需要做的是写出一个包含未压缩状态数据的文件,然后通过 JSP 将其送入压缩。如果您不想编写自己的实现,请查看Vadim Loevski 的这篇文章。它包括一个用于压缩 OS 文件的 Java 存储过程。



Note: In this context JSP means Java Stored Procedure, which is a Java program embedded in the database. It is not the same as Java Server Pages, which is a web technology, and hence the more common usage for the JSP acronym. I apologise for any confusion given.

注意:在此上下文中,JSP 表示 Java 存储过程,它是嵌入在数据库中的 Java 程序。它与 Java Server Pages 不同,后者是一种 Web 技术,因此是 JSP 首字母缩写词的更常见用法。对于任何引起的混乱,我深表歉意。

回答by Gary Myers

UTL_RAW.CAST_TO_RAW is not any sort of compression algorithm. No idea where you came up with the idea that it was. RAW (and its larger cousin BLOB) are simply was of storing data that isn't a number, date or a string. You don't want to store binary data in strings because there's a chance of character conversion issues.

UTL_RAW.CAST_TO_RAW 不是任何类型的压缩算法。不知道你是从哪里想到的。RAW(及其更大的表亲 BLOB)只是用于存储不是数字、日期或字符串的数据。您不想将二进制数据存储在字符串中,因为可能会出现字符转换问题。

The correct PL/SQL package for compression is UTL_COMPRESS which uses the standard Lempel-Ziv algorithm.

用于压缩的正确 PL/SQL 包是使用标准 Lempel-Ziv 算法的 UTL_COMPRESS。

http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16760/u_compr.htm#BGBBCDDI

http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16760/u_compr.htm#BGBBCDDI

回答by yallie

as_zip(blog post) is a native PL/SQL package to manipulate ZIP archives.
It handles files of up to 4 gigabytes (looks like limitation of the original ZIP format).
The package is written by Anton Schefferand is MIT-licensed.

as_zip博客文章)是一个用于操作 ZIP 档案的本机 PL/SQL 包。
它可以处理高达 4 GB 的文件(看起来像原始 ZIP 格式的限制)。
该软件包由Anton Scheffer编写并获得 MIT 许可。