Calling Stored Procedure which returns single or multiple value
Hi All Experts,
I have written one stored procedure which is returning different
integer values according to condition.I am calling this
stored procedure through prepareCall() method then executeUpdate() method ,but it is always returning 1,not my desired value.
Pl also tell me,if my stored procedure returns more than one value
then how will i get those values in my java program?
Pl help by writing some sample code.
Thanx in Advance.
Pradipto
1) Create CallableStatement
2) For each of returning value you have to call RegisterOutParameter()
3) For others user setXXX() method depending on type of parameter
4) call
5) use vars registered through RegisterOutParameter() - all your values should be there
Pavel
Similar Messages
-
Calling a stored procedure which returns a value
Hi Friends,
I want to call a stored procedure which returns a value.
Eg
create or replace procedure xyz(a1 in varchar2, a2 in varchar2, z1 out number)
thanksHi,
use this.
declare
retval number;
begin
abc('aaa','bbb',retval);
dbms_output.put_line('retval is ' ||retval);
end;
--Basava.S -
Calling Stored procedure which uses Bulk Collect
Hi All, I have Oracle stored procedure which uses Bulk Collect and returns table type parameter as output. Can anyone please help me how Can I call this kind of stored procedures which returns table type output using VB and Oracle's Driver. (I am successfully able to call using MS ODBC driver, but I want to use OraOLEDB driver.)
861412 wrote:
how Can I call this kind of stored procedures which returns table type output using VB and Oracle's Driver. This forum deals with the server-side languages SQL and PL/SQL.
Your question deals with the client side and Visual Basic language. -
Hello!
I have developed a Java application which calls stored procedures, some of which return a ResultSet (always one).
I need to support more DBMS vendors, so I used the standard JDBC syntax to call the stored procedures ({call storedProcedure(?,?)}).
I developed the code using MySQL, but succeded to call SQL Server 2000 stored procedures changing only the driver (that's the purpose of JDBC, right?).
Now I need to support the Oracle DBMS, but I can't find a way to create a stored procedure which returns a result set and allows me not to change the already stable Java code.
How could I achieve this result? Should I use some other Oracle object, say a function?
By the way, I searched the Internet, but only found solutions which would've made me change code. This is definitely not portable
Thank you very much for your help!
PS: Some of the stored procedures return both a ResultSet AND OUT parameters.Hello and thanks for your reply, jwenting.
However, keeping useless "philosophy" out of this thread, please just let me clarify that I obviously didn't want portability of stored procedures, I just wanted a standard JDBC to interface with them. I haven't had problems in the past with stored procedures and other DBMSs, I'm having them just now with the Oracle JDBC driver. Since JDBC is meant to be portable, I hoped there was a portable way of calling Oracle stored procedures (or whatever else in Oracle takes inputs and returns output and a ResultSet...). Unfortunately, there doesn't seem to be any, unless I use a commercial driver from DataDirect. I find this a heavy limitation of the Oracle JDBC driver, but, alas, here it is... I'll have to refactor my stable code...
Thanks again... -
Calling stored procedure and returning multiple resultsets
Hello,
Is it possible to create a procedure that return multiple result sets?
e.g.
procedure GetDataFromTables() is
begin
select * from table_one;
select * from table_two;
end GetDataFromTables;
And I want to call this procedure that returns multiple resultsets (one for table_one and another for table_two)
I have referred to the OCCI sample occiproc.cpp, but I am not sure how to handle multiple resultsets.
Your help is highly appreciated.Thank You,
Got the REF cursor in storedproc.cpp.
But as it is documented, getCursor() gets the REF CURSOR value of an OUT parameter as a ResultSet.
So, is it true that if I have to write a procedure that selects * from 50 tables (50 SQL statements) , I have to set 50 OUT parameters to get the result sets.?
Is there any better way of doing this?
e.g. in DB2, we can open multiple cursors in the procedure body and then get the result set one after another.
CREATE PROCEDURE get_staging_data ()
RESULT SETS 1 <no. of result sets>
LANGUAGE SQL
BEGIN ATOMIC
DECLARE L_SQL varchar(5000);
DECLARE c CURSOR WITH RETURN TO CLIENT FOR L_STMT;
SET L_SQL = '';
SET L_SQL = 'SELECT * FROM ';
SET L_SQL = L_SQL || IN_Tab_Name ;
SET L_SQL = L_SQL || ' WHERE VERIFY_FLAG=''S'' FOR READ ONLY OPTIMIZE FOR 2000 ROWS' ;
PREPARE L_STMT FROM L_SQL;
OPEN c; < can open multiple cursors in the prodedure body>
END -
Function calling stored procedure that returns a cursor into a LOV
Hello,
Is it possible in HTML DB to implement a process that has a function that calls a stored procedure that returns a cursor, used to then populate a select list?
Or can I do a function call to a stored procedure in the 'List of values definition' box for the item itself that returns a cursor to populate the item's select list?Hi Vikas,
Actually, I just found another posting that shows how to do what I'm looking for:
Re: Filling a LOV with a cursor
Check it out. I posted another question in response to that discussion...maybe you could answer that? Thanks!
Laura -
Send SQL query or call stored procedure, which is best???
hello experts!!
i would like to ask what will be the best implementation on querying a database using Java, send a SQL query(insert into table values...) or call stored procedure(just pass parameters)?? and also in stored procedure does "autoCommit/rollback" applies/make sense??I searched google for this:
Stored Procedures vs. SQL
and found this useful link:
http://www.karlkatzke.com/stored-procedures-vs-sql-calls/
I thiink you should also read up on other articles based on such google searches
to get other opinions. Also, read the links provided by that article.
Personnally, I think stored procedures should be avoided unless there is a definite
advantage as specified in the above article. Especially not used for CRUD operations.
Also, no matter where you put the SQL, it should be documented. I've seen too many stored procedures that aren't documented. -
SOAP TO JDBC scenario: calling stored procedure which will return the value
Hi
I have Soap To Jdbc scenario in which I am going to call the Stored Procedure at target side which will be executed and it is going to return the result set .
Result contains following values.
return code as ( 0 Or 1) and also specific exception message if its return code as 1.
Could you suggest me the way by which I can handled this return code and send it back to the Sap PI system then the same thing is directed the to SMTP server for sending mail to consern person.
Regards
KumarThe OUT parameters of stored procedure will be returned as response. Where exactly are you facing the proble? Here is a complete walkthourgh
/people/luis.melgar/blog/2008/05/13/synchronous-soap-to-jdbc--end-to-end-walkthrough
In your case, you don't want response at sender. Instead you want to mail it. For this you may use BPM to design your scenario with following steps
Receive (to receive data from sender)
Send Sync (to stored procedure and get response)
Send Async (to mail receiver)
Regards,
Prateek -
XI calling an Oracle Stored Procedure which returns an Object to XI
I am currently trying to call an Oracle Packaged/Procedure from XI which accepts a couple of parameters as I/O and returns an Object as one of the parameters.
I have created the Object within the Oracle Database CREATE OR REPLACE TYPE xy_jdbc AS OBJECT
column_name type ...etc
CREATE OR REPLACE TYPE xy_tab_jdbc AS TABLE OF xy_jdbc;
One of the parameters for the stored procedure is set up as this type xy_tab_jdbc this will be populated based upon one of the parameters passed into the Package/Procedure.
Is this possible? If it is, how do I map the returned object within XI?Dear Hilary,
the JDBC adapter does not support vendor-specific or non-scalar data types.
Workaround: Change the stored proc's signature not to use an object, but the object's fields instead.
Regards,
Thilo -
Calling a stored procedure which returns a UDT
Hi devs,
Recently I've come across this requirement where I need to get a Oracle UDT returned from a stored procedure. The stored procedure I've used is described below.
CREATE OR REPLACE PROCEDURE test_proc(param_id IN NUMBER, cust OUT CUSTOMER)
IS
BEGIN
SELECT customer INTO cust from CUS_T where id=param_id;
END;
the type CUSTOMER has the following structure.
CREATE OR REPLACE TYPE CUSTOMER AS OBJECT(
id NUMBER,
name VARCHAR2(20)
the table "CUS_T" is of the following structure.
CREATE TABLE CUS_T(id NUMBER, customer CUSTOMER);
The use case I'm trying to address is that I need to retrieve the CUSTOMER object corresponding to a particular ID through a java code snippet. Here's how I'm currently trying to get it done.
*CallableStatement cs=connection.prapareCall("{test_proc(?,?)}");*
*cs.setInt(1,some_int);*
*cs.registerOutParameter(2,Types.STRUCT);*
*cs.execute();*
*Struct result=(Struct)cs.getObject(1);*
Although Oracle returns UDTs as SQL Structs, I'm running into the following exception while executing the aforementioned code snippet.
*java.sql.SQLException: ORA-03115: unsupported network datatype or representation*
Any help on this matter would be greatly appreciated.
Cheers,
PrabathHi,
I've been able to find the solution for this problem. The following simple code snippet
has the done trick.
CallableStatement ocs = connection.prepareCall("{ call testProc(?)}");
ocs.registerOutParameter(1, Types.STRUCT,"CUSTOMER");
ocs.execute();
What I did there was, simply adding the UDT_NAME (the name CUSTOMER in the
previous example) while registering the OUT parameter.
Cheers,
Prabath
Edited by: 829281 on Feb 2, 2011 5:56 PM -
How to use stored procedure which returns result set in OBIEE
Hi,
I hav one stored procedure (one parameter) which returns a result set. Can we use this stored procedure in OBIEE? If so, how we hav to use.
I know we hav the Evaluate function but not sure whether I can use for my SP which returns result set. Is there any other way where I can use my SP?
Pls help me in solving this.
ThanksHi Radha,
If you want to cache the results in the Oracle BI Server, you should check that option. When you run a query the Oracle BI Server will get its results from the cache, based on the persistence time you define. If the cache is expired, the Oracle BI Server will go to the database to get the results.
If you want to use caching, you should enable caching in the nqsconfig.ini file.
Cheers,
Daan Bakboord -
How to execute an Oracle stored procedure which returns many records?
I have two synchronous scenarios XI<->PI<->JDBC, where JDBC is receiver adapter.
Each scenario runs a different stored procedure in Oracle database.
The first stored procedure returns only one record, the second stored procedure returns many records, which come from a cursor.
In the first scenario I executed the stored procedure following the directions of Help SAP page and works perfectly.
Link: [http://help.sap.com/saphelp_nw70/helpdata/en/2e/96fd3f2d14e869e10000000a155106/content.htm]
<root>
<StatementName5>
<storedProcedureName action=u201DEXECUTEu201D>
<table>realStoredProcedureName</table>
<param1 [isInput=u201Dtrueu201D] [isOutput=true] type=SQLDatatype>val1</param1>
</storedProcedureName>
</StatementName5>
<root>
I have sought in the forums of SDN and cannot find the way to run the second stored procedure, and receive the information it returns.
Thank you for your help.
Rafael Rojas.Think It doesnt matter either cursor or result set. Try to get the response back from JDBC and see what are the fields it exactly populating.
In Procedure you can able to find the columns selecting in Cursors. Give those columns in the DT.
File - JDBC (Execute-- Procedure)
To get the response
JDBC_respose - File
Correct me if im wrong.
Regards
Ramg -
How to call a procedure which returns out parameter in form personalization
Dear All,
I have one procedure which is having 2 parameter in and one parameter out .
The question is how to get the parameter out in from personalization in a local or global variable?
ThanksYes.
You can use the "forms_ddl" builtin
See the following examples. Make sure you include the single quotes as well as the = sign in the begining.
See http://phenix.blog.163.com/blog/static/8397219320096213953151/
http://oracle.anilpassi.com/forms-personalizations.html
Sandeep Gandhi -
Stored procedure which returns date error
if have a function getGmtDate in the package pa which uses a date as parameter and returns a date
conn.Connect()
strSQL = "pa.getGmtDate"
P_RETURN As New OracleParameter(":pRETURN", OracleDbType.Date, ParameterDirection.ReturnValue)
Dim P_DATE As New OracleParameter(":pDATE", OracleDbType.Date, 0, ParameterDirection.Input)
P_DATE.Value = Now 'current date
Dim cmd As New OracleCommand(strSQL, conn.getConnection)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(P_RETURN)
cmd.Parameters.Add(P_DATE)
cmd.ExecuteNonQuery()
dim returnValue as Date = P_RETURN.Value
and the date is retrieved correct from the db, but when I want to bind the resultdate to a variable then it throws an exception:
Cast from type 'OracleDate' to type 'Date' is not valid
can anyone help me?1) Create CallableStatement
2) For each of returning value you have to call RegisterOutParameter()
3) For others user setXXX() method depending on type of parameter
4) call
5) use vars registered through RegisterOutParameter() - all your values should be there
Pavel -
Invoking stored procedure that returns array(oracle object type) as output
Hi,
We have stored procedures which returns arrays(oracle type) as an output, can anyone shed some light on how to map those arrays using JPA annotations? I tried using jdbcTypeName but i was getting wrong type or argument error, your help is very much appreciated. Below is the code snippet.
JPA Class:
import java.io.Serializable;
import java.sql.Array;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.eclipse.persistence.annotations.Direction;
import org.eclipse.persistence.annotations.NamedStoredProcedureQuery;
import org.eclipse.persistence.annotations.StoredProcedureParameter;
* The persistent class for the MessagePublish database table.
@Entity
@NamedStoredProcedureQuery(name="GetTeamMembersDetails",
procedureName="team_emp_maintenance_pkg.get_user_team_roles",
resultClass=TeamMembersDetails.class,
returnsResultSet=true,
parameters={
@StoredProcedureParameter(queryParameter="userId",name="I_USER_ID",direction=Direction.IN,type=Long.class),
@StoredProcedureParameter(queryParameter="employeeId",name="I_EMPLOYEEID",direction=Direction.IN,type=Long.class),
@StoredProcedureParameter(queryParameter="TEAMMEMBERSDETAILSOT",name="O_TEAM_ROLES",direction=Direction.OUT,jdbcTypeName="OBJ_TEAM_ROLES"),
@StoredProcedureParameter(queryParameter="debugMode",name="I_DEBUGMODE",direction=Direction.IN,type=Long.class)
public class TeamMembersDetails implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private long userId;
private List<TeamMembersDetailsOT> teamMembersDetailsOT;
public void setTeamMembersDetailsOT(List<TeamMembersDetailsOT> teamMembersDetailsOT) {
this.teamMembersDetailsOT = teamMembersDetailsOT;
public List<TeamMembersDetailsOT> getTeamMembersDetailsOT() {
return teamMembersDetailsOT;
Procedure
PROCEDURE get_user_team_roles (
i_user_id IN ue_user.user_id%TYPE
, o_team_roles OUT OBJ_TEAM_ROLES_ARRAY
, i_debugmode IN NUMBER :=0)
AS
OBJ_TEAM_ROLES_ARRAY contains create or replace TYPE OBJ_TEAM_ROLES_ARRAY AS TABLE OF OBJ_TEAM_ROLES;
TeamMembersDetailsOT contains the same attributes defined in the OBJ_TEAM_ROLES.A few things.
You are not using a JDBC Array type in your procedure, you are using a PLSQL TABLE type. An Array type would be a VARRAY in Oracle. EclipseLink supports both VARRAY and TABLE types, but TABLE types are more complex as Oracle JDBC does not support them, they must be wrapped in a corresponding VARRAY type. I assume your OBJ_TEAM_ROLES is also not an OBJECT TYPE but a PLSQL RECORD type, this has the same issue.
Your procedure does not return a result set, so "returnsResultSet=true" should be "returnsResultSet=false".
In general I would recommend you change your stored procedure to just return a select from a table using an OUT CURSOR, that is the easiest way to return data from an Oracle stored procedure.
If you must use the PLSQL types, then you will need to create wrapper VARRAY and OBJECT TYPEs. In EclipseLink you must use a PLSQLStoredProcedureCall to access these using the code API, there is not annotation support. Or you could create your own wrapper stored procedure that converts the PLSQL types to OBJECT TYPEs, and call the wrapper stored procedure.
To map to Oracle VARRAY and OBJECT TYPEs the JDBC Array and Struct types are used, these are supported using EclipseLink ObjectRelationalDataTypeDescriptor and mappings. These must be defined through the code API, as there is currently no annotation support.
I could not find any good examples or doc on this, your best source of example is the EclipseLink test cases in SVN,
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/plsql/
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/customsqlstoredprocedures/
James : http://www.eclipselink.org
Maybe you are looking for
-
Hi, for some reason I can't add more music to my iPod and it doesn't give me the choice of choosing iTunes to show my iPod. I want to add more music but all it gives me the option to do it put pictures my computer. I really need help and I have no cl
-
Mini DVI port on MacBook changed
I have been using Mini DVI to VGA on my PowerBook (12 in) for several years, now. I just purchased the new MacBook (Black) and find that the adapter does not fit into the DVI port! When looking on a couple of retail website, including Apple, I find o
-
How do you add adobe flash player to your mac computer
How do you add adobe flash player on a mac computer so you can watch youtube and or listen to music?
-
I have a large quicktime movie. I am assuming I need to make it a flash movie to reduce size of file? I am unfamiliar with flash, so I need step by step instructions on how to do this and how to put on page in website. Thank you. octoberben
-
My FCP 4.5 quit when I want to export in MPEG 2, help me please
I finished to buy the system the 10,4 and Toast Titanium 7. In the FCP 4.5 I make to export in the QuickTime conversion I choose the MPEG-2 and the FCP is unexpectedly quit. Some thing must be in conflict, but I do not know what. I already order Univ