title: cx_Oracle库使用
date: 2016-06-19 11:22:12
tags: [oracle,python,web2py]
cx_Oracle使用
import cx_Oracle as orcl
print(orcl.clientversion())
username = "scott"
passwd = "123456"
host = "192.168.1.116"
port = "1521"
sid = "orcl"
dsn = orcl.makedsn(host, port,service_name= sid)
con = orcl.connect(username, passwd, dsn)
cursor = con.cursor()
sql = "SELECT ENAME, EMPNO FROM EMP"
cursor.execute(sql);
result = cursor.fetchall()
print("Total: " + str(cursor.rowcount))
for row in result:
print(row)
cursor.close()
con.close()
print(orcl.Date(2015,3,13))
web2py中间件pydal使用
from gluon import DAL, Field
db = DAL('oracle://scott/tiger@192.168.1.100:1521/orcl')
db.define_table('dept',Field('DEPINO'),Field('DNAME'),Field('LOC'))
print db(db.test.DEPINO != "").select()
其他
创建数据库、创建数据表语句。
#表结构复制
create database link orcl CONNECT TO GW IDENTIFIED BY "******" USING 'R5DEV_223';
CREATE TABLE testout.tab_users AS SELECT * FROM xyzdev.tab_users@orcl;
create table testout.tab_users as select * from xyzdev.tab_users where 1=2