This article mainly introduces Python's operational learning of Oracle Database

Source: Internet
Author: User

includes: Oracle Database in Windows installation and configuration under the operating system, python The third-party expansion packs that need to be installed, as well as sample learning for basic operations.

    1. Oracle Database
      1. Oracle Environment Configuration & Client Connectivity
      2. Download Installation Oracle Green Edition Client instantclient :

to the Oracle Download website instantclient Basic package, unzip to E:\ProgramFile\instantclient ;

    1. Set Environment variables:
    • nls_lang=simplified Chinese_china. ZHS16GBK(note that there are spaces in the middle, this if not set,toad query Chinese will be garbled)
    • tns_admin= E:\ProgramFile\instantclient
    • Path= ...; E:\ProgramFile\instantclient
    1. Configuration Tnsnames.tns File:

in the E:\ProgramFile\instantclient file creation under Tnsnames.ora , paste the following into the file:

*** =

(DESCRIPTION =

(Address_list =

(ADDRESS = (PROTOCOL = TCP) (host= * * * *) (PORT = 1521))

)

(Connect_data =

(SERVER = dedicated)

(service_name = * *)

)

)

Note: The red part of the figure changes according to your needs.

    1. Configuration PL/SQL Developer to connect:

in tools/preference oracle-connection option configuration oracle home and oci library :

    • Oracle Home : E:\ProgramFile\instantclient
    • OCI Library : E:\ProgramFile\instantclient\oci.dll

configuration complete, can be restarted Plsql Developer , enter the correct username and password to connect ~~~

    1. pyth On connection oracle database
    2. install cx_oracle package:

http://cx-oracle.sourceforge.net/ Need to be aware of the next version, choose according to the operating system and the version of python installed

Choose your own version and execute it directly after download

    1. Post-Installation verification:

Import cx_oracle No error:

Note: if import cx_oracle times error prompt cannot find oci. DLL , Workaround: To install oracle Find one on the machine, and then copy to libsite-packages The directory can be.

    1. Python Connection Oracle Basic operations of the database
    2. Create a database connection Connect and close the database connection Close

There are three ways to create a database connection:

Method One: User name, password and listen separate write

Import Cx_oracle

Db=cx_oracle.connect (' Username/[email protected]/orcl ')

Db.close ()

Method Two: User name, password and monitoring are written together

Import Cx_oracle

Db=cx_oracle.connect (' username ', ' password ', ' HOST/ORCL ')

Db.close ()

Method Three: Configure the Listener and connect

Import Cx_oracle

TNS=CX_ORACLE.MAKEDSN (' Host ', 1521, ' ORCL ')

Db=cx_oracle.connect (' username ', ' password ', TNS)

Db.close ()

    1. build cursor sql statement: query, UPDATE, INSERT, delete
    2. Create a database connection, create a cursor cursor sql statement, when execution is complete, close the cursor and close the database connection

After creating the connection, establish cursor , and perform SQL Statement

    1. submit after insert, UPDATE, delete operation Commit

This article mainly introduces Python's operational learning of Oracle Database

Related Article

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.