从cx

编程入门 行业动态 更新时间:2024-10-14 20:27:45
本文介绍了从cx_oracle执行sql脚本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法在python中使用cx_oracle执行sql脚本文件。

Is there a way to execute a sql script file using cx_oracle in python.

我需要在sql文件中执行创建表脚本。

I need to execute my create table scripts in sql files.

推荐答案

p> PEP-249 ,cx_oracle尝试遵守真的有这样的方法。

PEP-249, which cx_oracle tries to be compliant with, doesn't really have a method like that.

但是,这个过程应该很简单。将文件的内容拉到一个字符串中,将其拆分成;字符,然后在生成的数组的每个成员上调用.execute。我假设;字符仅用于定界文件中的oracle SQL语句。

However, the process should be pretty straight forward. Pull the contents of the file into a string, split it on the ";" character, and then call .execute on each member of the resulting array. I'm assuming that the ";" character is only used to delimit the oracle SQL statements within the file.

f = open('tabledefinition.sql') full_sql = f.read() sql_commands = full_sql.split(';') for sql_command in sql_commands: curs.execute(sql_command)

更多推荐

从cx

本文发布于:2023-06-06 01:35:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/531145.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:cx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!