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