python链接oracle

LINUX下python 链接 oracle

打开链接下载oracle并解压

https://github.com/oracle/odpi

oracle_client

把解压的oracle文件放入/opt/oracle/目录下

操作步骤

sudo mkdir -p /opt/oracle

sudo mv instantclient_18_3 /opt/oracle/

cd /opt/oracle

sudo sh -c "echo /opt/oracle/instantclient_18_3 > /etc/ld.so.conf.d/oracle-instantclient.conf" #注意版本对应instantclient_18_3

sudo ldconfig

export LD_LIBRARY_PATH=/opt/oracle/instantclient_18_3:$LD_LIBRARY_PATH


mkdir -p /opt/oracle/instantclient_18_3/network/admin 

下载libaio

sudo apt install libaio-dev

示例代码

# -*- coding: utf-8 -*-
# python  with oracle
# https://github.com/oracle/odpi


import cx_Oracle
#引用模块cx_Oracle
import os

def conn_sql():

    os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'

    db_user ="trff_zjk"
    db_passwd ="trff_zjk"
    db_host ="192.168.50.10:1521"

    # 数据库表名
    table_name = 'WX_ZPXX_20181227_02'

    # 数据库链接信息
    conn_info = db_user+"/"+ db_passwd +"@"+ db_host +"/orcl"
    conn=cx_Oracle.connect(conn_info)

    #连接数据库
    c=conn.cursor()
    return c

Oracle 分页

SELECT * FROM 
(
SELECT A.*, ROWNUM RN 
FROM (SELECT * FROM TABLE_NAME) A 
WHERE ROWNUM <= 40
)
WHERE RN >= 21

内容出处:,

声明:本网站所收集的部分公开资料来源于互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。如果您发现网站上有侵犯您的知识产权的作品,请与我们取得联系,我们会及时修改或删除。文章链接:http://www.yixao.com/share/29022.html

发表评论

登录后才能评论