Python3读取Oracle Blob类型并存为pdf文件

Python3安装cx_Oracle

进入Python3安装目录,打开cmd窗口,输入命令:python -m pip install cx_Oracle --upgrade
或者在项目内输入同样的命令进行安装

D:\ProgramFiles\Python3102>python -m pip install cx_Oracle --upgrade
Collecting cx_Oracle
  Downloading cx_Oracle-8.3.0-cp310-cp310-win_amd64.whl (213 kB)
     |████████████████████████████████| 213 kB 262 kB/s
Installing collected packages: cx-Oracle
Successfully installed cx-Oracle-8.3.0

顺带升级pip版本:

D:\ProgramFiles\Python3102>python -m pip install --upgrade pip
Requirement already satisfied: pip in d:\programfiles\python3102\lib\site-packages (21.2.4)
Collecting pip
  Downloading pip-22.0.4-py3-none-any.whl (2.1 MB)
     |████████████████████████████████| 2.1 MB 192 kB/s
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.2.4
    Uninstalling pip-21.2.4:
      Successfully uninstalled pip-21.2.4
  WARNING: The scripts pip.exe, pip3.10.exe and pip3.exe are installed in 'D:\ProgramFiles\Python3102\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-22.0.4

主要Python编码

import cx_Oracle

def start():
    minID = 0
    maxID = 0
    outPath = "D:\\pdf\\"
    conn = cx_Oracle.connect(user="dbuser", password="dbpwd", dsn="127.0.0.1/orcl")
    cursor = conn.cursor()

    for row in cursor.execute(""" select * from tbl_attach """):
        #读取blob字段内容
        datas = row[5].read()
        #pdf名称字段
        name_origin = row[1]
        with open(outPath + name_origin, "wb") as f:
            f.write(datas)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值