Skip to content

Learn about our organization's purpose, values, and history that define who we are and how we make a difference.

Who we are

why-we-are

Discover how the Mastech InfoTrellis ecosystem is enabling customers to make well-informed decisions faster than ever and how we stand apart in the industry.

Delve into our wealth of insights, research, and expertise across various resources, and uncover our unique perspectives.

Thrive in a supportive and inclusive work environment, explore diverse career options, grow your skills, and be a part of our mission to excellence.

Table of Content

Oracle Machine Learning

Introduction

Oracle Machine Learning Notebooks are very powerful and allow you to leverage the capabilities of Python combined with the ease of accessing data directly from Oracle Autonomous Database. Oracle provides the oml library which can be used to access and manipulate data. However, there is not a way to update a persistent database table using the oml library. This is by design as OML4Py considerers the table static.

Oracle Machine Learning Notebooks and Database Updates

Fortunately, the underlying cx_Oracle driver does allow for updating persistent database tables. The cx_Oracle driver can be seen in the below code updating a persistent database table:

import cx_Oracle

connection = cx_Oracle.connect(user=ORACLE_ADW_USER, password=ORACLE_ADW_PASSWORD, dsn=ORACLE_ADW_DSN)

cr = connection.cursor()

update_sql = "UPDATE MYSCHEMA.MY_STATUS SET LAST_UPDATED=CURRENT_TIMESTAMP, STATUS='complete', MESSAGE='complete' WHERE STATUS_ID = 123"

_ = cr.execute(update_sql)

cr.close()

It should be noted that when oml.sync is introduced into the code, the table will not be updated:

import cx_Oracle
import oml

oml.connect()

connection = cx_Oracle.connect(user=ORACLE_ADW_USER, password=ORACLE_ADW_PASSWORD, dsn=ORACLE_ADW_DSN)

cr = connection.cursor()

my_oml_df = oml.sync(view='TRANSACTIONS')

update_sql = "UPDATE MYSCHEMA.MY_STATUS SET LAST_UPDATED=CURRENT_TIMESTAMP, STATUS='complete', MESSAGE='complete' WHERE STATUS_ID = 123"

_ = cr.execute(update_sql)

cr.close()

Committing Changes

The above code will not throw an exception; however, the update to the persistent table will not occur.

The commit method from the cx_Oracle library can be used to circumvent this issue and ensure the update to the persistent database table is executed:

import cx_Oracle
import oml

oml.connect()

connection = cx_Oracle.connect(user=ORACLE_ADW_USER, password=ORACLE_ADW_PASSWORD, dsn=ORACLE_ADW_DSN)

cr = connection.cursor()

update_sql = "UPDATE MYSCHEMA.MY_STATUS SET LAST_UPDATED=CURRENT_TIMESTAMP, STATUS='complete', MESSAGE='complete' WHERE STATUS_ID = 123"

_ = cr.execute(update_sql)

my_oml_df = oml.sync(view='TRANSACTIONS')

connection.commit() # commit is required if oml.sync is being used

cr.close()
avatar

Brian Houlihan

Enterprise Consulting Architect

With more than 25 years of extensive experience, Brian Houlihan is a seasoned enterprise architect renowned for his expertise in integrations and the implementation of diverse Cloud platforms. His relentless pursuit of knowledge is evidenced by his recent immersion in artificial intelligence and machine learning.