如何获取DDL命令的输出python cx_oracle

发布于 2025-01-22 18:17:01 字数 209 浏览 3 评论 0原文

我目前正在与CX_oracle一起

使用SELECT语句,我可以使用fetchall()函数来获取行。

但是如何获取属于数据定义语言(DDL)类别的查询的输出。

例如,在使用Cursor.execute()执行赠款语句之后,假设查询有效的预期输出将是

“成功执行的授予”

,但是我如何使用cx_oracle,python获得此信息。

I am currently working with cx_oracle

Here with SELECT statements I am able to use the fetchall() function to get rows.

But how to get the outputs for queries that fall under Data Definition Language (DDL) category.

For example, after executing a GRANT statement with cursor.execute(), the expected output assuming the query is valid would be,

"GRANT executed successfully"

But how do I get this with cx_oracle, Python.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断肠人 2025-01-29 18:17:01

答案是您自己打印了,这就是SQL*Plus的作用。

DDL语句是语句而不是查询,因为它们不返回数据。他们将成功或错误条件归还执行它们的工具,然后可以打印任何消息。在您的情况下,该工具是cx_oracle。没有办法在CX_oracle中自动获取语句的类型(授予,创建等)。您的应用程序可以打印一条通用消息,例如“成功执行的语句”,也可以从SQL语句中提取第一个关键字,因此您可以打印像SQL*Plus这样的消息。

The answer is that you have print it yourself, which is what SQL*Plus does.

DDL statements are statements not queries because they do not return data. They return a success or error condition to the tool that executed them, which can then print any message. In your case the tool is cx_Oracle. There isn't a way to get the type (GRANT, CREATE etc) of the statement automatically in cx_Oracle. Your application can either print a generic message like 'statement executed successfully', or you can extract the first keyword(s) from the SQL statement so you can print a message like SQL*Plus does.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文