This article describes how to work with Oracle Package using dotConnect for Oracle.
Oracle databases allow creating packages, which are unified sets of stored procedures, functions, variables and user-defined types. dotConnect for Oracle leverages working with Oracle packages by implementing typed OraclePackage components. These components allow you to work with a package like with a usual .NET object, invoking stored procedures as object methods. This tutorial describes how to create and use typed OraclePackages.
This walkthrough supposes that you know how to establish a connection to server and how to create the database objects.
To follow the tutorial, you also need the package Pack created in your Oracle database. This can be made by executing the following script:
CREATE OR REPLACE PACKAGE Pack AS PROCEDURE get_all_depts (cur OUT SYS_REFCURSOR); PROCEDURE insert_dept (pDeptno INTEGER, pDname VARCHAR, pLoc VARCHAR); FUNCTION dept_count RETURN INTEGER; END PACK; / CREATE OR REPLACE PACKAGE BODY Pack IS PROCEDURE get_all_depts (cur OUT SYS_REFCURSOR) AS BEGIN OPEN cur FOR SELECT * FROM dept; END; PROCEDURE insert_dept (pDeptno INTEGER, pDname VARCHAR, pLoc VARCHAR) AS BEGIN INSERT INTO dept(deptno, dname, loc) VALUES (pDeptno, pDname, pLoc); END; FUNCTION dept_count RETURN INTEGER AS cnt INTEGER; BEGIN SELECT COUNT(*) INTO cnt FROM dept; RETURN cnt; END; END PACK; /
Typed OraclePackage can be created via Typed Oracle Package Wizard. The wizard can be started either from the Visual Studio main menu (Tools -> Oracle -> Oracle Package Wizard) or from the toolbox (double-click the OraclePackage component or drop it to the form). In the latter case, select the New typed package option in the dialog window and click OK:
After the wizard started, follow these steps:
Set the connection properties to the server where you created a package and click Next to proceed.
Note that the wizard may operate with both Direct and OCI connections.
In this page, you can select whether to show all packages in the database or only those belonging to the specific user. For this purpose, use the radio buttons All and User, and the list box for selecting the user.
Select the package you want to work with. In this sample, the Pack package is used. Click Next to continue.
The wizard will generate the Pack class representing the Pack Oracle package and, if you have selected the last check box, will place Pack instance pack1 onto the form. The package class needs an open connection, so if you have created a new connection while running the wizard, OracleConnection instance oracleConnection1 will be placed onto the form too.
The procedures of the Pack package will be available in pack1 just like usual object's methods. In the next sample, we invoke all methods of the Pack package, which are doing the following: