Apache Airflow Oracle Provider

4.5.2 · active · verified Sat Apr 11

The Apache Airflow Oracle Provider enables Airflow to interact with Oracle databases. It includes hooks and operators to execute SQL commands, manage data, and transfer data between Oracle instances. As of version 4.5.2, it leverages the modern `oracledb` driver for Python 3.10+ and is actively maintained, with releases often aligned with Apache Airflow's own release cycle or independently for bug fixes and features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a simple Airflow DAG using the `OracleOperator` to create a table and insert data into an Oracle database. Before running, configure an 'Oracle' connection in the Airflow UI with `Conn Id: oracle_default` and your Oracle database credentials.

from __future__ import annotations

import pendulum

from airflow.models.dag import DAG
from airflow.providers.oracle.operators.oracle import OracleOperator

# Ensure an Airflow connection named 'oracle_default' exists with Oracle DB details.
# In the Airflow UI (Admin -> Connections -> +), create a new connection:
# - Conn Id: oracle_default
# - Conn Type: Oracle
# - Host: your_oracle_host
# - Port: 1521 (or your port)
# - Schema: your_service_name_or_sid
# - Login: your_username
# - Password: your_password

with DAG(
    dag_id="oracle_example_dag",
    start_date=pendulum.datetime(2023, 1, 1, tz="UTC"),
    catchup=False,
    schedule=None,
    tags=["oracle", "example", "database"],
) as dag:
    create_table = OracleOperator(
        task_id="create_test_table",
        oracle_conn_id="oracle_default",
        sql="""
        CREATE TABLE IF NOT EXISTS AIRFLOW_TEST_TABLE (
            ID NUMBER PRIMARY KEY,
            NAME VARCHAR2(50)
        )
        """,
        autocommit=True,
    )

    insert_data = OracleOperator(
        task_id="insert_data_into_table",
        oracle_conn_id="oracle_default",
        sql="""
        INSERT INTO AIRFLOW_TEST_TABLE (ID, NAME) VALUES (1, 'Test User')
        """,
        autocommit=True,
    )

    create_table >> insert_data

view raw JSON →