运维联盟俱乐部

 找回密码
 立即注册
查看: 1619|回复: 0

[日常管理] cx_oracle

[复制链接]
  • TA的每日心情
    开心
    2023-8-9 11:05
  • 发表于 2020-7-31 09:36:12 | 显示全部楼层 |阅读模式
    1.更新cx_oracle
    1. C:\Users\zhyu>python
    2. Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
    3. Type "help", "copyright", "credits" or "license" for more information.
    4. >>> exit()

    5. C:\Users\zhyu>python -m pip install cx_Oracle --upgrade
    6. Collecting cx_Oracle
    7.   Downloading cx_Oracle-8.0.0-cp38-cp38-win_amd64.whl (203 kB)
    8.      |████████████████████████████████| 203 kB 9.4 kB/s
    9. Installing collected packages: cx-Oracle
    10.   Attempting uninstall: cx-Oracle
    11.     Found existing installation: cx-Oracle 7.3.0
    12.     Uninstalling cx-Oracle-7.3.0:
    13.       Successfully uninstalled cx-Oracle-7.3.0
    14. Successfully installed cx-Oracle-8.0.0
    15. WARNING: You are using pip version 20.1.1; however, version 20.2 is available.
    16. You should consider upgrading via the 'C:\Python38\python.exe -m pip install --upgrade pip' command.
    复制代码
    2.简单查询示例
    1. C:\Users\zhyu>python
    2. Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
    3. Type "help", "copyright", "credits" or "license" for more information.
    4. >>> import cx_Oracle
    5. >>> conn=cx_Oracle.connect('zhyu/zhyu@192.168.56.101:1521/ora19')
    6. >>> curs=conn.cursor()
    7. >>> sql='select * from t1'
    8. >>> rr=curs.execute(sql)
    9. >>> row=curs.fetchall()
    10. >>> print(row)
    11. [(2, 'zhangyu'), (1, 'zangyu')]
    12. >>> curs.close()
    13. >>> conn.close()
    14. >>> exit()
    复制代码
    3.简单插入示例
    1. >>> ora19=cx_Oracle.connect('zhyu/zhyu@192.168.56.101:1521/ora19')
    2. >>> curs=ora19.cursor()
    3. >>> sql='''
    4. ... insert into t1 values(4,'zhangyu')
    5. ... '''
    6. >>> runsql=curs.execute(sql)
    7. >>> ora19.commit()
    8. >>> sql1='select * from t1'
    9. >>> runsql=curs.execute(sql1)
    10. >>> res=curs.fetchall()
    11. >>> print(res)
    12. [(2, 'zhangyu'), (3, 'zhangyu'), (4, 'zhangyu'), (1, 'zangyu')]
    复制代码
    4.sys用户 as sysdba连接
    1. >>> ora19=cx_Oracle.connect('sys/oracle@192.168.56.101:1521/ora19',mode=cx_Oracle.SYSDBA)
    2. >>> curs=ora19.cursor()
    3. >>> sql='select * from dba_users'
    4. >>> runsql=curs.execute(sql)
    5. >>> res=curs.fetchall()
    6. >>> print(res)
    7. [('SYS', 0, None, 'OPEN', None, datetime.datetime(2019, 10, 14, 0, 56, 32)]
    复制代码







    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    运维联盟俱乐部 ( 冀ICP备19036648号 )

    GMT+8, 2024-5-17 11:24 , Processed in 0.057313 second(s), 21 queries , Gzip On.

    Powered by Discuz! X3.4

    © 2001-2023 Discuz! Team.

    快速回复 返回顶部 返回列表