logo
down
shadow

How to send the data stored in python variables to oracle database table using cx_oracle?


How to send the data stored in python variables to oracle database table using cx_oracle?

By : user2185030
Date : November 20 2020, 04:01 AM
hop of those help? If you've already succeeded to connect to the database, then all you need to do is build up a list of tuples that looks something like the following:
code :
data = [
    ('NameTwentyThree', 'Wayne', '7867904678', 'nametwentythree@gmail.com'),
    ('NameTwentyTwo', 'Arigato', '6578967543', 'nametwentytwo@gmail.com'),
]

cursor.executemany("""
    insert into TheTable (FirstName, LastName, PhoneNumber, Email)
    values (:1, :2, :3, :4, :5)""", data)


Share : facebook icon twitter icon
Connecting to Oracle database using cx_Oracle on Python

Connecting to Oracle database using cx_Oracle on Python


By : user2512153
Date : March 29 2020, 07:55 AM
this will help Am using Debian 5, Python 2.5 with cx_Oracle unicode version installed. I try to connect using the below script but its failing , the solution was to place the following
code :
cx_Oracle.connect(u'hr/XXXXX@local_xe')
unable to insert data that are stored in variables in to an MYSQL database table using python

unable to insert data that are stored in variables in to an MYSQL database table using python


By : nacho gaspar
Date : March 29 2020, 07:55 AM
it helps some times You should pass the variables as an argument to .execute instead of putting them in the actual query. E.g.:
code :
cursor.execute("""insert into track_table 
                    (tid,pid,usid,address,status,phno,email,ord_date,del_date)
                  values (%s,%s,%s,%s,%s,%s,%s,%s,%s)""", 
               (tid,pid,usid,address,status,phno,email,ord_date,del_date))
cursor.execute("""insert into user_table 
                    (tid,usid) 
                  values (%s,%s)""",(tid,usid))
Can't connect with cx_Oracle of Python to oracle remote database

Can't connect with cx_Oracle of Python to oracle remote database


By : DaveLock
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I had to set the ORACLE_HOME variable in the system variables and also add the bin directory in the PATH system variable. THNX
Return Empty String in place of Oracle NULL/Python None when pulling data from Oracle using cx_Oracle

Return Empty String in place of Oracle NULL/Python None when pulling data from Oracle using cx_Oracle


By : user1725439
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You can use an output type handler and out converter to transform this way. Something like this.
code :
def OutConverter(value):
    if value is None:
        return ''
    return value

def OutputTypeHandler(cursor, name, defaultType, size, precision, scale):
    if defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR):
        return cursor.var(str, size, cursor.arraysize, outconverter=OutConverter)

connection.outputtypehandler = OutputTypeHandler
Connecting to oracle database using python(cx_oracle)

Connecting to oracle database using python(cx_oracle)


By : demon917
Date : March 29 2020, 07:55 AM
I hope this helps you . Create def for connect by Oracle. for execute procedure use cursor. Don't forget close connect and cursor. Also in case exception.
code :
import cx_Oracle
import pandas as pd

ip = 'some_ip'
port = 1521
SID = 'some_SID'
user_name = 'user_name'
password = 'password'
query = """ SELECT * from table_name """

def connect_oracle(ip, port, SID, user_name, password):
    dsn_tns = cx_Oracle.makedsn(ip, port, SID)
    connection = cx_Oracle.connect(user_name, password, dsn_tns)
    return connection

def get_df(conn, query):
    df_ora = pd.read_sql(query, con=conn)
    return df_ora


def execute_proc(conn, procname, param):    
    my_cursor=conn.cursor()
    my_cursor.callproc(procname, param)
    conn.commit()

def execute_func(conn, procname, param):    
    my_cursor=conn.cursor()
    out_parameter = my_cursor.var(cx_Oracle.NUMBER)
    qw = my_cursor.callfunc(procname, out_parameter)
    return qw

conn1 = connect_oracle(ip, port, SID, user_name, password)
df = get_df(conn1, query)
df.head()
execute_proc(conn1, "insert_temp", [])
execute_func(conn1, "get_version", [])
create or replace function get_version
return number
is
    v_version NUMBER(8) := 11;
begin
    return v_version;
end;
create table temp (clm number);
create or replace procedure insert_temp
is
    v_version NUMBER(8) := 11;
begin
    insert into temp(clm) values(v_version);
end;
select *  from temp
Related Posts Related Posts :
  • Pythonic way set variables if none in __init__
  • Python remove duplicate entries from list within a list
  • I'm trying to perform certain pattern matching using python's re module
  • Format Google Calendar Event Date
  • How to remove apostrophe's when writing to csv file in Python
  • How to graph the second derivatives of coupled non-linear second order ODEs in Python?
  • Full gradient descent in keras
  • How to manually calculate AUC of the ROC?
  • Python http.server command gives "Syntax Error"
  • How to groupby and sum if the cell value of certain columns fit specific conditions
  • Batch file not closed after being created and written to by Python?
  • Adding an extra in column into 2D numpy array python
  • Scraping content using pyppeteer in association with asyncio
  • Rearrange rows of Dataframe alternatively
  • Function not returning value due to errors in if else logic
  • Value Error in Python while calling a function
  • Is it possible to check if a function is decorated inside another function?
  • How to change "style property" in pygtk2
  • how to create new dataframe out of columns after resampling?
  • Why doesn't this Python code work? It returns no output
  • Python - Split multiple columns into multiple rows
  • Pyinstaller 3.4 Not Working on Windows 10 with Python 2.7
  • inputing numpy array images into pytorch neural net
  • Creating a Dataframe of Proportions
  • Scrapy with dynamic captcha
  • In python, how do I get urllib to recognize multiple lines in a string as separate URLs?
  • Add prefix and suffix to each element of a nested list
  • Generate string set from csv file in Python
  • Custom usage message for many-valued argument
  • Python Class, how to skip a wrong entry and proceed to next entry
  • Numpy efficient way to parse array of string
  • Kivy , Python: Update Label on_file_drop
  • What does it mean if a deeper conv layer converges first?
  • Selecting User in client.send_message() from arg list
  • python slicing multi levels list of dict using list comprehension
  • Value Error problem with multicell Dimensions must be equal, but are 20 and 13
  • How to print a board with coordinates?
  • Keras LSTM shape doesn't contain length of sequence
  • Boxplot with Pandas in Python
  • How can I rename a PySpark dataframe column by index? (handle duplicated column names)
  • How to calculate hash of a python class object
  • Using ideas from HashEmbeddings with sklearn's HashingVectorizer
  • keycloak.exceptions.KeycloakGetError: 404: b'' using Python 3.7
  • How to modify a column in a SQLite3?
  • VS Integration Services: flat file source to OLE DB destination - detect new data columns in file, add columns to table,
  • Customize xticks in matplotlib plot
  • How can I show the image in a labelframe which is inserted through askopenfilename?
  • Boxplot with distibution size histogram on top (and median regression)
  • Fit differential equation with scipy
  • ModuleNotFoundError: Correct setup
  • How to pass rendered plot to a html file through render_template?
  • Create flat ndarray from DataFrame column containing arrays
  • Bring radial axes labels in front of lines of polar plot matplotlib
  • Python3: Unable to split word from parsed data
  • Using Python to login to a website and web scrape
  • Customise shift in matplotlib offset
  • Combining and Reshaping rows and columns of 2 dataframes in R or Python
  • Regex condition after and before a known phrase
  • subplots based on records of two different pandas DataFrames ( with same structure) using Seaborn or Matplotlib
  • find numpy array in other numpy array
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org