Calling Procedures and Functions

SQL*XL
home

This page describes how to call PL/SQL procedures and functions in Excel using SQL*XL. PL/SQL can be executed from the SQL dialog. In the examples below, the SQL is executed from the SQL dialog.

Simple procedure and function examples:
Calling a procedure with only input parameters
Calling a procedure with input and output parameters
Calling a function

Source code for the package used in the examples above

Procedure calls returning a REF CURSOR:
Call to a procedure returning a ref cursor
Calling a procedure with input parameters, returning a ref cursor

Source code for the package used in the examples above

 

Package used for the simpel procedure and function call examples: (top )

CREATE OR REPLACE PACKAGE ProcTest
AS
   PROCEDURE ProcInput (Text IN VARCHAR);
   PROCEDURE ProcMultiply (Number1 IN NUMBER, Number2 IN NUMBER, Result OUT NUMBER);
   FUNCTION FuncMultiply (Number1 IN NUMBER, Number2 IN NUMBER) Return NUMBER;
END ProcTest;
/

CREATE OR REPLACE PACKAGE BODY ProcTest
AS
   PROCEDURE ProcInput (Text IN VARCHAR)
   AS
   BEGIN
      Insert into TempText (DebugText) values (Text);
      COMMIT; 
   END; 

   PROCEDURE ProcMultiply (Number1 IN NUMBER, Number2 IN NUMBER, Result OUT NUMBER) 
   AS
   BEGIN
      Result := Number1 * Number2;
   END;

   FUNCTION FuncMultiply (Number1 IN NUMBER, Number2 IN NUMBER) Return NUMBER
   AS
   BEGIN
      RETURN Number1 * Number2;
   END;
END ProcTest;
/

Package used for the ref cursor procedure call examples: (top )

CREATE OR REPLACE PACKAGE EmpPack
AS
   TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;

   PROCEDURE GetEmpData (emp_cv OUT EmpCurTyp);
   PROCEDURE GetEmp (employee IN number, emp_cv OUT EmpCurTyp);
END EmpPack;
/

CREATE OR REPLACE PACKAGE BODY EmpPack
AS
   PROCEDURE GetEmpData (emp_cv OUT EmpCurTyp)
   AS
   BEGIN
      OPEN emp_cv FOR select * from emp;
   END;

   PROCEDURE GetEmp (employee IN number, emp_cv OUT EmpCurTyp)
   AS 
   BEGIN
      OPEN emp_cv FOR select * from emp where empno = Employee;
   END;
END EmpPack;
/


See also: