|
| 1 | + .. Licensed to the Apache Software Foundation (ASF) under one |
| 2 | + or more contributor license agreements. See the NOTICE file |
| 3 | + distributed with this work for additional information |
| 4 | + regarding copyright ownership. The ASF licenses this file |
| 5 | + to you under the Apache License, Version 2.0 (the |
| 6 | + "License"); you may not use this file except in compliance |
| 7 | + with the License. You may obtain a copy of the License at |
| 8 | +
|
| 9 | + .. http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | + .. Unless required by applicable law or agreed to in writing, |
| 12 | + software distributed under the License is distributed on an |
| 13 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | + KIND, either express or implied. See the License for the |
| 15 | + specific language governing permissions and limitations |
| 16 | + under the License. |
| 17 | +
|
| 18 | +
|
| 19 | +.. _howto/operators:oracle: |
| 20 | + |
| 21 | +Oracle Operators |
| 22 | +================ |
| 23 | +The Oracle connection type provides connection to a Oracle database. |
| 24 | + |
| 25 | +Execute a Stored Procedure in an Oracle database |
| 26 | +------------------------------------------------ |
| 27 | + |
| 28 | +To execute a Stored Procedure in an Oracle database, use the |
| 29 | +:class:`~airflow.providers.oracle.operators.oracle.OracleStoredProcedureOperator`. |
| 30 | + |
| 31 | +Assume a stored procedure exists in the database that looks like this: |
| 32 | + |
| 33 | + .. code-block:: sql |
| 34 | +
|
| 35 | + CREATE OR REPLACE PROCEDURE |
| 36 | + TEST_PROCEDURE (val_in IN INT, val_out OUT INT) AS |
| 37 | + BEGIN |
| 38 | + val_out := val_in * 2; |
| 39 | + END; |
| 40 | + / |
| 41 | +
|
| 42 | +This stored procedure accepts a single integer argument, val_in, and outputs |
| 43 | +a single integer argument, val_out. This can be represented with the following |
| 44 | +call using :class:`~airflow.providers.oracle.operators.oracle.OracleStoredProcedureOperator` |
| 45 | +with parameters passed positionally as a list: |
| 46 | + |
| 47 | +.. exampleinclude:: /../../providers/oracle/src/airflow/providers/oracle/example_dags/example_oracle.py |
| 48 | + :language: python |
| 49 | + :start-after: [START howto_oracle_stored_procedure_operator_with_list_inout] |
| 50 | + :end-before: [END howto_oracle_stored_procedure_operator_with_list_inout] |
| 51 | + |
| 52 | + |
| 53 | +Alternatively, parameters can be passed as keyword arguments using a dictionary |
| 54 | +as well. |
| 55 | + |
| 56 | +.. exampleinclude:: /../../providers/oracle/src/airflow/providers/oracle/example_dags/example_oracle.py |
| 57 | + :language: python |
| 58 | + :start-after: [START howto_oracle_stored_procedure_operator_with_dict_inout] |
| 59 | + :end-before: [END howto_oracle_stored_procedure_operator_with_dict_inout] |
| 60 | + |
| 61 | +Both input and output will be passed to xcom provided that xcom push is requested. |
| 62 | + |
| 63 | +More on stored procedure execution can be found in `oracledb documentation |
| 64 | +<https://python-oracledb.readthedocs.io/en/latest/user_guide/plsql_execution.html#pl-sql-stored-procedures>`_. |
0 commit comments