python -- 连接 orclae cx_Oracle的使用

时间:2021-07-21 21:46:18

 

 

 

 

 

import cx_Oracle                                                #引用模块cx_Oracle
conn=cx_Oracle.connect('oa/oa@192.168.0.70:1521/ekp')    #连接数据库


cursor = conn.cursor ()

try:
    # 解析sql语句
    # cursor.parse("select *  dual")
    pass
    # 捕获SQL异常
except cx_Oracle.DatabaseError as e:
    print(e)   # ORA-00923: 未找到要求的 FROM 关键字

# 执行sql 语句
cursor.execute ("select * from EKP_PRODUCTIVITY_SL")


for row in cursor:
    print(row)




c.close()                                                       #关闭cursor
conn.close()