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,
Prabath
Hi,
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
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 -
Call a Stored Procedure that returns a REFCURSOR using ODI Procedure
Hi,
I have a scenario wherein the stored procedure (TEST_PROC1) that returns a REFCURSOR. The second procedure(TEST_PROC2) will use the REFCURSOR as inpuut and insert it to a table.
Now, I need to execute the test procedures (TEST_PROC1 and TEST_PROC2) using the ODI Procedure but I always get error. However, I was able to execute the test procedures using sqlplus. Here is the command I used for sqlplus:
var rc refcursor
exec TEST_PROC1(:rc);
exec TEST_PROC2(:rc);
PL/SQL Stored Procedure:
-- TEST_PROC1 --
create or replace
PROCEDURE TEST_PROC1 (p_cursor IN OUT SYS_REFCURSOR)
AS
BEGIN
OPEN p_cursor FOR
SELECT *
FROM test_table1;
END;
-- TEST_PROC2 --
create or replace
procedure TEST_PROC2( rc in out sys_refcursor ) is
FETCH_LIMIT constant integer := 100;
type TFetchBuffer is table of test_table2%RowType;
buffer TFetchBuffer;
begin
loop
fetch rc bulk collect into buffer limit FETCH_LIMIT;
forall i in 1..buffer.Count
insert into test_table2(
c1, c2
) values(
buffer(i).c1, buffer(i).c2
exit when rc%NotFound;
end loop;
end;
Is there a way to call a PL/SQL Stored Procedure that returns a REFCURSOR using ODI Procedure?
Thanks,
CathyThanks for the reply actdi.
The procedure TEST_PROC1 is just a sample procedure. The requirement is that I need to call a stored procedure that returns a cursor using ODI and fetch the data and insert into a table, which in this case is test_table2.
I was able to execute a simple SQL procedure (without cursor) using ODI procedure. But when i try to execute the SQL procedure with cursor in ODI, I encountered error.
Do you have any idea how to do this? -
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.
Pradipto1) 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 -
How to call a stored procedure which has out parameter value
my code is
public Connection createConnection() {
Connection conn = null;
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(URL,USER,PASS);
} catch (ClassNotFoundException cnfe) {
System.err.print("Class not found");
} catch (SQLException sqle) {
System.err.print("SQLException");
return conn;
public static void main(String args[]){
StroedProcedure stp = new StroedProcedure();
Connection con = stp.createConnection();
try {
CallableStatement stproc_stmt = con.prepareCall("{call Account_Summary(?,?,?,?,?,?,?,?)}");
stproc_stmt.setString(1, "123456");
stproc_stmt.setDate(2, null);
stproc_stmt.setString(3, null);
stproc_stmt.setString(4, null);
stproc_stmt.setString(5, null);
stproc_stmt.setString(6, null);
stproc_stmt.setDate(7, null);
stproc_stmt.setDate(8, null);
stproc_stmt.registerOutParameter(1,Types.CHAR);
stproc_stmt.registerOutParameter(2,Types.DATE);
stproc_stmt.registerOutParameter(3,Types.CHAR);
stproc_stmt.registerOutParameter(4,Types.CHAR);
stproc_stmt.registerOutParameter(5,Types.CHAR);
stproc_stmt.registerOutParameter(6,Types.CHAR);
stproc_stmt.registerOutParameter(7,Types.DATE);
stproc_stmt.registerOutParameter(8,Types.DATE);
stproc_stmt.execute();
System.out.println("test "+stproc_stmt.getString(1));
ResultSet rs = stproc_stmt.executeQuery();
while (rs.next()){
System.out.println("result "+rs.getString("ACCPK"));
} catch (SQLException e) {
e.printStackTrace();
}And the stored procedure is
CREATE OR REPLACE
procedure Account_Summary (accpk in out char, incdt out date, bcur out char, bmark out char, tarTE out char, numHold out char, stDt out date, AsDt out date)
is
begin
select account_pk, inception_date, base_currency, benchmark into accpk, incdt, bcur, bmark
from account a
where a.Account_pk=accpk;
select target_te, number_holdings, start_date, as_date into tarTE, numHold, StDt, AsDt
from acc_summary asum
where asum.account_pk=accpk;
end Account_Summary;but it gives a exception ORA-01460: unimplemented or unreasonable conversion requested
ORA-06512: at "REPRO.ACCOUNT_SUMMARY", line 4
ORA-06512: at line 1
i want to execute a stored procedure which has in , inout or out parameter
but it can not work========================
In some contects varchar2 variable limit is 32512 characters... October 16, 2003
Reviewer: Piotr Jarmuz from Poznan, Poland
Interesting to note is the fact that varchar2 variables as parameters to stored
procedures (in in/out out) may be "only" 32512 bytes long.
I've checked this in Java and Perl. 32512 is the last value that works, for any
bigger it throws:
Exception in thread "main" java.sql.SQLException: ORA-01460: unimplemented or
unreasonable conversion requested
But in PL/SQL as you said 32767
Regards,
Piotr
=================================
This i got it from ask tom, well it make sense.... try checking your input with small numbers and strings
Have fun -
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 -
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 -
Can I call a stored procedure which has DMLs from a function ??
Hello all,
Here is my req. I Want to use a function which in turn executes a procedure to populate a table. This procedure inserts data into a table .
How can I make it work.?
thanks,
DnakkaHi,
Here is an example procedure and a function.
The procedure:
CREATE OR REPLACE PROCEDURE proc1 AS
BEGIN
INSERT INTO tab1 VALUES(1, 'some string value');
COMMIT;
END;
The function which calls proc1:
CREATE OR REPLACE FUNCTION func1 RETURN VARCHAR2 AS
BEGIN
proc1;
RETURN 'done';
END;
Hope that helps.
Savitha. -
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 -
while Using Tomcat it will throw out of memory for 50000 records and the weblogic throws Out of memory error for 2 lakshs records, and the Ibm server throws
Out of memory error for 1 laksh recordswhile Using Tomcat it will throw out of memory for 50000 records and the weblogic throws Out of memory error for 2 lakshs records, and the Ibm server throws
Out of memory error for 1 laksh records -
Another "How to call a stored procedure" question
Hi,
I want to call a stored procedure which returns 4 VARCHAR as a output
parameter, and use 2 VARCHAR as a input parameter. How can I do
that ?
the signature of the SP is like this
dec(
in_a IN VARCHAR2,
in_b IN VARCHAR2,
out_c OUT VARCHAR2,
out_d OUT VARCHAR2,
out_e OUT VARCHAR2,
out_f OUT VARCHAR2,
Thank YouThere is an example in your wls installation, did you check that? it shows
you how to access cursor as a resultset.
<wls install dir>\samples\examples\jdbc\mssqlserver4\complexproc.java
hth
sree
"Saman" <[email protected]> wrote in message
news:[email protected]..
>
Hi,
I am using weblogic JDriver for MSSQLServer 7.0. I want to call a
stored procedure which returns a CURSOR as a output parameter. How can Ido
that ?
the signature of the SP is like this
Myprocedure (@c CURSOR VARYING OUTPUT)
Thank You,
Saman -
How to call a stored procedure question
Hi,
I am using weblogic JDriver for MSSQLServer 7.0. I want to call a
stored procedure which returns a CURSOR as a output parameter. How can I do
that ?
the signature of the SP is like this
Myprocedure (@c CURSOR VARYING OUTPUT)
Thank You,
SamanThere is an example in your wls installation, did you check that? it shows
you how to access cursor as a resultset.
<wls install dir>\samples\examples\jdbc\mssqlserver4\complexproc.java
hth
sree
"Saman" <[email protected]> wrote in message
news:[email protected]..
>
Hi,
I am using weblogic JDriver for MSSQLServer 7.0. I want to call a
stored procedure which returns a CURSOR as a output parameter. How can Ido
that ?
the signature of the SP is like this
Myprocedure (@c CURSOR VARYING OUTPUT)
Thank You,
Saman -
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...
Maybe you are looking for
-
Hi All, I have a problem with JDialogs in my standalone application. This app pops-up multiple JDialogs, say a stack of JDialogs. I have a standalone application which runs as a JFrame, call it JFrame1, which is working fine. JFrame1 pops-up a JDialo
-
E-mail synch, read/unread, how can I set this up?
I'd like to refer to an older question I found which hadn't been answered properly. https://discussions.apple.com/thread/3557308?start=0&tstart=0 Quite simply, the question is; I have my work e-mail, my Hotmail and my Gmail all set-up on my iPhone 4S
-
Creating RAID doesn't work using Disk Utility
When I try to create a RAID in Disk Utility, the pair gets corrupted and I get an error - "couldn't find RAID". What is missing? Is there something else to install? I'm trying this on an external USB drive.
-
Mail 2.0.7 crashing on sending mail
Hi all. I have three accounts in Mail; one IMAP, two pop. Every time I send a message Mail crashes. The messages go, but Mail gives me the beachball and hangs. I have MailTags and Mail ActOn installed, along with Growl, but they seem to be behaving c
-
when my zen neeon play some mp3 file it get's hang, i scanned with Norman antivirus and it hang when scanned the same file, when i deleted it hang again(connected PC).but it's ok playing the other mp3 file,help me... can i formated the mp3 player fro