cx_Oracle for python
2014-02-13cx_Oracle是一个用来连接并操作Oracle数据库的Python扩展模块,支持包括Oracle9.2, 10g以及11g等版本。
cx_Oracle 7 need Python 2.7 or 3.5 and higher,Older versions of cx_Oracle may work with older versions of Python.
#!/usr/bin/python
import cx_Oracle
print cx_Oracle.version;
print dir(pyev)
help(cy_Oracle)
1、下载网址:
http://sourceforge.net/projects/cx-oracle
#!/bin/sh
yum -y install git python-devel libaio libaio-devel
git clone https://github.com/oracle/python-cx_Oracle.git cx_Oracle
cd cx_Oracle
git submodule init
git submodule update
python setup.py install
2、unzip instantclient-basic-macos.x64-12.2.0.1.0.zip
Add links to $HOME/lib
or /usr/local/lib
to enable applications to find the library
vi /etc/ld.conf.d/ora.conf
ldconfig
3、mkdir -p /opt/oracle/instantclient_12_2/network/admin
tnsnames.ora
Then set the environment variable
export TNS_ADMIN=$ORACLE_HOME/network/admin
4、实例:
more alter_viewer_page_id.py
#!/usr/bin/env python
import cx_Oracle
import date
ym=time.strftime('%Y%m')
sql='alter table VIEWER_'+ ym + ' modify PAGE_ID NUMBER(12)'
conn = cx_Oracle.connect('viewer/123456@192.168.1.32:1521/mydb')
cursor = conn.cursor()
cursor.execute(sql)
cursor.close()
5、
#!/usr/bin/python
import cx_Oracle
conn = cx_Oracle.connect('tuser/123455@172.16.1.206:1521/dbpri')
cursor = conn.cursor()
cursor.execute('Select tablespace_name,file_name from dba_data_files')
for ts_name,fname in cursor:
print(ts_name,fname)
cursor.close()
6、
#!/usr/bin/python
import cx_Oracle
#conn = cx_Oracle.connect('tu/123456@1.1.1.2:1521/mydb')
#conn = cx_Oracle.connect('tu/123456@db')
conn = cx_Oracle.connect('tuser/9911@ip:1521/idb')
cursor = conn.cursor()
#result=cursor.execute('Select count(*) from test')
#result=
cursor.execute('Select tablespace_name,file_name from dba_data_files')
#data=cursor.fetchone()
#print (data)
all_data=cursor.fetchall()
print(all_data)
#many_data=cursor.fetchmany(8)
#print (many_data)
cursor.close()
相关日志
- oracle中drop一个表,让数据文件释放空间
- oracle批量杀掉死锁进程
- ORA-00257: archiver error. Connect internal only, until freed. (DBD ERROR: OCISessionBegin)
- oracle同义词SYNONYM
- substr()函数
- oracle create dblink
- oracle 启动归档模式
- oracle表空间文件
- linux删除oracle表空间文件后空间不释放
- nagios check_oracle_health install shell
- oracle最大连接数processes
- nagios check_oracle_health
- 数据库查询重复行shell脚本
- oracle导入txt数据文件实例
- mysql导入txt数据文件实例
- 修改NLS_CHARACTERSET和NLS_NCHAR_CHARACTERSET字符集
- NLS_NCHAR_CHARACTERSET和NLS_CHARACTERSET的区别
- 如何安装mysql-5.6.12
- 设置NLS_LANG环境变量
- Oracle Golden Gate数据库同步技术
- mysql或oracle合并行函数
- Oracle InstantClient安装步骤
- shell sqlplus run sql
- oracle误删datafile
- mysqld_safe — MySQL Server Startup Script
- 如何禁用mysql端口3306
- oracle触发器实例 (8)
- sql语句处理BLOB (8)
- Drizzle A database for the Cloud (1)
- SGA/PGA的设置与调整 (9)
- 根据v$SGA_TARGET_ADVICE设置SGA SIZE (6)
- shmmax/shmall和sga_max_size/sga_target应该设置多大 (3)
- exp/imp和expdp/impdp的逻辑哲学 (1)
- oracle安装后期stop big port (1)
- OLTP和OLAP的区别 (3)
- mysql创建数据库及用户 (1)
- Mysql分支MariaDB简介 (6)
- ORA-01843: not a valid month (3)
- sql语句where 1=1和1=2的作用 (4)
- 如何安装mysql-5.5.31 (8)
- rlwrap实现sqlplus使用上下键查历史命令
- CentOS_x64_6.3 install Oracle 10.2.0.1报错ins_emdb.mk (2)