# Oracle Procedure Task

This task involves calling a procedure stored in an Oracle database. Depending on individual data types, it either returns a list of data or a specific data type's value.

## Parameters

### Procedure Code

- The procedure code is automatically generated based on the _procedure name_ and _parameters_, and there's no need for users to input it.
- For example, if the procedure's name is _mcs.myproc_ with parameters _id_ and _out_name_, it would be expressed as follows:

```text
mcs.myproc(:id, :out_name);
```

### Procedure Name

- Specifies the name of the procedure.
- If the procedure needs to be distinguished by package or user names, use a period (.) to separate them.
- Example:

```text
mcs.myproc
```

### Parameters

- Parameters consist of the following elements:
  - Parameter Name
  - Direction: IN, INOUT, OUT
  - Data Type: String, Number, Date, Cursor
  - Value: For input variables, the corresponding value
  - Max Size: For String or Buffer data types, the maximum size of the variable.

#### Parameter Name

The parameter name specifies the name of the parameter used in the procedure. In the example above, 'id' and 'out_name' are parameter names.

### Direction

Specifies whether the variable is an input (IN) or output (OUT) variable.

### Data Type

Specifies the data type of the parameter. The data type should be specified exactly as it is named when creating the procedure.

For instance, if a procedure is implemented as follows:

```sql
CREATE OR REPLACE NONEDITIONABLE PROCEDURE myproc (in_id IN VARCHAR2, out_name OUT VARCHAR2) AS
BEGIN
    SELECT name INTO out_name FROM MCS.FMB_USERS WHERE id = in_id ;
END;
```

Both the first and second parameters are of type VARCHAR2.

When calling such a procedure, you should specify the parameter type as String and, for output, also specify the maximum size.

Here's an example of how to specify it:

![procedure example1](./assets/../../../../assets/images/oracle-procedure-example1.png 'procedure example1')

### Accessor

The configuration follows the [JSONATA documentation](http://docs.jsonata.org/overview.html).

When the 'accessor' is specified, the value composed by that accessor is used as the parameter value. If no result is generated by the 'accessor' operation, the value set in 'Value (val)' is used.

### Value (val)

If the parameter is an input (IN), this field specifies the value. Enter a "constant" value directly for this field.

In the example mentioned earlier, if 'ID' is specified as the input value for the 'id' parameter, you should use the value returned by the ID task as the input value.

This value is used if there is no result from the 'accessor' setting.

### Max Size

For parameters with String or Buffer data types, specify the maximum size. Ignore this for other data types.

## Task Result

The result of calling the procedure is returned in Object format, with the parameter names specified for output becoming keys and their corresponding values returned.

For example, in the task mentioned above, the result value would be:

```javascript
{
  out_name: 'Admin'
}
```

## Another Example (Cursor)

### Procedure Implementation Example

```sql
CREATE OR REPLACE NONEDITIONABLE PROCEDURE PROCEDURE1(out_cursor OUT SYS_REFCURSOR) AS
BEGIN
    BEGIN
        OPEN out_cursor FOR
            SELECT * FROM FARMWEATHER WHERE rownum <= 1000;
    END;
END PROCEDURE1;
```

### Procedure Invocation Example

![procedure example2](./assets/../../../../assets/images/oracle-procedure-example2.png 'procedure example2')

### Task Result for Procedure Invocation

```javascript
{
  "out_cursor": [
    {
      "FARMDATE": "2006-01-07T15:00:00.000Z",
      "MAXT": 29.5,
      "MINT": 21.8,
      "WINDSPEED": 1.6,
      "FARMHUM": 70.2,
      "PRECIPITATION": 0
    },
    {
      "FARMDATE": "2006-01-08T15:00:00.000Z",
      "MAXT": 30.1,
      "MINT": 21,
      "WINDSPEED": 1.6,
      "FARMHUM": 67.4,
      "PRECIPITATION": 0
    },
    ..
  ]
}
```
