cx_oracle_cx_Oracle的基础

cx_oracle

Recently I’ve been working a lot with Oracle Databases and Python. Although Oracle is a big company, I found there’s not such a strong community to help with their package in Python for dealing with databases, cx_Oracle, and I found their documentation not that great.

最近,我一直在与Oracle数据库和Python一起工作。 尽管Oracle是一家大公司,但我发现并没有一个强大的社区来帮助他们使用Python处理数据库cx_Oracle的软件包,而且我发现他们的文档不是很好。

So, I decided to do this post following my philosophy of writing posts that the Thiago (me) of 1 month ago would have thanked for.

因此,我决定按照我的写作哲学来写这篇文章,这是1个月前的Thiago(我)会感谢的。

1.连接到数据库 (1. Connect to the database)

The first thing to do is to connect to your database. In this case, probably you have an user and a password. Also, you should have the data source name. With all of those in hand you can connect to the database:

首先要做的是连接到数据库。 在这种情况下,您可能有一个用户和一个密码。 另外,您应该具有数据源名称。 有了这些,您可以连接到数据库:

Easy peasy!

十分简单!

2.执行SQL命令 (2. Execute SQL Commands)

With cx_Oracle you can execute any Oracle SQL command, selects, inserts, updates etc. In order to execute the commands, you have to create a cursor. You can use the same cursor for running several commands. I just recommend you to use a connection and a cursor for each function in your application. So, you create a connection and a cursor in the beginning of your function and close them at the end.

使用cx_Oracle,您可以执行任何Oracle SQL命令,选择,插入,更新等。为了执行命令,必须创建一个游标。 您可以使用同一光标运行多个命令。 我只建议您为应用程序中的每个功能使用连接和游标。 因此,您可以在函数的开头创建一个连接和一个游标,然后在结尾处将其关闭。

2.1选择语句 (2.1 Select Statements)

It is important to mention here that the fetchone() and

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值