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)