Link to home
Start Free TrialLog in
Avatar of Cosine_Consultants
Cosine_Consultants

asked on

Connect to Oracle and Run a PL/SQL (Procedure or function)

Hi,

I want to connect to oracle using a vb.net and then execute a PL/SQL procedure or function that returns a cursor (select * from employees).

Thanks
SOLUTION
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The above code requires that you provide your connection string...
Avatar of Bob Learned
If you have VB.NET 2003, then you can use the OracleClient also, or you can use the the .NET provider from Oracle, like we do.

Bob
Avatar of doobdave
doobdave

Just to add to what Chaosian and TheLearnedOne have said:

I was recently delving into Oracle (having worked with SQL Server for a few years) and found that you do indeed have to return a cursor in your stored procedure, in order to get back a RESULT SET.
If you already have the stored procs set up in Oracle, then the code provided by Chaosian should work.

HTH,
David
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cosine_Consultants

ASKER

I have used Chaosian Code and it works. But how can I run my stored Procedure to return a cursor. I tried both Chaosian and TheLearnedOne code to run my stored procedure but it does not work.
 
That's the whole "problem" in this case. Microsoft went with a model intended to optimize datasets for disconnected use (i.e. web app use). When they made that decision, they implemented a model that only allows you to grab the data and operate on it locally. If you want to treat the dataset as if it is attached directly to the database, you need to use the DataAdapter's Update method to update the database after you make changes.

BTW: you can make all your changes locally, then batch update the database using the update method -- this method examines the rowstate for each row in the specified table and performs the appropraite operation on altered rows. Unaltered rows are ignored.

Hope this helps -- or have I missed the point?
Does your Stored Procedure look something like this?

  PROCEDURE get_layouts
       (layout_id_in   IN    org_chart_layouts.layout_id%TYPE,
        results        OUT   orgchart_pkg.result_type)
                         
   IS
                         
   BEGIN
   
      OPEN results FOR
           SELECT * ....

   Where results is returned, using the OPEN FOR.

Bob