This is the seventh video of Database programming with Python video tutorial series. In this video, we will see how to connect to the Oracle database using the cx_oracle package and fetch the desired number of records or data at a time from the table using the fetchmany method. The table has been created in the second video of the tutorial series.
fetchmany(n) will return the first n number of the record that will be available with the cursor, basically, all the data that the select statement would have fetched will be stored with the cursor, and you can use the fetchmany method to get just the first n number of records from the cursor.
fetchmany method returns a list of tuples, each row will be available as a tuple, upon execution.
fetchmany(10) will return the first 10 rows available in the cursor, if less than 10 rows are available then it will return all the available records
Steps performed:
================
Create Connection
Create Cursor
Prepare select statement
Execute select statement with execute()
Fetch n record using the fetchmany()
close the cursor
close the connection
The cx_Oracle is a Python extension module that enables access to Oracle Database. It conforms to the Python database API 2.0 specification with a considerable number of additions and a couple of exclusions.
cx_Oracle 7 has been tested with Python version 2.7, and with versions 3.5 through 3.8. You can use cx_Oracle with Oracle 11.2, 12, 18 and 19 client libraries. Oracle's standard client-server version interoperability allows connection to both older and newer databases. For example, Oracle 19c client libraries can connect to Oracle Database 11.2.
Links to all videos related to Database programming with Python
=================================================================
1. Install cx_Oracle : • Python | How to Install python packages
2. Create connection and create table : • Python Programming | Connect to an Or...
3. Insert record into the table with execute() : • Python programming | Insert data into...
4. Insert multiple records into the table with executemany() : • Python programming | How to insert mu...
5. Retrive all the data from the table using the fetchall() : • Python programming | Select or get da...
6. Retrive one record from the table using the fetchone() : • Python programming | Select or get da...
7. Retrive specific number of records from the table using the fetchmany() : • How to read data from table in python...
8. Use Bind Variables in the select statement to avoid complicating the query with concatenation operation : • Python programming | Executing SQL qu...
9. use callproc method to execute oracle procedure with parameters : • Python programming | How to execute O...
10. use callfunc method to execute oracle function with parameters : • How to execute Oracle Function from P...
Tools used in creating and executing the scripts:
==================================================
VSCode - Visual Studio Code
SQL Developer
Links used while creating the content:
=======================================
https://en.wikipedia.org/wiki/Pip_(pa...)
https://oracle.github.io/python-cx_Or...
https://github.com/oracle/python-cx_O...
Content and video created by - Kishan Mashru