如何使用sql炼金术检索每个列值

时间:2015-06-12 11:14:21

标签: python python-2.7

我正在使用SQL Alchemy连接到驻留在Linux机器中的Oracle 11g数据库。我正在用Python编写一个脚本来连接数据库并从特定的表中检索值。

我写的代码是:

    from sqlalchemy import *
    def db_connection():
    config = ConfigParser.RawConfigParser()
    config.read('CMDC_Analyser.cfg')
    USER = config.get('DB_Connector','db.user_name' )
    PASSWORD = config.get('DB_Connector','db.password' )
    SID = config.get('DB_Connector','db.sid' )
    IP = config.get('DB_Connector','db.ip')
    PORT = config.get('DB_Connector','db.port')
    engine = create_engine('oracle://{user}:{pwd}@{ip}:{port}/{sid}'.format(user=USER, pwd=PASSWORD, ip=IP, port=PORT, sid=SID), echo=False)
    global connection
    connection = engine.connect()
    p = connection.execute("select * from ssr.bouquet")
    for columns in p:
        print columns
    connection.close()

表格中的完整值打印在此处。我想只从特定列中选择值。因此我使用了以下代码:

    for columns in p:
            print columns['BOUQUET_ID']

但在这里我收到以下错误。

sqlalchemy.exc.NoSuchColumnError:“找不到列'BOUQUET_ID'的行中的列”

如何解决这个问题?

0 个答案:

没有答案