Oracle Database Operations in Python practice

Source: Internet
Author: User
To enable Python to operate the Oracle database, you must first install the cx_Oracle package. You can obtain the installation package through the following address:

To enable Python to operate the Oracle database, you must first install the cx_Oracle package. You can obtain the installation package through the following address:

1. To enable Python to operate the Oracle database, first install the cx_Oracle package. You can obtain the installation package through the following address:

[Plain]

  • 2. You also need some class libraries of oracle. You need to install the Oracle Instant Client package on the machine running python.

    [Plain]

  • Find the package that meets your platform and install it. Here I use the rpm package, so run the following command to install

    [Plain]

  • $ Sudo rpm-ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.i386.rpm
  • After installation, you need to set the environment variables as follows:

    [Plain]

  • $ Export LD_LIBRARY_PATH =$ {LD_LIBRARY_PATH}:/usr/lib/oracle/11.2/client/lib
  • 3. Create a simple python file and test whether the installation is successful.

    [Python]

    4. The following is a database table creation and insertion Operation.

    [Python]

    5. next let's look at the query. there are usually two ways to query: one is to use cursor. fetchall () is used to obtain all query results and then iterate over one row. fetchone () gets a record until the obtained result is null. Let's take a look at the following example:

    [Python]

    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.