python访问oracle_python 连接 oracle

pip install cx_Oracle

下载oracel 客户端 instantclient-basic-windows.x64-18.5.0.0.0dbru.zip ,不下载客户端可能有以下报错:

DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "The specified module could not be found". See https://oracle.github.io/odpi/doc/installation.html#windows for help

解压文件到脚本 的下级目录,或者设置路径到环境变量

#encoding=utf-8

import cx_Oracle as oracle

import os

#print(os.environ["path"])

set_path = os.environ["path"]

oracle_path = "..\\instantclient_18_5"

os.environ["path"] = ';'.join((set_path,oracle_path)) # oracle 路径 暂时加到 环境变量

#print(os.environ["path"])

def checkCodeFor2():

print("##########查询2号验证码#############\n")

db = oracle.connect("账号", "密码", 'ip:1521/库名')

cur = db.cursor()

while(1):

emp_id = input("请输入查询的ID:\n")

if emp_id:

try:

cur.execute('select a.code,a.id from db_test a where a.id={}'.format(emp_id))

#cursor.execute('select 1;')

data = cur.fetchone()

print(data)

check_sign = input("是否继续查询:Y/y 是 /N 否,其他任意字符都退出\n")

if check_sign.lower() == "y":

pass

else:

return 0

except oracle.DatabaseError as e:

msg_error = e

print("可能数据输入错误,请检查数据正确性,错误:\n{}".format(msg_error))

else:

pass

if __name__=="__main__":

checkCodeFor2()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值