使用Python操作Oracle

创建表,并插入数据

SQL> create table tbs(c1 varchar2(20),c2 varchar2(20));

Table created.

SQL> insert into tbs values('begin001','begin002');

1 row created.

SQL> commit;

Commit complete.

SQL> insert into tbs values('begin003','begin004');

1 row created.

SQL> commit;

Commit complete.

 

使用python操作Oracle

[root@master ~]# python
Python 2.7.11 (default, Jun  7 2016, 16:41:16) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> import os
>>> os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.ZHS16GBK'
>>> db=cx_Oracle.connect('begin001','begin001','172.16.41.154:1521/ortest')
>>> cur=db.cursor()
>>> rst=cur.execute("select * from tbs")
>>> for linestr in rst :
... 	print str(linestr[0])+","+linestr[1]
... 
begin001,begin002
begin003,begin004
>>>

 

关注dbDao.com的新浪微博

扫码加入微信Oracle小密圈,了解Oracle最新技术下载分享资源

TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569