使用SQLAlchemy时,为什么insert语句在oracle中不起作用?

时间:2017-02-02 13:17:07

标签: python python-2.7 sqlalchemy

我使用SQLAlchemy和python 2.7连接到Oracle数据库。我可以验证连接字符串是否正常工作,SELECT语句是否产生正确的结果。但是,当我试图制作一个插入语句时,系统会挂起。

以下是代码:

oracle_select = "INSERT INTO Demographics " \
                "(Customer_ID, Gender, Marital_Status, Children, Birth_Date, Registration_Date, Store_Id, City, " \
                "Postal_Code, Mobile_Phone, Email, Last_Update, Mobile_App, Customer_Status) " \
                "VALUES " \
                "({0}, '{1}', '{2}', {3}, to_date('{4}', 'YYYY-MM-DD'), to_date('{5}', 'YYYY-MM-DD HH24:MI:SS'), " \
                "{6}, '{7}', {8}, '{9}', '{10}', to_date('{11}', 'YYYY-MM-DD HH24:MI:SS'), {12}, '{13}')"

with oracle_engine.connect() as connection:
    for r in results:
        connection.execute(oracle_select.format(r.customer_id, r.gender, r.marital_status, r.children, r.birth_date,
                                               r.registration_date, r.store_id, r.city, r.postal_code, r.mobile_phone,
                                               r.email, r.last_update, r.mobile_app, r.customer_status))

results是一个python数组,它包含前一个select语句中的相应对象。

0 个答案:

没有答案