Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a sql server developer but currently I am using oracle 10g.
I don't know how to create SP in oracle.

I want to create procedure for simple "Select * from Emp" and call it from c#.

Please help me
Posted
Updated 9-Jan-11 23:06pm
v2
Comments
Dalek Dave 10-Jan-11 5:06am    
Edited for Grammar and Readability.

Which provider (to access database) are you using? Your C# code will depend on that.

Oracle.com has lots of books in there website although their search is a bit crap. You will find all the information there. Try searching for the books maybe using google and site:oracle.com
 
Share this answer
 
Comments
Dalek Dave 10-Jan-11 5:06am    
Sage advice.
Spec:

SQL
CREATE OR REPLACE PACKAGE PKG_VERIFY AS




PROCEDURE prc_Verify  (i_id  IN  tablename.id%TYPE,
o_cursor         OUT    sys_refcursor,
o_ErrorCode      OUT       VARCHAR2);


END PKG_VERIFY;



Body:

SQL
create or replace
PACKAGE BODY PKG_VERIFY IS

PROCEDURE prc_Verify
                                 (i_id          IN  tablename.id%TYPE,
                                  o_cursor         OUT    sys_refcursor,
                                  o_ErrorCode      OUT       VARCHAR2)
  IS
  BEGIN

   o_Errorcode := SQL_OK;
  OPEN o_cursor FOR
      SELECT Acc,Bcc
      FROM   tablename
      WHERE  id = i_id;

   EXCEPTION
                 WHEN NO_DATA_FOUND THEN
                    o_Errorcode := 'No Record Found';
  END;
END PKG_VERIFY;


Hope this helps!
 
Share this answer
 
v4
Comments
dan!sh 10-Jan-11 5:14am    
1. That is a package and not a stored procedure.
2. You haven't shown creating specification so just this bit won't work.
3. It takes in a table as parameter which is not at all inline with OPs requirement. He just wants to query a database table.
Anupama Roy 10-Jan-11 5:20am    
1.prc_Verify is the procedure within package PKG_VERIFY
2.This will work as it's a working code posted ,he just need to replace table with his table name & rest of parameters.
3.It's not taking a table as parameter table.id%TYPE means that the input i_id's datatype is the same as it's datatype is set for id column in table .it's most appropriate way of writing in 10G
Anupama Roy 10-Jan-11 5:24am    
i have updated table with tablename.It was a typo!
dan!sh 10-Jan-11 5:31am    
We can have procedure without packages as well. Are you sure there is no "specification" created for this package? AFAIK every package needs it.

I misread your code, yes it is id column's type. My fault. And yes again, it is a good way of specifying types in packages/procedures.
Anupama Roy 10-Jan-11 5:45am    
I agree to your point that we can have procedures without packages.It's just an example ,one way of doing this. Spec & Body is a must to make a stored procedure complete.I just dint add it.We cannot post every bit of code snippet here.Forums are to help ppl to begin with & they have to take efforts to complete the requirement :)Thanks for ponting out.Adding spec too!
Check the below article

Calling Oracle stored procedures from Microsoft.NET

Accept the answer if find useful :)
 
Share this answer
 
If you need to know how to call the actual SP, check this out:

SqlConnection lSQLConn = null;
SqlCommand lSQLCmd = new SqlCommand();
//Declare a DataAdapter and a DataSet
SqlDataAdapter lDA = new SqlDataAdapter();
DataSet lDS = new DataSet();
 
//...Execution section
 
// create and open a connection object
lSQLConn = new SqlConnection(connStr);
lSQLConn.Open();
//The CommandType must be StoredProcedure if we are using an ExecuteScalar
lSQLCmd.CommandType = CommandType.StoredProcedure;
lSQLCmd.CommandText = "sp_YourSPName"; 
lSQLCmd.Parameters.Add(new SqlParameter("@Parm1", aParm1));
lSQLCmd.Parameters.Add(new SqlParameter("@Parm2", aParm2));
lSQLCmd.Parameters.Add(new SqlParameter("@Parm3", aParm3));
lSQLCmd.Parameters.Add(new SqlParameter("@Parm4", aParm4));
 
lSQLCmd.Connection = lSQLConn;
//Fill the DataAdapter with a SelectCommand
lDA.SelectCommand = lSQLCmd;
lDA.Fill(lDS);


More Info:
Executing a Stored Procedure from a WCF Service Method C#
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900