Friday, April 1, 2022

Oracle Cloud Functions in Python Example

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")

No comments: