Trying to call a stored procedure from C# (and failing)
Hi;
Two questions on this. The first is - is there a way to call a stored procedure, including passing paramaters, where the entire request is in a single string? I ask because our app lets users enter any select and so if we have to break out the parameters, then we will have to parse their select string and I worry that we will miss some of the select syntax and not always parse the select correctly.
Second, the following is telling me:
System.Data.OracleClient.OracleException was unhandled
Message="ORA-06550: line 1, column 7:\nPLS-00306: wrong number or types of arguments in call to 'ADD_JOB_HISTORY'\nORA-06550: line 1, column 7:\nPL/SQL: Statement ignored\n"
Source="System.Data.OracleClient"
ErrorCode=-2146232008
Code=6550
StackTrace:
at System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle errorHandle, Int32 rc)
This is calling ADD_JOB_HISTORY in the XE/HR database. How do I figure out what it is unhappy with? I have tried every variation I can think of for this. Latest is:
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "ADD_JOB_HISTORY";
OracleParameter param = new OracleParameter("employee_id", OracleType.Number);
param.Value = 123;
cmd.Parameters.Add(param);
param = new OracleParameter("start_date", OracleType.DateTime);
param.Value = DateTime.Now.AddMonths(-1).Date;
cmd.Parameters.Add(param);
param = new OracleParameter("end_date", OracleType.DateTime);
param.Value = DateTime.Now.Date;
cmd.Parameters.Add(param);
param = new OracleParameter("job_id", OracleType.NVarChar);
param.Value = "SA_MAN";
cmd.Parameters.Add(param);
param = new OracleParameter("department_id", OracleType.Number);
param.Value = 10;
cmd.Parameters.Add(param);
thanks - dave
Dave,
You can pass an entire select statement as single parameter, such as a varchar2. Then, you just have PL/SQL execute the SQL statement for you.
Here's a code sample using ODP.NET for the same stored procedure that will work for the call to ADD_JOB_HISTORY. It appears you are using MS OracleClient in your code.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Oracle.DataAccess.Client;
namespace ConsoleApplication1
class Program
static void Main(string[] args)
try
OracleConnection con = new OracleConnection();
con.ConnectionString = "User ID=hr;Password=hr;Data Source=xe;";
con.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "ADD_JOB_HISTORY";
OracleParameter param = new OracleParameter("employee_id", OracleDbType.Int16);
param.Value = 123;
cmd.Parameters.Add(param);
param = new OracleParameter("start_date", OracleDbType.Date);
param.Value = DateTime.Now.AddMonths(-1).Date;
cmd.Parameters.Add(param);
param = new OracleParameter("end_date", OracleDbType.Date);
param.Value = DateTime.Now.Date;
cmd.Parameters.Add(param);
param = new OracleParameter("job_id", OracleDbType.NVarchar2);
param.Value = "SA_MAN";
cmd.Parameters.Add(param);
param = new OracleParameter("department_id", OracleDbType.Int16);
param.Value = 10;
cmd.Parameters.Add(param);
cmd.ExecuteNonQuery();
Console.ReadLine();
catch (Exception ex)
Console.WriteLine(ex.Message.ToString());
Console.WriteLine(ex.StackTrace.ToString());
}
Similar Messages
-
Calling packaged stored procedure from Java
Hi All,
I'm trying to call a stored procedure from Java but I'm having
problems with registrating the output parameter. I'm getting
the error: Conflicting parameters.: sqltype=2003
This is the stored procedure which is located in a package in
the Oracle database:
package Pack_GetAgencyInformation as
Type InfoType is record ( agen_code varchar(3), agen_designation
varchar(30), agen_adresse varchar(60), agen_tel varchar(12) );
function GetAgencyInformation( P_AGENCE VARCHAR )
return Pack_GetAgencyInformation.InfoType
end Pack_GetAgencyInformation;
This is the Java source from where I'm calling the procedure:
//DriverManager.registerDriver (new
oracle.jdbc.driver.OracleDriver());
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@164.48.69.125:1521:ventes", "system", "*****
// @machineName:port:SID,
userid, password
CallableStatement cs = conn.prepareCall("{ ? = call
Pack_GetAgencyInformation.GetAgencyInformation( ? )}");
try {
cs.registerOutParameter( 1,
oracle.jdbc.driver.OracleTypes.ARRAY);
} catch (SQLException e) {
e.printStackTrace();
cs.setString(2, "001" );
//ResultSet rset = cs.executeQuery();
The stacktrace:
java.sql.SQLException: Parametertypen conflicteren.:
sqlType=2003
at oracle.jdbc.dbaccess.DBError.throwSqlException
(DBError.java:168)
at oracle.jdbc.dbaccess.DBError.throwSqlException
(DBError.java:210)
at
oracle.jdbc.driver.OracleCallableStatement.registerOutParameter
(OracleCallableStatement.java:220)
at
oracle.jdbc.driver.OracleCallableStatement.registerOutParameter
(OracleCallableStatement.java:350)
at dbAccess.main(dbAccess.java:25)
I think it has to do with the type InfoType which is created in
the Stored Procedure. I'm absolute no Oracle expert and I
prefer not to make changes to the Oracle database. So any
solution in Java is welcome!
BR, H.RietmanI managed to get it to work only by changing the stored
procedure. I have changed the return type record to a Ref
Cursor type (had to change alot of code for this). It seams
that Oracle JDBC drivers DON'T support the Record type as a
return type.
So the next question is: is it possible to typecast a record
type to a ref cursor type in Oracle. In this way I can easily
change the return type for the stored procedures.
/Harald -
Calling a stored procedure from within a ViewObject
Is it possible to make stored procedure call from within a BC4J ViewObject? Basically something like this:
select * from table(f1(3)); where f1 is a table function. Using Oracle's pipelined table functions?
If not, is it possible to call a stored procedure from Java and have the returned results be put back into a BC4J RowSet.
In addition, is there a way to create a JDBC Resultset from a BC4J RowSet?
We need to be able to dynamically create our SQL statements (the entire SQL, not just the where clause) but are required to have these sql statements generated/executed from within a pl/sql stored procedure in the database.Is it possible to make stored procedure call from within a BC4J ViewObject? Basically something like this:
select * from table(f1(3)); where f1 is a table function. Using Oracle's pipelined table functions?
Yes. Using our expert-mode query feature this is possible.
is it possible to call a stored procedure from Java and have the returned results be put back into a BC4J RowSet.
Yes. See this article about basing a view object on a REF CURSOR:
http://radio.weblogs.com/0118231/2003/03/03.html
In addition, is there a way to create a JDBC Resultset from a BC4J RowSet?
No. Not directly. What's the business requirement here so I can understand better?
We need to be able to dynamically create our SQL statements (the entire SQL, not just the where clause) but are required to have these sql statements generated/executed from within a pl/sql stored procedure in the database.
REF CURSOR would work fine, or if it's just the statement that needs to be generated dynamically, you could fetch the text of the SQL statement from the stored procedure, then use createViewObjectFromQueryStmt(). Although this has runtime overhead involved with describing the query.
The REF CURSOR based approach is probably best for this. -
How to call a stored procedure from WorkShop
Hello Everyone .. I'm quite new with WebLogic 8.1 & WorkShop, so please bare with
me .. Today I'm simply trying to find out how to call a stored procedure from
within workshop, using any of the DB Controls .. I see workshop provides a way
create a Java Control, Rowset Control, but it wont easily allow for a stored procedured
to be entered in place of the inline query .. Perhaps I've over looked it. Any
advise on the best way to tackle this task will be appreciated.
AtahualpaAtahualpa--
Maybe this will help:
http://edocs.bea.com/workshop/docs81/doc/en/workshop/guide/controls/database/conStoredProcedures.html
Eddie
Atahualpa wrote:
Hello Everyone .. I'm quite new with WebLogic 8.1 & WorkShop, so please bare with
me .. Today I'm simply trying to find out how to call a stored procedure from
within workshop, using any of the DB Controls .. I see workshop provides a way
create a Java Control, Rowset Control, but it wont easily allow for a stored procedured
to be entered in place of the inline query .. Perhaps I've over looked it. Any
advise on the best way to tackle this task will be appreciated.
Atahualpa -
Calling a stored procedure from a url
I am needing to call a stored procedure from a url string (or
anchor) understand that from training to be as follows:
http://host:port/pls/dad/package.procedure?query_string
With that in mind, I am getting an error as follows:
Not Found
The requested URL /pls/portal30/at_hrfm.checkshow.showcheck was
not found on this server.
Here is a sample of my url
http://servername:port/pls/portal30/at_hrfm.checkshow.showcheck
I can see servername:port/pls/portal30, it is just the
procedure I am having a problem with.
Here is a sample of my source code that is created under the
at_hrfm schema (I also tried under portal30 schema).
package body checkshow as
procedure showcheck as
begin
htp.htmlOpen;
htp.headOpen;
htp.title('My Check');
htp.comment ('This should be your Check');
htp.bodyOpen;
htp.header (1,'Check');
htp.print ('checkdate');
htp.bodyClose;
htp.headClose;
htp.htmlClose;
end;
end;I think I figured this out. I don't think the grant to ANONYMOUS is going to work with production XE and the online documentation is in need of an update. It appears that production XE has been locked down and you will need to specify the name of each stored procedure you wish to allow to be executed by adding it to the WWV_FLOW_EPG_INCLUDE_MOD_LOCAL function. This is spelled out in more technical detail here: http://download.oracle.com/docs/cd/B25329_01/doc/appdev.102/b25309/adm_wrkspc.htm#BEJCGJFJ
Another alternative that would work involves creating a separate DAD. Using the DAD approach with my schema made all of my stored procedures callable from a web browser, so I rejected this approach. To make this usable (secure) I would have needed to create and maintain a separate database user for the DAD and then only granted it execute for the stored procedures I wanted to be callable from a URL.
Finally I read about using an on-demand procedure and having it invoke the desired stored procedure. While I didn't try this out, it sounds like another good approach because it maintains session security. If it can be used to return an image I do not know.
- Jim -
Calling a stored procedure from Reports
I am trying to call a stored procedure using oracle reports in the afterparameter code. My code is:
v_ain := sp_get_ain(:P_session_id);
Can someone help me out by telling what is wrong. I keep getting an error stating that sp_get_ain needs to be declared.?!I am creating a function and a stored procedure and calling them
in afterparameter report trigger.
-------------------Create function ----------------
create or replace function get_name( emp_id number) return varchar2 is
v_name varchar2(20);
begin
select name into v_name
from sample_table
where employ_id = emp_id ;
return(v_name); ---------This is the way to return value from function.
exception
when no_data_found then
return('Name not found.');
when others then
return('Other error found.');
end ;
==================================================================================
------------------------Create procedure ------------------------------------
create or replace procedure get_name( emp_id number, return_name out varchar2) is
v_name varchar2(20);
begin
select name into v_name
from sample_table
where employ_id = emp_id ;
return_name := v_name ; --Assign out parameter value from procedure.
exception
when no_data_found then
return_name := 'Name not found.';
when others then
return_name := 'Other error found.';
end ;
============================================================================
-----------------Call function and procedure from report ---------------------
In formula column or any report trigger you can use this code.
v_function_return_name varchar2(20);
v_procedure_return_name varchar2(20);
v_employ_id number(10);
begin
v_employ_id := 101 ;
v_function_return_name := get_name(v_employ_id ); --- call function
get_name(v_employ_id , v_procedure_return_name ); -- call procedure
end;
Here v_function_return_name has same value as v_procedure_return_name,
these are the values returned from function and procedure.
--Anita -
Calling Oracle Stored Procedure from BC4J JSP App
I am on an extremely tight deadline and am trying to get my JSP application to use an Oracle Stored Procedure. I need to take some input from the user and send these values as parameters. Has anyone worked with Stored Procedures in JDev3.1? Please reply with some sample code if possible.
Thanks.Hi,
Someone posted a similar request the other day. Here is my response to them:
Basically, you need to create a custom method from your JSP's ViewObject, which calls the stored procedure. You can then call the ViewObject's custom method from the JSP client.
Here is how I have done it:
1. Choose the ViewObject that your JSP is based on and choose 'Edit' from the context menu.
2. On the Java tab of the ViewObject wizard, choose Generate Java File checkbox for the View Object Class and click the Finish button. A file is created under the ViewObject node in the Navigator named 'viewobjectImpl.java'.
3. Open the viewobjectImpl.java file in the code editor and create a method to call your stored procedure (see sample code below).
4. Compile the VOImpl.java file.
5. Choose the view object again, and choose Edit again from the context menu.
6. On the Client Methods tab, you should now see your method appear in the Available field. Select it and shuttle it to the Selected field.
7. Click Finish to leave the VO wizard, and rebuild your Business Components project.
8. In your JSP, call the custom method (see sample code below).
sample code for custom method calling a stored procedure from VOImpl.java file:
public int getTotalHits(String mon, String year) {
CallableStatement stmt = null;
int total;
// the call to the PL/SQL stored proc
String totalhits = "{? = call walkthru.total_hits(?,?)}";
// use the AM conxn 2 call storedproc
stmt = getDBTransaction().createCallableStatement(totalhits, 1);
try
// Bind the Statement Parameters and //Execute this Statement
stmt.registerOutParameter(1,Types.INTEGER);
stmt.setString(2,mon); stmt.setString(3,year);
stmt.execute();
total = stmt.getInt(1);
catch (Exception ex)
throw new oracle.jbo.JboException(ex);
finally
try
stmt.close();
catch (Exception nex)
return total;
sample render code for calling custom method from JSP custom bean:
public void render() {
int totalhits;
try
Row[] rows;
// Retrieve all records by default, the qView variable is defined in the base class
qView.setRangeSize(-1);
qView.first();
rows = qView.getAllRowsInRange();
// instantiate a view object for our exported method
// and call the stored procedure to get the total
ViewObject vo = qView.getViewObject();
wtQueryView theView = (wtQueryView) vo;
totalhits = theView.getTotalHits(session.getValue("m").toString(),session.getValue("y").toString());
out.println(totalhits);
} catch(Exception ex)
throw new RuntimeException(ex.getMessage());
} -
Trying to call a stored proc from a form ?
Hi im trying to call a stored procedure that create a web page
any where from within a form. (the SP It uses the htp package).
It does not seem to work.
lets say in the PL/SQL block before the footer i pu
<schema>.my_procedure;
i get a not decleared <schema>.my_procedure error.
Could someone help !
Also is there a way to call stored proc directly from the url
I tried httP://hostname/pls/portal30/<schema>.my_procedure
unsuccessful.
thanksFor it to work, you should grant EXECUTE on your Procedure to
PUBLIC.
Have you done that?
If yes then there is a problem. -
Calling invalid stored procedure from java
Will the stored procedure which is invalid get re-compiled automatically when called from a java program?
1.a stored procedure is invalid (oracle 9i)
2.calling the stored procedure from a java program
3.what will happen a.oracle recompiles the stored procedure
b.returns an sql exception
what happens,kindly help
drop your mail to [email protected]
Keep Smiling and Mailing,
Vijay Anand Natesan.thank you ..Kindly let me know if any of your friends have tried this
-
Error calling a stored procedure from C#
Please help me!
I'm new in .net technology.
I have an Oracle 9i server and an application in .net C# language.
I'm trying to call a stored procedure written in plsql.
This is the testing procedure:
CREATE OR REPLACE PROCEDURE TEST_PROC
par_1 in number
as
begin
insert into tbltestinput (number_col) values (par_1);
commit;
end;
And the calling code is:
OracleCommand objCmd = new OracleCommand("TEST_PROC",conn);
objCmd.CommandType = CommandType.StoredProcedure;
OracleParameter inPar_1 = new OracleParameter();
inPar_1.OracleType = OracleType.Number;
inPar_1.Direction = ParameterDirection.Input;
inPar_1.Value = 123456;
objCmd.Parameters.Add(inPar_1);
objCmd.ExecuteNonQuery();
It returns this error:
Exception Message: ORA-06550: row 1, column 7: PLS-00306: wrong number or types of arguments in call to 'TEST_PROC' ORA-06550: row 1, column 7: PL/SQL: Statement ignored
Exception Source: System.Data.OracleClient
The stored procedure is very very simple to test only the call.
Anybody can help me.
Thanks !!!!Hello,
System.Data.OracleClient == Microsoft provider for Oracle (whereas this is the Oracle Data Provider for .NET forum).
However, the MS provider operates in Bind By Name mode, so you might try adding this to your code:
inPar_1.ParameterName = "par_1";Perhaps that will help a bit,
Mark -
Calling Oracle Stored Procedure from Weblogic.
Hi All,
I am using Oracle 11g R2 and weblogic 10.3.5.0
Do you know if it is possible to call a stored procedure from Weblogic.
Basically, what I would like to do is to call the following procedure : EXEC DBMS_SESSION.SET_IDENTIFIER('provider_a') when my application connects to my database, "provider_a" being the user used to connect to the oracle schema.
Thanks.Up !
Thanks. -
Can i call a stored procedure from OracleDashboardPrompt?
Hi,
Can i call a stored procedure from OracleDashboardPrompt once i click the Go button in OBIEE?The input parameters to the procedure are the one that i have given in DashboardPrompt.and based on the result of the procedure(either 0 or 1),i have to display reports.Can anyone help me.
Thanks in Advance...Please find below the possible approach to the scenario:
1.Create a prompt for the column which you need as input to store proc and create a presentation variable for that .
2.Create a dummy report with 1 column which will have the above created presentation variable as filter(We can design this reports in such a way like the first column will get filtered based on the presentation variable)
3.Create a second column and in the column definition we can add a code like
evaluate('StoreProc(%1)','@{firstcolumn}')
4.We can hide the first column in the report and only show the output of store proc to the end user
Hope this helps :) -
Can we call a stored procedure from a Trigger
Hello Everyone,
I need some help in writing the triggers in Oracle 10g Database.
Can we call a stored procedure from a trigger?Can we call a stored procedure from a trigger? Yes. Why did you think we couldn't?
Cheers, APC -
Problem in calling Oracle stored procedure from Java.
I am trying to invoke the Oracle stored procedure from Java. The procedure does not take any parameters and does not return anything. If I call it from SQL prompt it is working perfectly. I am calling it in my program as follows.
callable_stmt=con.prepareCall("{call pkg_name.proc_name()}");
callable_stmt.execute();
The problem is the control-of-flow is getting strucked in the second line I wrote. It is not giving any error also.
Please clarify me what's wrong with my code?
Seenu.And how long does the stored procedure take to run from your client machine when running it via sqlplus?
-
How to call a Stored procedure from xsodata service?
Hi Everyone,
I have created an stored procedure and I'm trying to consume this store procedure from xsodata service.
But unable to activate the service because of an error.
Invalid procedure or parameter list in procedure "package.WebContent.src.hana.procedures::PROCEDURE
I have activated both store procedure as well as attribute view.
Here is my stored procedure.
PROCEDURE "SCHEMA"."package.WebContent.src.hana.procedures::PROCEDURE" (
IN row "SCHEMA"."package.tables::object" )
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER AS
--DEFAULT SCHEMA <default_schema_name>
--READS SQL DATA AS
BEGIN
Write your procedure logic
declare shortdesc string;
SELECT SHORT_DESCRIPTION INTO shortdesc FROM :row;
END;
Service:
service namespace "package.WebContent.src.hana.service"{
"package/OBJECT.attributeview" as "OBJECTS"
key ("OBJECT_ID")
create using "package.WebContent.src.hana.procedures::PROCEDURE";
Is there anything wrong in the way i'm calling the procedure??Hi Arjun,
You can expose the procedure as an Odata Service if you wrap it in a Scripted Calculation View..
Firstly You will have to create a Scripted Calculation View from the Modeller perspective.
Below is an example I just tried.
Add Columns & Input Parameters
Consume this Calc View in your Odata service :
service namespace "services.test"
"pda.Models::CV_TEST" as "Customer"
keys generate local "ID"
parameters via entity;
Check your service by Passing the Input Parameters
http://<host>:<port>/<>/services/test.xsodata/CustomerParameters(2)/Results?$format=json
Hope this was Helpful
Regards,
Avinash Raju
Maybe you are looking for
-
Downloaded files won't open, and mouse sometimes disappears
Hey there, I've just been having some rather minor problems with my iBook, and I thought maybe someone could help me out. First of all, my iBook won't open a lot of applications that I download. It says that it can't find the application to open the
-
Album art, separate drive, can't update
I have searched the forums and have found many old posts concerning some of my issues. Nothing current, as far as I can tell I am running (connected, not wireless) Front Row from my iBook in my den to my amplifier. It is streaming music from my Mac P
-
Consolidation not getting started in Task Flow
Hi All, I am using Task Flow to run the HFM Consolidations in 9.3.1.. when i select "Run Now", the task flow is getting started and is in "Active" mode but the consol never starts. I checked in "Running Tasks" and in the grid for the cell status, bot
-
I have a problem associated with the right mouse button. When I right click on my 3D program I get a tray with the finder and open apps icons. This prevents the execution of the action I want to carry out in the 3D program. This only happens on the M
-
Flash Constantly Crashes in FF
I have read all the FAQs and tried everything in the forums and knowledge base and Adobe Flash continues to crash. I have even installed older versions but now they no longer work because I get error messages that I need to upgrade to a newer version