Procedure with Array IN parameter
Hi,
I have requirement to create a procedure that accepts an Array as IN parameter , Query a table using this array and return the result as refcursor .
please suggest the best approach . i tried to get it as below but not working .
CREATE OR REPLACE TYPE ARR_ID AS TABLE OF VARCHAR2(20);
CREATE OR REPLACE
PROCEDURE TEST_ARRAY
(P_ARR_ID IN ARR_ID,
P_CUR_OUT OUT SYS_REFCURSOR)
AS
BEGIN
OPEN P_CUR_OUT FOR
SELECT * FROM EMPLOYEE WHERE EMP_ID IN (SELECT * FROM TABLE(P_ARR_ID ));
END;
/
I am not questioning design, but there is nothing wrong with your SP. For example:
SQL> CREATE OR REPLACE TYPE ARR_ID AS TABLE OF VARCHAR2(20);
2 /
Type created.
SQL> CREATE OR REPLACE
2 PROCEDURE TEST_ARRAY
3 (P_ARR_ID IN ARR_ID,
4 P_CUR_OUT OUT SYS_REFCURSOR)
5 AS
6 BEGIN
7 OPEN P_CUR_OUT FOR
8 SELECT * FROM HR.EMPLOYEES WHERE EMPLOYEE_ID IN (SELECT * FROM TABLE(P_ARR_ID ));
9 END;
10 /
Procedure created.
SQL> VARIABLE refcur REFCURSOR
SQL> EXEC TEST_ARRAY(ARR_ID(100,110),:refcur);
PL/SQL procedure successfully completed.
SQL> PRINT refcur
EMPLOYEE_ID FIRST_NAME LAST_NAME
EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY
COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
100 Steven King
SKING 515.123.4567 17-JUN-03 AD_PRES 24000
90
110 John Chen
JCHEN 515.124.4269 28-SEP-05 FI_ACCOUNT 8200
108 100
EMPLOYEE_ID FIRST_NAME LAST_NAME
EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY
COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
SQL> SY.
Similar Messages
-
How to change stored procedure with Table Valued Parameter
I am not sure how to change the normal stored procedure with Table Value Parameter.Do I have to create a separate Table or do I have to create a datatype. Can you please help me with this
ALTER PROCEDURE [dbo].[uspInsertorUpdateINF]
@dp_id char(32),
@dv_id char(32),
@em_number char(12),
@email varchar(50),
@emergency_relation char(32),
@option1 char(16),
@status char(20),
@em_id char(35),
@em_title varchar(64),
@date_hired datetime
AS
BEGIN
SET NOCOUNT ON;
MERGE [dbo].[em] AS [Targ]
USING (VALUES (@dp_id, @dv_id , @em_number, @email, @emergency_relation, @option1, @status, @em_id, @em_title, @date_hired))
AS [Sourc] (dp_id, dv_id, em_number, email, emergency_relation, option1, status, em_id, em_title, date_hired)
ON [Targ].em_id = [Sourc].em_id
WHEN MATCHED THEN
UPDATE
SET dp_id = [Sourc].dp_id,
dv_id = [Sourc].dv_id,
em_number = [Sourc].em_number,
email = [Sourc].email,
emergency_relation = [Sourc].emergency_relation,
option1 = [Sourc].option1,
status = [Sourc].status,
em_title = [Sourc].em_title,
date_hired = [Sourc].date_hired
WHEN NOT MATCHED BY TARGET THEN
INSERT (dp_id, dv_id, em_number, email, emergency_relation, option1, status, em_id, em_title,date_hired)
VALUES ([Sourc].dp_id, [Sourc].dv_id, [Sourc].em_number, [Sourc].email, [Sourc].emergency_relation, [Sourc].option1, [Sourc].status, [Sourc].em_id, [Sourc].em_title, [Sourc].date_hired);
END;It's not clear how you would change the procedure. But assuming that you want to replace the existing scalar parameters with tabular input, this is how you would do it. You first create a table type:
CREATE TYPE Insertor_type AS TABLE
(dp_id char(32),
dv_id char(32),
em_number char(12),
email varchar(50),
emergency_relation char(32),
option1 char(16),
status char(20),
em_id char(35),
em_title varchar(64),
date_hired datetime)
Then you change the procedure header:
ALTER PROCEDURE [dbo].[uspInsertorUpdateINF] @tvp Insertor_type READONLY AS
And finally you change the USING clause:
USING (SELECT dp_id, dv_id , em_number, email, emergency_relation, option1, status, em_id, em_title, date_hired
FROM @tvp) AS [Sourc] ON [Targ].em_id = [Sourc].em_id
The rest is fine as it is.
Erland Sommarskog, SQL Server MVP, [email protected] -
Creating a job for a procedure with an input parameter
Hi,
I want to create a job for a procedure ( sp_proc ) with a input parameter.
The input parameter is a date value.
As per the syntax for dbms_job.submit procedure;
dbms_job.submit (
job IN BINARY_INTEGER,
what IN VARCHAR2,
next_date IN DATE,
interval IN VARCHAR2 DEFAULT 'NULL',
no_parse IN BOOLEAN DEFAULT FALSE);
How should the procedure be declared in the 'what' parameter of the dbms_job.submit procedure ?
Please guide.
Thanks.Hi,
You are wright, I have found this thread [DBMS_JOB -- how to pass parameters to the job|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:351033761220].
Regards, -
Using stored procedures with a timestamp parameter with Delphi and ADO
Dear Oracle experts,
I have a problem concerning using a stored procedure with Delphi.
I try to use a stored procedure which hast two input parameters ( a integer and a timestamp).
The timestamp parameter is my problem since I would like to use the "to_timestamp"
Oracle-function to create the timestamp parameter to be inserted into my procedure.
If I insert the to_timestamp statement as a adodatetime I have to perform the conversion to the oracle timestamp in my application.
If I want to use the to_timestamp statement I have to use the ftstring datatype but in that case I get an error because I use a string as input for my procedure were it awaits a timestamp.
So the problem seems to be that the function call "to_timestamp" is not interpreted if it is transferred through my ADO component.
Do you know how to use a procedure with Delphi (ADO) with a function as input parameter ?
Best regards,
Daniel Wetzler
P.S. :
This is the Delphi code to use my Procedure.
FactsTempDS:=TADODataset.Create(nil);
Sproc1 := TAdoStoredProc.Create(nil);
Sproc1.Connection := TDBConnection(strlistConnectionstrings.objects[iConnectionIndex]).Connection;
Sproc1.ProcedureName := 'ECSPACKAGE.PROCFINDINITIALSWITCHSTATE';
Sproc1.Parameters.CreateParameter ('SwitchID',ftInteger,pdinput,0,0);
//Sproc1.Parameters.CreateParameter ('StartTime',ftdatetime,pdinput,50,0);
Sproc1.Parameters.CreateParameter ('StartTime',ftString,pdinput,50,0);
Sproc1.Parameters.Findparam('SwitchID').value:=SwitchID;
Sproc1.Parameters.FindParam('StartTime').Value:= 'to_timestamp(''2005/12/30 19:36:21'', ''YYYY/MM/DD HH:MI:SS'')';
Sproc1.CursorType := ctKeyset;
Sproc1.ExecuteOptions:=[];
Sproc1.Open;
Sproc1.Connection := nil;
FactsTempDS.Recordset:= sproc1.Recordset;
if FactsTempDS.RecordCount=0
then raise Exception.Create('No line switch variable found for switch '+IntToStr(SwitchID)+' before starttime. Check BDE dump filter.')I have my entity manager setup in a singleton.
I'm finding it's costly to generate the emf, but if I don't close the em (enitity manager) and emf (entity manager factory) my open cursor count climbs until I exceed the max number of open cursors on the database (11g RAC)
I'm committing the connection, and uow, and closing the em at the end of each call.
But until I close the emf, the open cursors aren't released.
TransactionhistoryPkg tranPkg = new TransactionhistoryPkg(conn); //Class created over database package via JPublisher
tranPkg.transactionhistoryInsSp(insertTrans.getCardId()); // executes db package
tranPkg.closeConnection();
conn.commit();
uow.commit();
uow.getAccessor().decrementCallCount();
em.close();
Am I missing something really obvious here??
btw - I found this link helpful in troubleshooting the max cursors issue: https://support.bea.com/application_content/product_portlets/support_patterns/wls/InvestigatingORA-1000MaximumOpenCursorsExceededPattern.html -
Calling a stored procedure with an XmlType parameter.
I am attempting to execute a stored function via a named query. The stored procedure has a single parameter of Oracles 'xmltype', and also returns an xmltype. For example this dummy function
function testXML(xml_in xmltype) return xmltype is
begin
return xml_in;
end;
Is it possible to make the named query call with an oracle.xdb.XMLType or oracle.xdb.dom.XDBDocument? I cannot find any examples of this being done. I also want the returning xmltype to be converted into a Java class.
Another question - will I need to work with a conversion manager to achieve this?Local Exception Stack:
Exception [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)): oracle.toplink.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Invalid column typeError Code: 17004
Call:BEGIN ? := TestPackage.testXML(XML_IN=>?); END;
bind => [=> RESULT, oracle.xml.parser.v2.XMLDocument@1a64732 => XML_IN]
Query:DataReadQuery()
at oracle.toplink.exceptions.DatabaseException.sqlException(DatabaseException.java:290)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:570)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:442)
at oracle.toplink.threetier.ServerSession.executeCall(ServerSession.java:453)
at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:117)
at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:103)
at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:174)
at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeSelect(DatasourceCallQueryMechanism.java:156)
at oracle.toplink.queryframework.DataReadQuery.executeNonCursor(DataReadQuery.java:118)
at oracle.toplink.queryframework.DataReadQuery.executeDatabaseQuery(DataReadQuery.java:110)
at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:603) -
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 -
Calling PLSQL Procedure with CLOB input parameter from JDBC
Hi..
I've got a PLSQL procedure with a CLOB object as input parameter:
function saveProject (xmldoc CLOB) RETURN varchar IS
I want to call that procedure from my JDBC Application as...
String data = "..."
CallableStatement proc = conn.prepareCall
("begin ? := saveProject (?); end;");
neither
proc.setCharacterStream(2, new StringReader(data, data.length());
nor
proc.setString(2, data);
will work.
The Application throws java.sql.Exception: ... PLS-00306 wrong
number or types of arguments in call 'SAVEPROJECT'
How can I use set setClob method?
The Problem is: with Oracles CLOB implementation I can't create
an Instance, and from the CallableStatement a can't get a
Locator for a CLOB-Object.
This CLOB stuff makes me really nuts!
please somebody help me.. thanks
AlexHi All,
You can not make it like that.
You can not make clob as input parameter.
Do you want an easy way?
This is the easy way.
sample:
function myFunction(S varchar2(40))
return integer as
begin
insert into TableAAA values(S)
--TableAAA only contains 1 column of clob type
end;
This will work the problem with this is the parameter is in
varchar2 right? so there will be limited length for it.
You can do this to call that function:
nyFunction('My String that will be input into clob field');
There's another slight difficult way, I understand that you have
installed Oracle client/server in your system, try to look at
jdbc folder and try to find demo.zip in that folder, you can
find several ways of doing thing with jdbc.
Have a nice day,
Evan -
Stored Procedure with Input & output parameter as XML
Hi
I have a requirement wherein i need to have a stored procedure with accepts huge XML from Java and the SP has to process all the records in the XML and return XML output with some messages in it.
Currenty, I have a stored procedure to process the xml stored in Oracle Database.
I am using the following SQL statement to read the data from the XML column.
select xmltest1.id,xmltest1.name
from xmltest,
XMLTABLE(
XMLNamespaces(default 'syncpsna/schemas'),
'/XMLTestRequest/insert/row'
PASSING xmltest.data_xml
COLUMNS
"ID" number(10) PATH 'id',
"NAME" varchar2(50) PATH 'name') xmltest1
where xmltest.id = 2;I want to execute similary queries to fetch data from the XML Passed as an input parameter from JAVA.
if i could get some examples of reading the XML and sending the xml back to the calling program.
RegardsHi,
if i could get some examples of reading the XML and sending the xml back to the calling program.What kind of process do you want to perform on the input XML?
You said "reading", but for what purpose? Storing data in the database, or just transform the XML into another form?
Anyway, you'll probably need a function, something like :
create or replace function processXML (inputXML in xmltype)
return xmltype
is
outputXML xmltype;
begin
-- process inputXML here, and construct outputXML
return outputXML;
end;Back in Java, you can use the oracle.xdb.XMLType class to map the XMLType SQL datatype to a Java object and manipulate it. -
Db Adapter: problems by calling a procedure with type as parameter
Hi,
We using a db adapter in a bpel process.
In that dapter we call a procedure with types as in and out parameter
package.procedure(p_in IN in_t, p_rsult OUT result_t).
When we calling the procedure, we don't call the procedure directly.
We call that procedure in a schema who have the execute rigths for the package and the types.
When we run the process we get the error message
unable to convert the xsd element p_in whose user defined type is in_t
cause: java.sql.SQLException: ora-01436 connect by loop in user data
I am not shore if I draw the right conclusions.
Is it rigth that bpel have a problem by using types as parameter when using two schematas? Isn't it a bug.
For every help I was thankful.
Thanks in advanced.
MichaelHi,
thanks for the hint. I have implemented a wrapper package and it's working well.
Only one crux. The parameter of the called procedure are data types and not simple types.
CREATE OR REPLACE TYPE pesa_db_return_t AS OBJECT
(SUCCESS_MSG varchar2(255)
,FAULT_SQLCODE varchar2(255)
,FAULT_SQLMSG varchar2(255)
Wrapper package...
IS
PROCEDURE prc_writeReOinDB (p_AuftragRechnungOnline IN pesa_data.pesa_tivu_reo_t
,p_result OUT pesa_data.pesa_db_return_t)
IS
BEGIN
pkg_pesa_reo.prc_writeReOinDB (p_AuftragRechnungOnline => p_AuftragRechnungOnline
,p_result => p_result
END prc_writeReOinDB;
END pkg_pesa_wrapper;
So I have to declare the parameter with the schema user in front of.
Now, we have deployed thes sources on a second enviroment and get following error:
<2008-04-22 15:01:25,749> <ERROR> <eweber.collaxa.cube.engine.dispatch> <BaseScheduledWorker::process> Failed to handle dispatch message ... exception ORABPEL-05002
Message handle error.
An exception occurred while attempting to process the message "com.collaxa.cube.engine.dispatch.message.instance.CallbackDeliveryMessage"; the exception is: Type class not found.
Cannot find class for type "org.apache.xerces.dom.ElementNSImpl". Please check that the class is located in the classpath.
You have a hint for me what I have to do?
Thanks in advanced,
Michael -
How to call a oracle procedure with in/out parameter frm unix shell script?
Hi,
I need to call an oracle stored procedure from unix script. The procedure has 1 input parameter and 2 output parameter. Please send me the syntax for the same. Based on the output values of procedure, I have to execute some more commands in unix script.
Thanks and regards
AAn example :
TEST@db102 SQL> select ename, job from emp
2 where empno = 7902;
ENAME JOB
FORD ANALYST
TEST@db102 SQL> create or replace procedure show_emp (
2 v_empno in number,
3 v_ename out varchar2,
4 v_job out varchar2 )
5 is
6 begin
7 select ename, job into v_ename, v_job
8 from emp
9 where empno = v_empno;
10 end;
TEST@db102 SQL> /
Procedure created.
TEST@db102 SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[ora102 work db102]$ IN=7902
[ora102 work db102]$ set `sqlplus -s test/test@db102 << !
var out1 varchar2(30);
var out2 varchar2(30);
set pages 0
set feed off
exec show_emp($IN,:out1,:out2);
print
exit
`[ora102 work db102]$ echo $1 $2
FORD ANALYST
[ora102 work db102]$ -
How to execute a stored procedure with an out parameter ?
Guys I am struggling with executing a stored procedure from sql plus.I mean my stored procedure has 2 input parameter and 1 out put parameter (status of the execution).
MY_PROCEDURE(p_name in varchar2,p_age in number,p_status out varchar2)
end my_procedure;
When I say
EXECUTE MY_PROCEDURE('manohar','Shetty');
i get insufficient parameters errors.
please help.EXECUTE isn't a valid PL/SQL construct. It's a SQL*Plus command. You don't want to put any SQL*Plus commands in a PL/SQL block.
You can always execute a stored procedure purely through PL/SQL
begin
my_stored_procedure( x, y, z );
end;SQL*Plus happens to give you the execute command so you can avoid the begin and end statements.
Justin -
With JDBC, calling a stored procedure with ARRAY as out parameter
Hi,
I want to use the data type ARRAY as an out parameter in an Oracle stored procedure. I want to call the stored procedure from
my java program using JDBC.
The problem it's i use a 8.1.7 client to acces with oci to a 7.1.3 Database.
With this configuration I can get back a Cursor but not an Array.
Does it's possible ?
Thanks for your help !
MichaklOriginally posted by JDBC Development Team:
It's very similar to other datatype except that it uses OracleTypes.ARRAY typecode and the value is mapped to a oracle.sql.ARRAY instance. The code looks as follows --
cstmt.registerOutParameter (idx, OracleTypes.ARRAY, "VARRAY_TYPE_NAME_HERE");
cstmt.execute ();
ARRAY array = (ARRAY) cstmt.getObject (idx);
Thanks for your reply.
I have to use:-
OracleCallableStatement cs1 = (OracleCallableStatement )conn.prepareCall
( "{call proj_array(?)}" ) ;
for retrieving a collection as an OUT parameter.
This gives me the errors:-
C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Blob getBlob(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
import java.sql.*;
^
C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Array getArray(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
import java.sql.*;
^
C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Clob getClob(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
import java.sql.*;
^
C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Ref getRef(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
import java.sql.*;
^
How do I get rid of these errors?
null -
Calling a stored procedure with array as IN parameter
Hi,
I need to invoke a stored procedure which actually requires 2 IN parameters , both are ARRAY of numbers.. Can anyone tell me using JDBC callableStatement how to invoke this stored procedure?
how to pass array of numbers as input to stored procedure? also what is the corresponding JAVA data type?
the procedure definition is as follows:
PROCEDURE update_group
( in_username IN consumers.consumer_name%type,
in_group_id IN account_group.acct_grp_id%type,
in_group_name IN account_group.acct_grp_dsply_nm%type,
in_group_type IN account_group.acct_group_type_cd%type,
in_rem_accts_arr IN number_array,
in_add_accts_arr IN number_array,
out_over_max_ind OUT integer);
thanks in advanceHi,
You need to define a Call Spec like the following (assume NVarrayClass class):
create or replace procedure nvaproc (x IN OUT number, y IN OUT
NVARRAY,
z IN NVARRAY)
as language java
name 'NVarrayClass.nvaproc(oracle.sql.NUMBER[], java.sql.Array[],
java.sql.Array)';
show errorsI have tons of examples of array in chapter 3 and 8 of my book. The code depot is available @ http://books.elsevier.com/companions/1555583296?country=United+States
Kuassi http://db360.blogspot.com -
Errer when, Call from java to pl sql procedure with table out parameter
Hi ,
Please help me ? It's urgent for me .....
My Oracle Code is like this ,
CREATE TABLE TEST_TABLE ( DATE1 DATE, VALUE_EXAMPLE VARCHAR2(20 BYTE), VALUE2_EXAMPLE VARCHAR2(20 BYTE), VALUE3_EXAMPLE NUMBER ); CREATE OR REPLACE TYPE TONERECORDTEST AS OBJECT ( DATE1 DATE, VALUE_EXAMPLE VARCHAR2(20), VALUE2_EXAMPLE VARCHAR2(20), VALUE3_EXAMPLE NUMBER ); CREATE OR REPLACE TYPE TTESTTABLE IS TABLE OF TONERECORDTEST; CREATE OR REPLACE PACKAGE test_collection_procedures AS PROCEDURE testCallProcedureFromJava(start_time IN DATE, end_time IN DATE, table_data OUT TTesttable); END test_collection_procedures; / CREATE OR REPLACE PACKAGE BODY test_collection_procedures AS PROCEDURE testCallProcedureFromJava(start_time IN DATE, end_time IN DATE, table_data OUT TTesttable) IS BEGIN SELECT TONERECORDTEST(date1, value_example, value2_example, value3_example) BULK COLLECT INTO table_data FROM TEST_TABLE WHERE DATE1>=start_time AND DATE1<=end_time; END testCallProcedureFromJava; END test_collection_procedures;
And my Java Code is like
import java.sql.Connection; import java.sql.DriverManager; import oracle.jdbc.OracleCallableStatement; import oracle.jdbc.OracleTypes; import oracle.sql.ARRAY; import oracle.sql.ArrayDescriptor; import oracle.sql.STRUCT; import oracle.sql.StructDescriptor; public class testPLCollectionType { public static void main(java.lang.String[] args) { try{ //Load the driver Class.forName ("oracle.jdbc.driver.OracleDriver"); // Connect to the database Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@serverbd:1521:squema1","user", "password"); // First, declare the Object arrays that will store the data (for TONERECORDTEST OBJECT TYPE) Object [] p2recobj; Object [] p3recobj; Object [] p4recobj; // Declare the Object Arrays to hold the STRUCTS (for TTESTTABLE TYPE) Object [] p2arrobj; // Declare two descriptors, one for the ARRAY TYPE // and one for the OBJECT TYPE. StructDescriptor desc1=StructDescriptor.createDescriptor("TONERECORDTEST",conn); ArrayDescriptor desc2=ArrayDescriptor.createDescriptor("TTESTTABLE",conn); // Set up the ARRAY object. ARRAY p2arr; // Declare the callable statement. // This must be of type OracleCallableStatement. OracleCallableStatement ocs = (OracleCallableStatement)conn.prepareCall("{call test_collection_procedures.testCallProcedureFromJa va(?,?,?)}"); // Declare IN parameters. Realize that are 2 DATE TYPE!!! Maybe your could change with setDATE ocs.setString(1,"01-JAN-04"); ocs.setString(2,"10-JAN-05"); // Register OUT parameter ocs.registerOutParameter(3,OracleTypes.ARRAY,"TTESTTABLE"); // Execute the procedure ocs.execute(); // Associate the returned arrays with the ARRAY objects. p2arr = ocs.getARRAY(3); // Get the data back into the data arrays. //p1arrobj = (Object [])p1arr.getArray(); p2arrobj = (Object [])p2arr.getArray(); System.out.println("Number of rows="+p2arrobj.length); System.out.println("Printing results..."); for (int i=0; i<p2arrobj.length; i++){ Object [] piarrobj = ((STRUCT)p2arrobj).getAttributes();
System.out.println();
System.out.print("Row "+i);
for (int j=0; j<4; j++){
System.out.print("|"+piarrobj[j]);
}catch (Exception ex){
System.out.println("Exception-->"+ex.getMessage());
Actually when i running the java program it is showing error
Exception-->ORA-06550: line 1, column 58:
PLS-00103: Encountered the symbol "VA" when expecting one of the following:
:= . ( @ % ;
The symbol ":=" was substituted for "VA" to continue.
I am not getting the error .Please help me out Dhabas Edited by: Dhabas on Jan 12, 2009 3:49 PM// Declare the callable statement.
// This must be of type OracleCallableStatement.
..."{call test_collection_procedures.testCallProcedureFromJa va(?,?,?)}");Looks like Ja divorced va. -
Error While calling stored procedure with array
I am getting following error
java.sql.SQLException: Fail to construct descriptor: Invalid arguments
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:829)
at oracle.sql.StructDescriptor.createDescriptor(StructDescriptor.java:85)
at oracle.sql.STRUCT.toSTRUCT(STRUCT.java:322)
at oracle.jdbc.oracore.OracleTypeADT.toDatum(OracleTypeADT.java:253)
at oracle.jdbc.oracore.OracleTypeADT.toDatumArray(OracleTypeADT.java:296)
at oracle.jdbc.oracore.OracleTypeUPT.toDatumArray(OracleTypeUPT.java:137)
at oracle.sql.ArrayDescriptor.toOracleArray(ArrayDescriptor.java:750)
while executing following code
com.brocade.wwn.params.AuthParams ap = new com.brocade.wwn.params.AuthParams();
ap.setAuthKey("1");
ap.setAuthValue("1.1");
com.brocade.wwn.params.AuthParams ap1 = new com.brocade.wwn.params.AuthParams();
ap.setAuthKey("11");
ap.setAuthValue("1.11");
//com.brocade.wwn.params.AuthParams[] arrAP = new com.brocade.wwn.params.AuthParams[1];
//Object[] arrAP = new Object[1];
//arrAP[0] = ap;
com.brocade.wwn.params.AuthParams[] arrAP = {ap,ap1};
System.out.println(" >>> Creating Array Descriptor .... ");
oracle.sql.ArrayDescriptor arraydesc =
oracle.sql.ArrayDescriptor.createDescriptor("WWP.AUTH_ENTRIES", conn);
System.out.println (" ----> " + arraydesc.getBaseName());
System.out.println (" ----> " + arraydesc.getName());
System.out.println (" ----> " + arraydesc.getSQLName());
System.out.println (" ----> " + arraydesc.getSchemaName());
System.out.println (" ----> " + arraydesc.getTypeName());
System.out.println (" ----> " + arraydesc.getMaxLength());
System.out.println (" ----> " + arraydesc.getArrayType());
System.out.println ( arraydesc.TYPE_VARRAY + " : " + arraydesc.TYPE_NESTED_TABLE );
// Object[] tObj = arraydesc.toArray(arrAP);
//tObj = new String[2];
//tObj[0] = "sdaf";
//tObj[1] = "sdaf1";
// tObj[0] = ap;
System.out.println(" >>> Array Descriptor Created .... ");
oracle.sql.ARRAY array = new oracle.sql.ARRAY(arraydesc, conn, arrAP);
My database is Oracle 8i and I am using oracle 9i thin drivers.
Can anybody help me on this ....
thanksI am trying to pass parameter to test my procedure but it is giving this error : ORA-06531: Reference to uninitialized collection
ORA-06512: at line 12
Here is example for my test procedure:
declare
v_session_id_tab SESSION_ID_TAB_TYPE;
v_service_type_tab SERVICE_TYPE_TAB_TYPE ;
v_service_location_tab SERVICE_LOCATION_TAB_TYPE ;
v_service_call_name_tab SERVICE_CALL_NAME_TAB_TYPE;
v_service_call_start_time_tab SERVICE_CALL_ST_TAB_TYPE;
v_service_call_end_time_tab SERVICE_CALL_ET_TAB_TYPE;
v_service_call_duration_tab SERVICE_CALL_DUR_TAB_TYPE;
v_status_tab STATUS_TAB_TYPE;
v_notes_tab NOTES_TAB_TYPE;
begin
v_session_id_tab(1) := 1;
v_service_type_tab(1) := 'db';
v_service_location_tab(1) := 'local';
v_service_call_name_tab(1) := 'Name of call';
v_service_call_start_time_tab(1) := SYSDATE;
v_service_call_end_time_tab(1) := SYSDATE;
v_service_call_duration_tab(1) := 100;
v_status_tab(1) := 'Z';
v_notes_tab(1) := 'NOTES';
BULK_INSERTS (v_session_id_tab,v_service_type_tab, v_service_location_tab,v_service_call_name_tab,v_service_call_start_time_tab,v_service_call_end_time_tab,
v_service_call_duration_tab, v_status_tab, v_notes_tab);
end;
I declare all types at schema level.
Please give your comments.
Thank you
Maybe you are looking for
-
Hi All, I got a requirement to develop a report, when executed, will execute and send a mail automatically of output, to a particular user. Please tel me where to put the logic. Thank You, Rohith.
-
Mail freeze's and then restarts
Hey guys, once i receive a new email and i go to reply to it Mail, freeze's goes to an error screen and relaunch's Mail, but whenever i got to an older email i am able to send the message through. Any ideas?
-
I work for an elementary school and some of the teachers are getting new MacBook Pros with Mountain Lion on them. However, some of the programs they used to use with Snow Leopard are too old to be run on Mountain Lion. Is there a way to fix this and
-
Hello, I've been trying to create a script in Visual Basic to find text in a document and replace it with a graphic. A tutorial I found mentioned that the Adobe site had a pre-made script called ReplaceTextWithGraphic for download on http://www.adobe
-
1. Is there anyway to make what you write on the PDF with the marker tool permanent? 2. Is there a way to make it so the form can have an area for the user to upload a file?