加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

SQLAlchemy连接Oracle

发布时间:2020-12-12 15:07:06 所属栏目:百科 来源:网络整理
导读:SQLAlchemy是python下的数据库orm映射框架,几乎支持所有常用数据库,很受python开发者的青睐 SQLAlChemy依赖cx_oracle 先根据自己的python版本下载oracle库: cx_oracle 本地也要按照oracle的客户端,可以到甲骨文官网下载到 # coding: utf-8from sqlalchemy im

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',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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读