【问题标题】:How to execute non sql commands in python using cx_Oracle如何使用 cx_Oracle 在 python 中执行非 sql 命令
【发布时间】:2014-04-09 20:11:19
【问题描述】:

我是 python 新手。有人可以帮我弄清楚如何在 python 中使用 cx_Oracle 执行以下命令吗?

  1. 假脱机 C:\drop_tables.sql
  2. 选择“删除表”||表名 || '级联约束;' FROM user_tables;
  3. 线轴关闭
  4. @C:\drop_tables.sql

我知道我可以将 cursor.execute() 用于第二个命令,但对于其他非 sql 命令,特别是 1 和 3,我没有任何线索。

如果有人可以提供帮助,我们将不胜感激。

谢谢, 阿拉维

【问题讨论】:

  • 你为什么需要使用SPOOL?难道你不能直接将光标中的表名读入一个列表,然后为列表中的每个表运行DROP TABLE 语句吗?

标签: python cx-oracle


【解决方案1】:

所以我通过以下方式实现了我所需要的

cur.execute("SELECT table_name FROM user_tables")

结果 = cur.fetchall()

结果中的行:

cur.execute('DROP TABLE ' + row[0] + ' CASCADE CONSTRAINTS')*

非常感谢卢克的想法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-18
    • 1970-01-01
    • 2020-03-16
    • 2021-04-26
    • 2019-06-23
    • 2018-06-25
    • 2014-10-18
    相关资源
    最近更新 更多