Python programming | Executing SQL queries with Bind Variables from python script

preview_player
Показать описание
This is the eighth 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 use bind variables in the query statement. The table has been created in the second video of the tutorial series.

While executing the query if you need to set some parameters at run time, then bind variables are of the perfect use.

Steps performed:
================
Create Connection
Create Cursor
Prepare select statement with bind variables
Execute select statement with execute() and provide the value at this time
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
=================================================================

Tools used in creating and executing the scripts:
==================================================
VSCode - Visual Studio Code
SQL Developer

Links used while creating the content:
=======================================

Content and video created by - Kishan Mashru
Рекомендации по теме
Комментарии
Автор

I just wanted to fetch the data/input from the user in Python and store it to oracle. You solved it for me... thank you

nagadeepthimr
Автор

Thanks for the video. Can you provide an example on how to use bind variable with the IN statement and a python list?

jmejias
Автор

how can i do this when my sql to execute is in a variable itself?

errolthomas
Автор

I am facing error when I use execute it show error

kamleshkumar-tgsw
Автор

Thanks for this video. It helped. I am facing one issue, i am trying to run using pd but getting error whereas when i run same cursor.execute(sql) it is working fine.
what i am doing something like this

import pandas as pd
query = " " " select * from table where some_id = :id " " "
df = pd.read_sql_query(query, conn, {'id' : 123})

PankajKumar-uthh
Автор

How can I do to get :age from templates and send to this query? Someone can help me?

ulissesavelar
join shbcf.ru