Australia/Sydney
BlogApril 1, 2022

Oracle Cloud Functions in Python Example

Fahd Mirza

Oracle Functions is a fully managed, multitenant, highly scalable, on-demand, functions-as-a-service platform. It’s built on enterprise-grade Oracle Cloud Infrastructure (OCI) and powered by the Fn Project open source engine. The serverless and elastic architecture of Oracle Functions means you have no infrastructure administration or software administration to perform. 


One common requirement is to connect to Oracle database through Oracle functions. You can use following Python code chunk to accomplish that:


def sqlconnect(user, passwd, dsn, query):

    conn = cx_Oracle.connect(user=user, password=passwd, dsn=dsn)

    cursor = conn.cursor()

    cursor.execute(query)

    return cursor.fetchall()


if __name__ == '__main__':

    host = "remoteserver"

    service_name = "test"

    conn_string = f"{host}/{service_name}"

    sqlconnect("user", "password", conn_string, "select sysdate from dual")

Share this post:
On this page

Let's Partner

If you are looking to build, deploy or scale AI solutions — whether you're just starting or facing production-scale challenges — let's chat.

Subscribe to Fahd's Newsletter

Weekly updates on AI, cloud engineering, and tech innovations