cx_Oracle连接oracle数据库
一、准备工作
#下载oracle客户端 https://www.oracle.com/database/technologies/instant-client/downloads.html #windows都下载32位
#下载后解压,将解压后的路径添加到系统环境变量中
#如果用Navicat的话,在选项OCI配置内加载oci.dll文件
二、单表代码
import datetime import cx_Oracle # 建立数据库链接 connection = cx_Oracle.connect("用户名", "密码", "ip地址/orcl") cursor = connection.cursor() # 查询sql sql = '''SELECT * FROM table''' rows = cursor.execute(sql) for row in rows: print(row) # 插入sql insert_sql='''INSERT INTO table VALUES(:tuser,:date_time) ''' cursor.execute(insert_sql,{"tuser":"maple","date_time":datetime.datetime.now()}) connection.commit() # 修改sql update_sql='''UPDATE table SET date_time = :v WHERE user = :n''' cursor.execute(update_sql,{'v':datetime.datetime.now(),"n":"maple"}) connection.commit() cursor.close() connection.close()
三、多表代码
等待更新。。。。