We may need to manipulate the Oracle database in our tests, such as a scenario where the data is inserted into Oracle while another tool reads from it, and how to ensure that the data being read is sequential, that is, first inserted into the first read out, According to this scenario, you first need to create a script that continually inserts data into the Oracle database. This time we think of the Python cx_oracle library, which we will implement:
Import Cx_oracleimport timeisotimeformat= '%y-%m-%d%x ' def connectoracle (): Conn=cx_oracle.connect (' Dwa/[email Protected]:1521/orcl ') cursor=conn.cursor () cursor.execute ("drop table Test_increase") Cursor.execute ("Create Table Test_increase (F1 CHAR) ") Cursor.execute (" commit "); for I in Range (0,999999): C_time=time.strftime ( Isotimeformat, Time.localtime (Time.time ())) Cursor.execute ("INSERT into dt_test_increase values ('%d ')"% (i)) CURSOR.E Xecute (' Commit ') print "%d,%s"% (i,c_time) cursor.close () conn.close () if __name = = ' __main__ ': connectoracle ()
More information: www.kootest.com; Technology Exchange Group: 182526995
Python Learning-Connecting to Oracle Database