Python_ Operating Oracle Database

Source: Internet
Author: User

1. cx_oracle

Python connects to the Oracle database and requires the use of the Cx_oracle package.

Of the package: http://cx-Oracle.sourceforge.net/

When downloading, note the version, for different versions of Oracle and platform, there are different cx_oracle.

2. Simple introduction of query operation

#Encoding:utf-8Importcx_oracle#parameter: username/password @ Listener (server host: Server port/server name)#conn = Cx_oracle.connect ("Test/[email protected]:1521/usertest")#parameters are: User name, password, listener (server host: Server port/server name)#conn = cx_oracle.connect ("Test", "root", "10.80.17.5:1521/usertest")#parameters are: User name, password, TSNconn = Cx_oracle.connect ("Test","Root","Test_user")#Create cursorcursor =conn.cursor () SQL="SELECT * FROM Student"#Execute SQL statementcursor.execute (SQL)#get all the recordsone =Cursor.fetchall ()#An access record for one entry forXinchOne :Printx#Close Cursorcursor.close ()#Close ConnectionConn.close ()

3. What is TSN?

TNS: A data connection string that represents a database connection and configures your data network connection, there will be a string like this.
This string can be found in your Oracle installation root \ora92\network\admin\tnsnames.sql, you can find this file in your Oracle installation directory,
Test_user=
(DESCRIPTION =
(Address_list =
(ADDRESS = (PROTOCOL = TCP) (HOST = 10.80.17.5) (PORT = 1521))
)
(Connect_data =
(service_name = usertest)
)
)
The "Test_user" above is what you want, TNS.

Python_ Operating Oracle Database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.