How to Call A Stored Procedure In Oracle Pl/Sql?

9 minutes read

To call a stored procedure in Oracle PL/SQL, you need to use the EXECUTE or CALL statement followed by the name of the procedure and any required parameters enclosed in parentheses. For example, if you have a stored procedure called my_procedure that takes two parameters param1 and param2, you would call it like this:

1
EXECUTE my_procedure(param1, param2);


Alternatively, you can use the CALL statement like this:

1
CALL my_procedure(param1, param2);


Make sure to replace my_procedure, param1, and param2 with the actual names of your stored procedure and parameters. Also, be aware of any input/output parameters that the stored procedure may have and handle them accordingly in your calling statement.

Best Oracle Database Books in October 2024

1
Oracle PL/SQL by Example (The Oracle Press Database and Data Science)

Rating is 5 out of 5

Oracle PL/SQL by Example (The Oracle Press Database and Data Science)

2
Expert Oracle Database Architecture: Techniques and Solutions for High Performance and Productivity

Rating is 4.9 out of 5

Expert Oracle Database Architecture: Techniques and Solutions for High Performance and Productivity

3
OCA Oracle Database SQL Exam Guide (Exam 1Z0-071)

Rating is 4.8 out of 5

OCA Oracle Database SQL Exam Guide (Exam 1Z0-071)

4
Pro Oracle Database 23ai Administration: Manage and Safeguard Your Organization’s Data

Rating is 4.7 out of 5

Pro Oracle Database 23ai Administration: Manage and Safeguard Your Organization’s Data

5
Oracle Essentials: Oracle Database 12c

Rating is 4.6 out of 5

Oracle Essentials: Oracle Database 12c

6
Oracle PL/SQL Programming: Covers Versions Through Oracle Database 12c

Rating is 4.5 out of 5

Oracle PL/SQL Programming: Covers Versions Through Oracle Database 12c

7
Pro Oracle Database 23c Administration: Manage and Safeguard Your Organization’s Data

Rating is 4.4 out of 5

Pro Oracle Database 23c Administration: Manage and Safeguard Your Organization’s Data

8
Oracle Database Administration: The Essential Refe: A Quick Reference for the Oracle DBA

Rating is 4.3 out of 5

Oracle Database Administration: The Essential Refe: A Quick Reference for the Oracle DBA

9
Modern Oracle Database Programming: Level Up Your Skill Set to Oracle's Latest and Most Powerful Features in SQL, PL/SQL, and JSON

Rating is 4.2 out of 5

Modern Oracle Database Programming: Level Up Your Skill Set to Oracle's Latest and Most Powerful Features in SQL, PL/SQL, and JSON


How to call a stored procedure with IN OUT parameters in Oracle PL/SQL?

To call a stored procedure with IN OUT parameters in Oracle PL/SQL, you can follow these steps:

  1. Define the stored procedure with IN OUT parameters in your PL/SQL package or standalone procedure. For example:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
CREATE OR REPLACE PROCEDURE update_employee_salary(
    emp_id IN NUMBER,
    new_salary IN OUT NUMBER
) AS
BEGIN
    -- Update the employee's salary
    UPDATE employees
    SET salary = new_salary
    WHERE employee_id = emp_id;
END;


  1. Call the stored procedure in your PL/SQL block and pass the values for the IN OUT parameters. For example:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
DECLARE
    v_employee_id NUMBER := 100;
    v_new_salary NUMBER := 50000;
BEGIN
    DBMS_OUTPUT.PUT_LINE('Employee ' || v_employee_id || ' current salary: ' || v_new_salary);

    update_employee_salary(v_employee_id, v_new_salary);

    DBMS_OUTPUT.PUT_LINE('Employee ' || v_employee_id || ' new salary: ' || v_new_salary);
END;


In this example, the update_employee_salary procedure takes an employee ID and a new salary as input (IN) parameters, and updates the employee's salary. The new salary value is passed back to the caller as an output (OUT) parameter.


When you call the procedure in your PL/SQL block, you can see the old and new salary values being displayed using DBMS_OUTPUT.PUT_LINE statements.


How to call a stored procedure with a return value in Oracle PL/SQL?

To call a stored procedure with a return value in Oracle PL/SQL, you can use the following syntax:


DECLARE result_value VARCHAR2(50); BEGIN result_value := procedure_name(parameter1, parameter2, ...); END;


In this syntax:

  • Replace 'procedure_name' with the name of the stored procedure you want to call.
  • Replace 'parameter1', 'parameter2', etc. with the input parameters required by the stored procedure.
  • Replace 'VARCHAR2(50)' with the data type and size of the return value expected from the stored procedure.


After calling the stored procedure, you can use the 'result_value' variable to access and manipulate the return value returned by the stored procedure.


How to call a stored procedure in Oracle PL/SQL using EXECUTE?

To call a stored procedure in Oracle PL/SQL using the EXECUTE statement, use the following syntax:

1
EXECUTE procedure_name(parameter1, parameter2, ...);


Here's an example of calling a stored procedure named my_procedure with two input parameters param1 and param2:

1
EXECUTE my_procedure('value1', 'value2');


Make sure to replace my_procedure, param1, param2, and 'value1', 'value2' with the actual names of your stored procedure and parameters, as well as the values you want to pass as input to the procedure.


How to call a stored procedure that returns a result set in Oracle PL/SQL?

You can call a stored procedure that returns a result set in Oracle PL/SQL by using a cursor. Here is an example of how you can do this:

  1. Define a cursor variable to hold the result set:
1
2
3
DECLARE
    CURSOR cur_result IS
    SELECT * FROM your_stored_procedure();


  1. Open the cursor and fetch the results:
1
2
3
4
5
6
7
8
9
BEGIN
    OPEN cur_result;
    LOOP
        FETCH cur_result INTO your_variables;
        EXIT WHEN cur_result%NOTFOUND;
        -- do something with the fetched values
    END LOOP;
    CLOSE cur_result;
END;


Replace your_stored_procedure() with the name of your stored procedure that returns a result set, and your_variables with the variables where you want to store the fetched values.


This is a basic example of how to call a stored procedure that returns a result set in Oracle PL/SQL using a cursor. You may need to adjust the code as per your specific requirements and the structure of your stored procedure.

Twitter LinkedIn Telegram Whatsapp

Related Posts:

To write and execute SQL queries in Delphi, you need to follow a few steps. First, establish a database connection using the appropriate components in Delphi, such as ADOConnection or FDConnection. Then, create a SQL query object, such as TADOQuery or TFDQuery...
To rename a sequence in Oracle, you can use the RENAME TO statement. Start by connecting to your Oracle database using a tool like SQL*Plus or SQL Developer. Then, use the following SQL syntax to rename a sequence: ALTER SEQUENCE old_sequence_name RENAME TO ne...
To call a function from an iframe, first make sure the function you want to call is accessible from the parent window. To do this, you can define the function in the parent window and then access it from within the iframe using the window.parent property. For ...