> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# DB-2-API: Calling Stored Procedures

> Enables calling stored procedures on DB-2-API in the Apinizer Platform. You can publish Oracle database stored procedures as REST API endpoints and work with IN and OUT parameters.

## Calling Procedures in Oracle Database with Apinizer DB to API Designer

> **Important**
>
> Apinizer does **not support OracleTypes.CURSOR**. It can only serve simple procedure calls as services.

## 1. Creating DB-2-API

A new API is defined via **Management → Development → API Creator** → **DB-2-API**.

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/01-db2api-creation.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=dd23eb4678f746a1ee688ecf7d55c4c9" alt="DB-2-API Creation" width="200" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/01-db2api-creation.png" />

Fill in the DB-2-API name and description fields, then click the **Save and Next** button.

**The image below shows DB-2-API settings:**

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/02-db2api-settings.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=ef488ccd8973ad5a14bff1674a767283" alt="DB-2-API Settings" width="800" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/02-db2api-settings.png" />

## 2. Creating Methods

Click the **Add** button to open the method/endpoint creation panel.

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/03-add-endpoint.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=64142b60ceb62efb376abf9b318d58de" alt="Adding Endpoint" width="600" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/03-add-endpoint.png" />

### 2.1 Calling Procedures with Only IN Parameters

The Oracle database procedure used as a demo is shown in the example below:

```sql theme={null}
create or replace PROCEDURE sampleProcedureWithInParams (
  pId IN NUMBER, 
  pName IN VARCHAR2, 
  pDesc IN VARCHAR2, 
  pCost IN NUMBER, 
  pPrice IN NUMBER, 
  pCat IN NUMBER
) IS 
begin 
  INSERT INTO "TEST"."PRODUCTS" (
    PRODUCT_ID, 
    PRODUCT_NAME, 
    DESCRIPTION, 
    STANDARD_COST, 
    LIST_PRICE, 
    CATEGORY_ID
  ) VALUES (pId, pName, pDesc, pCost, pPrice, pCat); 
  commit; 
end;
```

**The image below shows method creation settings:**

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/04-method-creation-in-params.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=956b22c497e9abd8d082b012f9d579f4" alt="Method Creation - IN Parameters" width="800" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/04-method-creation-in-params.png" />

### 2.2 Calling Procedures with IN and OUT Parameters

#### A. The Oracle database procedure used as a demo is shown below:

```sql theme={null}
create or replace PROCEDURE sampleProcedureWithInOutParams (
  pId IN NUMBER, 
  pName OUT VARCHAR2
) IS 
begin 
  select PRODUCT_NAME into pName 
  from PRODUCTS 
  where PRODUCT_ID = pId; 
  commit; 
end;
```

**The image below shows method creation settings:**

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/05-method-creation-in-out-params.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=4dbc49579bb0ba0d0fee9cf16abc95a8" alt="Method Creation - IN/OUT Parameters" width="800" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/05-method-creation-in-out-params.png" />

#### B. The Oracle database procedure used as a demo is shown below:

```sql theme={null}
create or replace PROCEDURE sampleProcedureWithInOutCursorParams (
  cat_id IN NUMBER, 
  total_cost OUT NUMBER, 
  cursoroutparam OUT SYS_REFCURSOR
) IS 
begin 
  SELECT sum (standard_cost) INTO total_cost 
  FROM PRODUCTS 
  where category_id = cat_id; 
  
  OPEN cursoroutparam FOR 
    SELECT * FROM PRODUCTS 
    where category_id = cat_id; 
end;
```

**The image below shows method creation settings:**

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/06-method-creation-in-out-cursor-params.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=1c11abb39f68540da0484d6cecbd6b16" alt="Method Creation - IN/OUT Cursor Parameters" width="800" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/06-method-creation-in-out-cursor-params.png" />

## 3. Viewing API Definition Documents

Click the **Show Sample Message Body** link to view the message content.

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/07-show-sample-message-body.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=210bc4e5b273c2aee6fd6e81f076b259" alt="Show Sample Message Body" width="400" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/07-show-sample-message-body.png" />

## 4. Creating API Proxy

You can instantly create an API Proxy by clicking the **Create API Proxy** button from the DB-2-API screen.

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/08-create-api-proxy.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=f988f8a3c3815ee1ece9c88c2ba2a1b4" alt="Create API Proxy" width="800" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/08-create-api-proxy.png" />

When creating the API Proxy, fill in the fields shown in the image below and click the **Save** button.

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/09-api-proxy-creation-form.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=40194edc7305ff5092c146dc5adeb964" alt="API Proxy Creation Form" width="800" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/09-api-proxy-creation-form.png" />

### 4.1 Deploying the API Proxy

The API Proxy can be quickly deployed to a defined environment and made available for client consumption.

This operation can be managed through the dialog opened by the **Deploy** button on the API Proxy screen.

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/10-deploy-dialog.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=70336ba3b2443e35d6d56b63d1188773" alt="Deploy Dialog" width="800" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/10-deploy-dialog.png" />

## 5. Testing

### 5.1 Testing the IN Procedure

When the parameters expected by the relevant method are added to the request and executed, the following successful response is returned.

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/11-test-result-in-proc.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=06f2cd0b6c9bd0294fe122d6cbac4623" alt="IN Procedure Test Result" width="800" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/11-test-result-in-proc.png" />

### 5.2 Testing the OUT Cursor Procedure

When the parameters expected by the relevant method are added to the request and executed, the following successful response is returned.

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/12-test-result-out-cursor-proc.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=8ec70d752dabda025331d966fce4f231" alt="OUT Cursor Procedure Test Result" width="800" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/12-test-result-out-cursor-proc.png" />

### 5.3 Testing the OUT Procedure

When the parameters expected by the relevant method are added to the request and executed, the following successful response is returned.

<img src="https://mintcdn.com/apinizer/EhzN-eazjyqTurxc/images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/13-test-result-out-proc.png?fit=max&auto=format&n=EhzN-eazjyqTurxc&q=85&s=6f52258813aa1d3e49c516dc853116d1" alt="OUT Procedure Test Result" width="800" data-path="images/tutorials/api-olusturucu-senaryolari/db2api-stored-procedure/13-test-result-out-proc.png" />
