SQLAlchemy是python下的数据库orm映射框架, 几乎支持所有常用数据库, 很受python开发者的青睐
SQLAlChemy依赖cx_oracle
先根据自己的python版本下载oracle库: cx_oracle
本地也要按照oracle的客户端, 可以到甲骨文官网下载到
# coding: utf-8
from sqlalchemy import Column, Integer, String, create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Post(Base): __tablename__ = 't_post' id = Column('id', Integer, primary_key=True) date = Column('date', String) post = Column('post', String) name = Column('name', String) value = Column('value', String) time = Column('time', String)
engine = create_engine('oracle://username:password@192.168.1.6:1521/databasename', echo=True) Database= sessionmaker(bind=engine)
if __name__ == '__main__': db = Database() query = db.query(Post).filter(Post.name.like('%xxx')) print query.count() query = query.all()[30:40] for x in query: print x.id, x.name