I've posted to the mqseries forum too, but haven't got any answers yet.
I have problems using a Websphere adapter for JDBC in order to call an Oracle stored procedure. The procedure looks like this:
create or replace
procedure sp_myproc(par_out out SYS_REFCURSOR)
as
begin
open par_out for select * from my_table;
end;
I have generated the BO definition using ODA. I have also read this:http://pic.dhe.ibm.com/infocenter/dmndhelp/v7r0mx/index.jsp?topic=%2Fcom.ibm.wsadapters.jca.jdbc.doc%2Fdoc%2Fcjdb_ov_storedproc_bo.html
My question is how to specify the ASI for the RetrieveSP correctly?
If I use: SPN=sp_myproc;RS=true;OP=RS I get the following error: "ResultSet as output parameter for Stored Procedure not supported for database Oracle and JDBC Driver oracle.jdbc.OracleDriver".
Related
I'm using SQL Oracle to build a stored procedure. I'm trying to build a stored procedure of the SQL-query below.And I want to return those data to a C# program.
select * from employee_master
I have tried following. Is this correct?
CREATE OR REPLACE PROCEDURE EMPLOYEE_SELECTALL (p_recordset OUTSYS_REFCURSOR)AS
BEGIN
OPEN p_recordset FOR
SELECT
*
FROM
EMPLOYEE_MASTER;
END EMPLOYEE_SELECTALL;
If you wish to build a stored procedure that return such resultset first of all you should check if you really need to do this. It's incidental and not recommended way for Oracle. But if you really need so, you should use REF CURSOR.
after executing your stored procedure in SQL Developer, it automatically brings back any output for you to view, including one or more ref cursors.
Example code and screenshots here
I have a SP which is Merge type in nature. For the purpose, I am laoding a temp table with data on Oracle database and Then I am inserting/Updating my destination table by calling this stored procedure. I am not passing any parameter inside this stored procedure.
When I used {call mystoredprocedure ()} using ado net or old db connection for oracle database, the execute sql task just goes yellow and never finishes up.
I have called this stored procedure directly on sql developer and it work fine.
Can anyone suggest me to do this correctly.
In Toad or SQL Developer, I would call my Oracle procedure with:
EXEC SCHEMA.MY_PROCEDURE();
In SSIS, in a SQL task, I can call my Oracle procedure like:
BEGIN SCHEMA.MY_PROCEDURE();
END;
The following stored procedure code works in our DEV and TEST environments which run with Oracle 11G but will not work in our 10G PROD environment:
first, I created my own data structure in Oracle to hold any array of VARCHAR2:
create or replace
type MAT_MULTIPLES_ARRAY as table of VARCHAR2(100);
here is the procedure code:
create or replace PROCEDURE MAT_SUBMIT_JOB (v_multiples_columns_to_add IN our_schema.MAT_MULTIPLES_ARRAY)
v_jobno number;
v_job_name VARCHAR2(100);
v_error_message VARCHAR2(32000);
begin
v_job_name := 'doesnt matter right now';
dbms_scheduler.create_job(v_job_name,program_name=>'MAT_JOB_PROGRAM');
dbms_scheduler.set_job_anydata_value(v_job_name,1,sys.anydata.convertCollection(v_multiples_columns_to_add));
dbms_scheduler.enable(v_job_name);
end;
again, this same code works in 11G in our DEV and TEST environments, and it compiles in our 10G environment, but then it appears to barf during runtime, on the second dbms_scheduler line (in bold).
Does dbms_scheduler work in 10G? Or perhaps there is a problem with 'sys.anydata.convertCollection(v_multiples_columns_to_add)'
Here is the error message:
ORA-22370: incorrect usage of method originated from line 19 in my procedure.
line 19 is the line with convertCollection() call.
Please help!
I found this in the documentation:
http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_sched.htm#i1000820
SET_JOB_ANYDATA_VALUE requires that you be the owner of the job or have ALTER privileges on that job. You can also set a job argument value if you have the CREATE ANY JOB privilege.
This might also be related as well:
ANYDATA with Collections based on rowtype
how do you create a stored procedure with a simple select (SELECT * FROM TABLE) using Oracle? Also, any good tutorials on stored procedures would help tremendously.
Thanks.
It depends on what you're trying to return from the stored procedure (resultset vs. scalar value) and what version of Oracle you're on (newer versions make this easier).
This question is probably a dupe of Get resultset from oracle stored procedure.
create or replace procedure spr_select_Emp(eno in number, employee out emp%RowType)
As
Begin
Select empno,ename,mgrno,hiredate,sal,comm,deptno into employee from emp
where empno=eno
End;
A procedure is created using the Oracle create or replace procedure syntax below:
create or replace procedure
()
as (or is)
local variable declaration
begin
code section
exceptions
end;
more info here: http://www.dba-oracle.com/t_create_or_replace_procedure.htm
The Oracle version of our database is 10g.
The stored procedure selects all the elements in a table and returns a REF CURSOR type as follows:
create or replace
PROCEDURE S_S_TEST(
test_OUT OUT OAS_TYPES.REFCURSOR
)
AS
BEGIN
OPEN test_OUT FOR
SELECT *
FROM table_p;
CLOSE test_OUT;
END S_S_TEST;
When this stored procedure is executed in JAVA the following exception is obtained-
java.sql.SQLException: Cursor is closed. at oracle.jdbc.driver.T4CResultSetAccessor.getCursor(T4CResultSetAccessor.java:323) at oracle.jdbc.driver.ResultSetAccessor.getObject(ResultSetAccessor.java:85) at oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:1401) at com.ibm.ws.rsadapter.jdbc.WSJdbcCallableStatement.getObject(WSJdbcCallableStatement.java:443)
I am trying to understand what the error is and how it could be fixed. Could someone please help me out?
Thanks!
The client calling the stored procedure is responsible for closing the cursor. Please remove the code:
CLOSE test_OUT;
The client closes it. In this case the client is the JDBC program that calls the stored procedure.