Skip to content

Instantly share code, notes, and snippets.

@cjbj
Last active August 18, 2025 23:55
Show Gist options
  • Select an option

  • Save cjbj/1c80e5b008ec6798c02ba0505cedfce5 to your computer and use it in GitHub Desktop.

Select an option

Save cjbj/1c80e5b008ec6798c02ba0505cedfce5 to your computer and use it in GitHub Desktop.
Inserting a DataFrame using python-oracledb from the video "Python DataFrames with Oracle Database for Analysis and AI" https://youtu.be/0BJNlbh71LY For other examples, see https://github.com/oracle/python-oracledb/tree/main/samples
# insert.py
#
# For other python-oracledb DataFrame examples, see https://github.com/oracle/python-oracledb/tree/main/samples
import os
import pandas
import oracledb
un = os.environ.get('ORACLE_USERNAME')
pw = os.environ.get('ORACLE_PASSWORD')
cs = os.environ.get('ORACLE_DSN')
connection = oracledb.connect(user=un, password=pw, dsn=cs)
cursor = connection.cursor()
#-------------------------------------------------------------------------------
cursor.execute("drop table if exists mytab")
cursor.execute("create table mytab (k number, v varchar2(20))")
#-------------------------------------------------------------------------------
d = {'k': [10, 20, 30],
'v': ["koala", "wombat", "kangaroo"]}
df = pandas.DataFrame(data=d)
cursor.executemany("insert into mytab (k, v) values (:1, :2)", df)
#-------------------------------------------------------------------------------
print()
for r in cursor.execute("select * from mytab"):
print(r)
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment