读取 lob 时出现 cx_Oracle MemoryError

发布于 2024-07-29 18:52:38 字数 382 浏览 4 评论 0原文

当尝试使用 cx_Oralce 从 lob 字段读取数据时,我收到“exceptions.MemoryError”。 这段代码一直有效,这个 lob 字段似乎太大了。

Example:
xml_cursor = ora_connection.cursor()
xml_cursor.arraysize = 2000
try:
    xml_cursor.execute(“select xml_data from xmlTable where id = 1”)
    for row_data in xml_cursor.fetchall():
        str_xml = str(row_data[0])  #this throws “exceptions.MemoryError”

When trying to read data from a lob field using cx_Oralce I’m receiving “exceptions.MemoryError”. This code has been working, this one lob field seems to be too big.

Example:
xml_cursor = ora_connection.cursor()
xml_cursor.arraysize = 2000
try:
    xml_cursor.execute(“select xml_data from xmlTable where id = 1”)
    for row_data in xml_cursor.fetchall():
        str_xml = str(row_data[0])  #this throws “exceptions.MemoryError”

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帥小哥 2024-08-05 18:52:38

是的,如果 Python 给出 MemoryError,则意味着该行中的一个字段占用的内存比您拥有的内存多(当然对于 LOB 来说这是可能的)。 您必须将其分割并分成块(反复使用 select dbms_lob.substr(xml_data, ...) 并将其提供给增量 XML 解析器(或将其写出到文件中) ,或者您尝试使用该多 GB LOB 执行的任何操作)DBMS_LOB 是 Oracle 提供的一个文档齐全的软件包,您可以在很多地方找到它的文档,例如 < a href="http://www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10802/d_lob.htm" rel="noreferrer">此处。

Yep, if Python is giving MemoryError it means that just that one field of that just one row takes more memory than you have (quite possible with a LOB of course). You'll have to slice it up and get it in chunks (with select dbms_lob.substr(xml_data, ... repeatedly) and feed it to an incremental XML parser (or write it out to a file, or whatever is it that you're trying to do with that multi-GB LOB). DBMS_LOB is a well-documented Oracle-supplied package, and you can find its docs in many places, e.g. here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文