Calling stored procedure with struct and boolean parameter
Hi all,
I am trying to write an EJB method using eclipselink that has to call a stored procedure which has the following parameters:
- an object type (in/out)
- a date (in)
- another date (in)
- a boolean (optional, in)
- a number (out)
- a string (out)
When using StoredProcedureCall, I succeed in passing the dates and the object type (as a STRUCT) into the procedure and read out the output variables. I can also do this using NamedStoredProcedureCall and only map the number and string in a result class. Drawbacks of NamedStoredProcedureCall:
- I cannot map the object type that comes back out (working example, anyone?)
- I cannot specify the boolean input variable
The problem is when I want to specify the boolean. In StoredProcedureCall, this is not possible since this only accepts native JDBC parameters. So I tried our PLSQLStoredProcedureCall.
Here, I can specify all in/out parameters except the object type! No matter what I try, I seem to end up with ORA-3115 - unsupported network datatype or representation. Does anyone have a working example on how to use this?
Regards,
Jeroen van Veldhuizen
REDORA B.V.
The problem is not that I want to pass in a boolean. When I try to use PLSQLStoredProcedure, I do not succeed in passing in/out an object type (or STRUCT). It looks like the code has been made to access PLSQL record and table types by wrapping them in an object type, but it seems not to be possible to to use an object type directly.
To start with: when you create a STRUCT parameter, the generated sql code is this:
DECLARE
l_param_in STRUCT := :1;and since struct is not a datatype, this fails.
Jeroen
Similar Messages
-
Java call stored procedure with nested table type parameter?
Hi experts!
I need to call stored procedure that contains nested table type parameter, but I don't know how to handle it.
The following is my pl/sql code:
create or replace package test_package as
type row_abc is record(
col1 varchar2(16),
col2 varchar2(16),
col3 varchar2(16 )
type matrix_abc is table of row_abc index by binary_integer;
PROCEDURE test_matrix(p_arg1 IN VARCHAR2,
p_arg2 IN VARCHAR2,
p_arg3 IN VARCHAR2,
p_out OUT matrix_abc
END test_package;
create or replace package body test_package as
PROCEDURE test_matrix(p_arg1 IN VARCHAR2,
p_arg2 IN VARCHAR2,
p_arg3 IN VARCHAR2,
p_out OUT matrix_abc
IS
v_sn NUMBER(8):=0 ;
BEGIN
LOOP
EXIT WHEN v_sn>5 ;
v_sn := v_sn + 1;
p_out(v_sn).col1 := 'col1_'||to_char(v_sn)|| p_arg1 ;
p_out(v_sn).col2 := 'col2_'||to_char(v_sn)||p_arg2 ;
p_out(v_sn).col3 := 'col3_'||to_char(v_sn)||p_arg3 ;
END LOOP ;
END ;
END test_package ;
My java code is following, it doesn't work:
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection
("jdbc:oracle:thin:@10.16.102.176:1540:dev", "scott", "tiger");
con.setAutoCommit(false);
CallableStatement ps = null;
String sql = " begin test_package.test_matrix( ?, ? , ? , ? ); end ; ";
ps = con.prepareCall(sql);
ps.setString(1,"p1");
ps.setString(2,"p2");
ps.setString(3,"p3");
ps.registerOutParameter(4,OracleTypes.CURSOR);
ps.execute();
ResultSet rset = (ResultSet) ps.getObject(1);
error message :
PLS-00306: wrong number or types of arguments in call to 'TEST_MATRIX'
ORA-06550: line 1, column 8:
PL/SQL: Statement ignored
Regards
LouisLouis,
If I'm not mistaken, record types are not allowed. However, you can use object types instead. However, they must be database types. In other words, something like:
create or replace type ROW_ABC as object (
col1 varchar2(16),
col2 varchar2(16),
col3 varchar2(16 )
create or replace type MATRIX_ABC as table of ROW_ABC
/Then you can use the "ARRAY" and "STRUCT" (SQL) types in your java code. If I remember correctly, I recently answered a similar question either in this forum, or at JavaRanch -- but I'm too lazy to look for it now. Do a search for the terms "ARRAY" and "STRUCT".
For your information, there are also code samples of how to do this on the OTN Web site.
Good Luck,
Avi. -
Calling Stored Procedure with a DATE input parameter
Hi. A question about Date input parameters when calling a stored procedure...
I have a procedure that takes a DATE parameter as input. I would like that DATE value to include a Time element.
My Application Module method takes an input parameter as java.util.Date (myParamDate) - which will preserve a time element(?).
However when I create the CallableStatement, I'm trying to set the parameter using setDate like this (for param 5):
st = getDBTransaction().createCallableStatement("begin cs_my_pck.request_values(?,?,?,?,?,?,?,?); end;", 0);
Connection myConn = st.getConnection();
ArrayDescriptor myArrDesc = ArrayDescriptor.createDescriptor("CS_FIELD_TABT", myConn);
Array sqlParamNameArray = new oracle.sql.ARRAY(myArrDesc, myConn, paramNames.toArray());
Array sqlParamValueArray = new oracle.sql.ARRAY(myArrDesc, myConn, paramValues.toArray());
Array sqlFilterNameArray = new oracle.sql.ARRAY(myArrDesc,myConn,filterNames.toArray());
st.setString(1, repType);
st.setObject(2, sqlParamNameArray);
st.setObject(3,sqlParamValueArray);
st.setObject(4,sqlFilterNameArray);
java.sql.Date myRepDate = new java.sql.Date(myParamDate.getTime());
st.setDate(5,myRepDate);
System.out.println("Report Date = " + myRepDate.toString());
st.setString(6,repUser);
st.setString(7,repAttach);
// set out param
st.registerOutParameter(8, Types.NUMERIC);
st.execute();I understand java.sql.Date does NOT include a Time element. But setDate() accepts only a java.sql.Date so my procedure parameter ends up with a zero time element.
How do I call this procedure retaining the Time element?
Thanks.It includes time element, if you want more precision go with timestamp.
http://docs.oracle.com/javase/6/docs/api/java/sql/Date.html -
Stored procedure with IN and OUT parameter
HI all,
here is code example
declare
in_dt date := '1-feb-2010' ;
col1 ...;
col2 ...;
col3 ...;
begin
select e.*
into col1,
col2,
col3
from table_xyz e
where e.start_dt = in_dt;
end;
How do i convert the above code into stored procedure by accepting "in_dt" as IN parameter and getting the result set displayed (output) through OUT parameter say "cur_out" (OUT paramter)
Thank you so much !!! I really appriciate it !!i ran my procedure which is very similar syndra posted
create or replace procedure foo(p_dt in date, cv out sys_refcursor) as
begin
open cv for
select e.*
from table_xyz e
where start_dt = p_dt;
end;
/Here is how is executed
DECLARE
P_DT DATE;
CV SYS_REFCURSOR;
BEGIN
P_DT := '10-oct-2005';
-- CV := NULL; Modify the code to initialize this parameter
scott.foo ( P_DT, CV );
COMMIT;
END;
-- i get PL/SQL procedure successfully complted , But i dont see the result set Or output
- How do i see the output when i m using refcursor ?? i tried using print , but nothing didnt work
- Any idea ??
Thank you!!
Edited by: user642297 on Jun 24, 2010 1:35 PM -
Calling Stored Procedure with OraClob as parameter IN
I am using Visual C++ and using oo4o the ole way
I am try to call stored procedure that have Clob as parameter in
it seems the the OraParameters Add method don't have the ability since it can only receive variantt.
How do I do it
Thanks
Yoavfyi
Related to the solution/workaround posted by Luc.
see "Do Oracle's JDBC drivers support PL/SQL tables/result sets/records/booleans? "
at http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#34_05
regards
Jan Vervecken -
Calling Stored Procedure with in Stored Procedure
I have one stored procedure A, I want to call Stored procedure A from Stored Procedure B and want to give input parameter to Stored Procedure A within Stored Procedure B using while loop.
i.e I have one stored procedure A which uses Telephone number as input parameter and pull out data
I want to create one more stored procedure B which will call stored procedure A internally and give telephone number one by one using while loop and push the result in Table C.>
I have one stored procedure A, I want to call Stored procedure A from Stored Procedure B and want to give input parameter to Stored Procedure A within Stored Procedure B using while loop.
i.e I have one stored procedure A which uses Telephone number as input parameter and pull out data
I want to create one more stored procedure B which will call stored procedure A internally and give telephone number one by one using while loop and push the result in Table C.
>
Doesn't sound a good idea in terms of performance or design. OK, what's your query?
The concept is:
create or replace procedure Proc_A (p_phone varchar2)
is
Begin
Insert into Tablec (col1, col2, col3, phone) values (val1, val2, val3, p_phone);
Exception
When no_data_found then
do what...
End;
Create or Replace Procedure Proc_B as
Begin
For i in (select phone_no from customer)
Loop
Proc_A(i.phone_no);
End Loop;
End;
/Once again, I have to say, it's a bad idea. You may well do it within a single procedure or even a single SQL. Tell us your exact requirements and we'll be able to help you
Edited by: user12035575 on Sep 5, 2011 8:26 PM -
How to call stored procedure with multiple parameters in an HTML expression
Hi, Guys:
Can you show me an example to call stored procedure with multiple parameters in an HTML expression? I need to rewrite a procedure to display multiple pictures of one person stored in database by clicking button.
The orginal HTML expression is :
<img src="#OWNER#.dl_sor_image?p_offender_id=#OFFENDER_ID#" width="75" height="75">which calls a procedure as:
procedure dl_sor_image (p_offender_id IN NUMBER)now I rewrite it as:
PROCEDURE Sor_Display_Current_Image(p_n_Offender_id IN NUMBER, p_n_image_Count in number)could anyone tell me the format for the html expression to pass multiple parameters?
Thanks a lot.
SamHi:
Thanks for your help! Your question is what I am trying hard now. Current procedure can only display one picture per person, however, I am supposed to write a new procedure which displays multiple pictures for one person. When user click a button on report, APEX should call this procedure and returns next picture of the same person. The table is SOR_image. However, I rewrite the HTML expression as follows to test to display the second image.
<img src="#OWNER#.Sor_Display_Current_Image?p_n_Offender_id=#OFFENDER_ID#&p_n_image_Count=2" width="75" height="75"> The procedure code is complied OK as follows:
create or replace
PROCEDURE Sor_Display_Current_Image(p_n_Offender_id IN NUMBER, p_n_image_Count in number) AS
v_mime_type VARCHAR2(48);
v_length NUMBER;
v_name VARCHAR2(2000);
v_image BLOB;
v_counter number:=0;
cursor cur_All_Images_of_Offender is
SELECT 'IMAGE/JPEG' mime_type, dbms_lob.getlength(image) as image_length, image
FROM sor_image
WHERE offender_id = p_n_Offender_id;
rec_Image_of_Offender cur_All_Images_of_Offender%ROWTYPE;
BEGIN
open cur_All_Images_of_Offender;
loop
fetch cur_All_Images_of_Offender into rec_Image_of_Offender;
v_counter:=v_counter+1;
if (v_counter=p_n_image_Count) then
owa_util.mime_header(nvl(rec_Image_of_Offender.mime_type, 'application/octet'), FALSE);
htp.p('Content-length: '||rec_Image_of_Offender.image_length);
owa_util.http_header_close;
wpg_docload.download_file (rec_Image_of_Offender.image);
end if;
exit when ((cur_All_Images_of_Offender%NOTFOUND) or (v_counter>=p_n_image_Count));
end loop;
close cur_All_Images_of_Offender;
END Sor_Display_Current_Image; The procedure just open a cursor to fetch the images belong to the same person, and use wpg_docload.download_file function to display the image specified. But it never works. It is strange because even I use exactly same code as before but change procedure name, Oracle APEX cannot display an image. Is this due to anything such as make file configuration in APEX?
Thanks
Sam -
Calling Stored Procedure with TestStand to SQL 2000
When I run the Stored Procedure in the query analyzer it returns the recordset fine. I am not specifying any parameters. I am Using TestStand 2.01 and SQL Server 2000. I am using the OPEN SQL STATEMENT step to call the SP. When I run the SP in TestStand I get no data returned. If I run the SQL statment in TestStand I get the data that I am requesting. Does TestStand not support stored procedures.
Hi,
The instructions that I posted were for TestStand 3.0. In version 3.0 you can call stored procedures with input/output paramateres and to support this functionality the data operation step support several new modes.
TestStand 2.0.1 does not support parameters on stored procedures, but it does support calling stored procedures that do not take parameters. To be able to access the data back from the database you need to set the cursor location (in the Advanced tab of the Open SQL Statement step) to Client (http://digital.ni.com/public.nsf/websearch/0EF68BF97AB1A61F86256B8E007D70C0?OpenDocument).
By changing the cursor to Client I was able to succesfully call a stored procedure from TestStand 2.0.1 and to read back the recordse
t return by the database. Please let me know if you are still experiencing dificulties.
Best regards,
Alejandro del Castillo
National Instruments -
Can Stored procedure with IN and OUT Paramter can be used in JDBC LOOKUP?
can Stored procedure with IN and OUT Paramter can be used in JDBC LOOKUP?
Checking online help, I do not see any possibility.
"Queries a data base by the given SQL statement."
http://help.sap.com/javadocs/pi/pi711sp03/com/sap/aii/mapping/lookup/DataBaseAccessor.html
-> execute -
Please help - Can not use stored procedure with CTE and temp table in OLEDB source
Hi,
I am going to create a simple package. It has OLEDB source , a Derived transformation and a OLEDB Target database.
Now, for the OLEDB Source, I have a stored procedure with CTE and there are many temp tables inside it. When I give like EXEC <Procedure name> then I am getting the error like ''The metadata could not be determined because statement with CTE.......uses
temp table.
Please help me how to resolve this ?you write to the temp tables that get created at the time the procedure runs I guess
Instead do it a staged approach, run Execute SQL to populate them, then pull the data using the source.
You must set retainsameconnection to TRUE to be able to use the temp tables
Arthur My Blog -
Calling Stored Procedure with Boolean Output Parameter
Hi all,
I'm running into an issue (or is it a BUG) when calling a Database Stored Procedure that has an output parameter of the boolean type.
procedure proc(p_text in varchar2, p_result out boolean)
is
.....I use the following 'standard' code (developer guide 36-19 36-20) to invoke this procedure from my application module.
try {
// 1. Define the PL/SQL block for the statement to invoke
String stmt = "begin proc(?,?); end;";
// 2. Create the CallableStatement for the PL/SQL block
st = getDBTransaction().createCallableStatement(stmt, 0);
// 3. Register the positions and types of the OUT parameters
st.registerOutParameter(2, Types.BOOLEAN);
// 4. Set the bind values of the IN parameters
st.setObject(1, "Some text");
// 5. Execute the statement
st.executeUpdate();
..............................As soon as 'st.registerOutParameter(2, Types.BOOLEAN);' is invoked I run into a SQLexception. "Invalid ColumnType: 16". Obviously 16 refers to Types.BOOLEAN.
[edit by Luc]
SOLUTION / WORKAROUND
To answer my own question.
It looks like BOOLEAN output parameters are not supported. I just Read "Appendix D Troubleshooting" of the Oracle® Database JDBC Developer's Guide and Reference 10g Release 2 (10.2).
I found that JDBC drivers do not support the passing of BOOLEAN parameters to PL/SQL stored procedures. If a PL/SQL procedure contains BOOLEAN values, you can work around the restriction by wrapping the PL/SQL procedure with a second PL/SQL procedure that accepts the argument as an INT and passes it to the first stored procedure. When the second procedure is called, the server performs the conversion from INT to BOOLEAN.
I'm not very happy with this but I guess I've no choice.
Regards Luc
Edited by: lucbors on Nov 30, 2010 10:37 AMfyi
Related to the solution/workaround posted by Luc.
see "Do Oracle's JDBC drivers support PL/SQL tables/result sets/records/booleans? "
at http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#34_05
regards
Jan Vervecken -
Call stored procedure with OUT parameter
Hello,
I have created a short-lived process. Within this process I am using the "FOUNDATION > JDBC > Call Stored Procedure" operation to call an Oracle procedure. This procedure has 3 parameters, 2 IN and 1 OUT parameter.
The procedure is being executed correctly. Both IN parameters receive the correct values but I am unable to get the OUT parameter's value in my process.
Rewriting the procedure as a function gives me an ORA-01460 since one of the parameters contains XML (>32K) so this is not option...
Has someone been able to call a stored procedure with an OUT parameter?
Regards,
NicoObject is Foundation, Execute Script
This is for a query, you can change to a stored procedure call. Pull the value back in the Java code then put into the process variable.
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.*;
PreparedStatement stmt = null;
Connection conn = null;
ResultSet rs = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:IDP_DS");
conn = ds.getConnection();
stmt = conn.prepareStatement("select FUBAR from TB_PT_FUBAR where PROCESS_INSTANCE_ID=?");
stmt.setLong(1, patExecContext.getProcessDataLongValue("/process_data/@inputID"));
rs = stmt.executeQuery();
rs.next();
patExecContext.setProcessDataStringValue("/process_data/outData", rs.getString(1));
} finally {
try {
rs.close();
} catch (Exception rse) {}
try {
stmt.close();
} catch (Exception sse) {}
try {
conn.close();
} catch (Exception cse) {} -
Calling Stored Procedure with CLOB parameter
Hi,
i have one procedure with IN parameter CLOB which is taking xml file and stored in one table column and this table column datatype is also CLOB. And this procedure called by .Net program but problem is when the file will come more than 32KB calling procedure failed. But as i know CLOB can stored up to 4GB data.
Is that Limitation of oracle or .Net version
please let me know the solution for that,
Create Procedure Insert_File(P_XMLFILE IN CLOB)
as
begin
insert into instances
values(p_xmlfile);
commit;
end;
regards,
MadanHi Thanks for your reply,
Actually this procedure called by .net program and the XML file has passed in that parameter which come from some FTP(its inbound) and this files we are storing into above mentioned table.
Error has come while calling stored procedure Through .net
Error Details:
Error calling stored procedure. 0 retry attemps has failed. Error: System.Exception: Error while calling stored procedure on Oracle: INSERT_FILE: System.Data.OracleClient.OracleException: ORA-01460: unimplemented or unreasonable conversion requested -
Calling a stored procedure with RAW and SYS_REFCURSOR
How do you call a stored procedure with the following input and output parameters?
create or replace PROCEDURE test
v_col1 IN NUMBER DEFAULT NULL ,
v_col2 IN VARCHAR2 DEFAULT NULL ,
v_col3 IN RAW DEFAULT NULL ,
v_vol4 IN DATE DEFAULT NULL,
cv_1 IN OUT SYS_REFCURSOR
OPEN cv_1 FOR
SELECT
lv_tmp1 aaaa ,
lv_tmp2 bbbb,
lv_tmp3 cccc
FROM DUAL ;
END;
Edited by: 925963 on Apr 6, 2012 10:50 AMDid you try just declaring the vars?
untested
declare
myCur SYS_REFCURSOR;
myRaw RAW(4);
BEGIN
test (0, 0, myRaw, sysdate, myCur);
END; -
Problem to call stored procedure with several IN pars and single REF Cursor
Hi,
Oracle 9.2.0.1
Ole DB Provider I've got with ODP 9.2.0.4
First I try to call packaged procedure with single
REF CURSOR - it works fine(PROCEDURE getDep(dep OUT DEPART.refcur) IS ...).
When I try to call procedure with additional IN parameter, I get an error ORA-01008: not all variables bound.
Packaged procedure: PROCEDURE getDep(dep OUT DEPART.refcur, i1 IN number) IS .... and so on.
Try to call from C#:
cmd.CommandText = "{call depart.getDep(?)}";
OleDbParameter par0 = cmd.CreateParameter();
par0.Value = some value;
par0.DbType = DbType.Int16;
par0.OleDbType = OleDbType.Integer;
par0.Direction = ParameterDirection.Input;
OleDbDataAdapter da = new OleDbDataAdapter(cmd.CommandText,con);
DataSet ds = new DataSet();
da.Fill(ds);
Connection string:
"Provider=OraOLEDB.Oracle;User Id=scott;Password=tiger;Data Source=ora92;OLEDB.NET=true;PLSQLRSet=true"
Please, HELP !
Thanks in advance,
VyacheslavHi,
Are you using OLEDB.NET driver (System.Data.Oledb) or ODP.NET driver (Oracle.DataAccess)?
If you are using ODP.NET, remember that you need to bind the refcursor output variable also (besides the numbder)
Arnold
Maybe you are looking for
-
I was able to use Yahoo toolbar with the older version of Firefox and now I am not able to, why? Is there a way to allow it?
-
Will I lose my iTunes Matched song copies in the Cloud if I do not renew my iTunes Match subscription ?
-
I trying to create a strip chart for 16 channels that will require displaying 10-20 minutes of data.It also starts a separate vi to set gains and offsets while displaying the data. Using AI Read.vi uses 100% of the CPU so the second vi does not run.
-
Disk Utility not recognizing Time Capsule Disk?
Hi I'm receiving the following error message from Time Machine: "The problem may be temporary. Try again later to back up. If the problem persists, use Disk Utility to repair your backup disk." I am able to access the Time Capsule's hard drive via Fi
-
Safari not responding instantly on startup.
Has anyone else had this issue where Safari stops responding immediately after you start it up? When I click it, the icon bounces up and down like it normally does, but as soon as it stops, that little spinning color wheel shows up, and from that poi