繁体   English   中英

使用 Python 从 oracle 数据库中提取文件

[英]Extract files from an oracle database with Python

我正在使用cx_Oracle访问 mon Oracle 数据库我一直在寻找一种从数据库中提取文件的方法,但我找不到解决方案。 通过提取我的意思是下载。 这是我到目前为止得到的:

from types import prepare_class
from typing import overload
import cx_Oracle

dsn_tns = cx_Oracle.makedsn('****', '****', service_name='****')
conn = cx_Oracle.connect(user=r'****', password='****', dsn=****)

c = conn.cursor()
c.execute('my request')

for row in c:
    print (row[0], '-', row[1])
conn.close()

我不知道我是否需要使用外部库或直接请求。

如果您有一列带有名称,另一列带有文件内容,您可以执行以下操作:

for fileName,fileContents in c.execute('select fileName,file contents from the_table'):
    with open(fileName, w) as f:
        F.write(fileContents)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM