使用 Oracle SQL Developer 将 CLOB 导出到文本文件
我正在使用 Oracle SQL Developer 并尝试将表导出到 CSV 文件。有些字段是 CLOB 字段,在许多情况下,导出时条目会被截断。我正在寻找一种方法来解决整个问题,因为我的最终目标是不在这里使用 Oracle(我收到了一个 Oracle 转储 - 它已加载到 Oracle 数据库中,但我正在使用另一种格式的数据,因此通过CSV 作为中介)。
如果对此有多种解决方案,鉴于这对我来说是一次性过程,我不介意使用更多黑客类型的解决方案来解决更多涉及的“正确执行”解决方案。
I am using Oracle SQL Developer and trying to export a table to a CSV file. Some of the fields are CLOB fields, and in many cases the entries are truncated when the export happens. I'm looking for a way to get the whole thing out, as my end goal is to not use Oracle here (I received an Oracle dump - which was loaded into an oracle db, but am using the data in another format so going via CSV as an intermediary).
If there are multiple solutions to this, given that it is a one time procedure for me, I don't mind the more hack-ish type solutions to more involved "do it right" solutions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您有权访问数据库盒上的文件系统,您可以执行以下操作:
我复制并粘贴了 来自此网站。
您还可能会找到有关 UTL_FILE 的上一个问题 有用。它解决了导出到 CSV 的问题。然而,我不知道或没有 UTL_FILE 如何处理 CLOB 的经验。
if you have access to the file system on your database box you could do something like this:
Which I copied and pasted from this site.
You may also find this previous question about UTL_FILE useful. It addresses exporting to CSV. I have no idea or experience with how UTL_FILE handles CLOBs, however.
您可以使用 Python 脚本来处理导出,CLOB 不会被截断:
仅供参考:帮助安装 cx_Oracle
You can use a Python script to take care of the export, the CLOBs won't get truncated:
FYI: Help installing cx_Oracle
假设 Oracle 转储是指 .dmp(来自导出或 expdp),那么您正在查看一个二进制文件。您需要将转储文件导入 Oracle 数据库,然后使用 UTL_FILE 或其他方式将数据导出为纯文本。
assuming by an Oracle dump you meant a .dmp (either from export or expdp), you're looking at a binary file. You'll need to import the dumpfile into an Oracle database and then export the data to plain text using UTL_FILE or other means.
这是一个简短而通用的 python 脚本,它就是这样做的 - 将表(其中包含 CLOB 字段)转储到平面 csv 文件: OraDump
Here is a short yet general python script that does just this - dumping tables (with CLOB fields, among the rest) to a flat csv file: OraDump
由于明确提到了 Oracle SQL Developer 并鼓励“hack-ish 类型解决方案”(以防万一有人仍然需要……):
如果从 SQL 工作表(在 Oracle SQL Developer 中)执行单个语句,则会显示结果作为一张桌子。
单击结果表后,使用键盘快捷键或编辑菜单首先标记整个表,然后复制其内容。
继续使用您选择的文本编辑器。粘贴。保存到文件。希望完成。 ;-)
即使对于超过 4000 个字符的 CLOB 也适用。它是否真的有帮助,很大程度上取决于 CLOB 的实际内容。有时,一些 SQL 预处理可能会帮助您...
或者尝试在结果表的本地菜单中导出...。从那里开始使用 Excel 95-2003 格式选项可能会起作用(比 CSV 或文本/TSV 更好)。
如果需要调整/进一步的细节,请发表评论。
As Oracle SQL Developer is explicitly mentioned and "hack-ish type solutions" were encouraged (and in case somebody is still in need…):
If a single statement is executed from a SQL Worksheet (in Oracle SQL Developer), the result is displayed as a table.
After clicking the result table, use either keyboard shortcuts or the Edit menu to first mark the whole table and then to copy its content.
Proceed to your text editor of choice. Paste. Save to a file. Hopefully done. ;-)
Works even for CLOBs exceeding 4000 characters. Whether or not it actually helps, will very much depend on the CLOBs' actual content. Sometimes some SQL pre-processing might get you there…
Alternatively try in the result table's local menu Export…. Going from there through the Excel 95-2003 format option might work (better than CSV or text/TSV).
Please comment, if and as this requires adjustment / further detail.