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