Skip to Main Content
  • Questions
  • Calling SP with PLSQL Tables indexed by char(1) parameters

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, kishan.

Asked: September 12, 2001 - 4:26 pm UTC

Last updated: August 13, 2004 - 6:12 pm UTC

Version: 8.1.6.1.0

Viewed 1000+ times

You Asked

Hello,
We have a simple stored procedure that we can't get it to work with Java. We are using Oracle 8.1.7 driver and oracle 8i db(8.1.6.1.0) on NT4, with JDK1.3. The stored procedure only has one parameter, PLSQL table indexed by char.
An error occurs when on call_proc.execute() line.

This is an error that we get:
java.sql.SQLException: ORA-06550: line 1, column 16:
PLS-00418: array bind type must match PL/SQL table row type
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

This sounds like a bug with Oracle 8.1.7 driver, but maybe we are doing something wrong. Please help!

Thanks in advance.


(1). Here is the code:

/* package */
create or replace package temppack
is
Type CHAR_TBL IS TABLE OF CHAR(1)
INDEX BY BINARY_INTEGER;

END TEMPPACK;
/* stand alone procedure */
create or replace procedure testchar(ab out temppack.char_tbl)
is
begin
for i in 1 ..10
loop
ab(i):=i;
end loop;
end;


/* Sample code */

import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;


public class testchar {
public static void main(String[] args)
throws SQLException
{
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn=
DriverManager.getConnection("jdbc:oracle:oci8:test/test@testdev");
OracleCallableStatement call_proc =(OracleCallableStatement)
conn.prepareCall("begin testchar(?);end;");

int elemSqlType = Types.CHAR;
int maxLen = 10;
int elemaxLen = 1;

call_proc.registerIndexTableOutParameter(1,maxLen,elemSqlType,elemaxLen);
call_proc.execute();
// access the value using JDBC default mapping
int a=0;
String[] values = (String[])
call_proc.getPlsqlIndexTable (1);
// print the elements

for (int i=0; i<values.length; i++)
System.out.println (values[i]);
call_proc.close();
}

catch (SQLException e)
{
System.out.println(e.toString());
}

}
}






and Tom said...

refer to
</code> http://docs.oracle.com/cd/A87860_01/doc/java.817/a83724/indexby1.htm#1059014 <code>

only JDBC types of NUMERIC and VARCHAR are supported (types.Char is not).

Apparently, support for tables of CHAR are not supported, you'll need to use a table of VARCHAR. If you have existing code that cannot be changed, you'll have to use a block like this:

....
conn.prepareCall(
"declare "+
" temp_data temppack.char_tbl; "+
" type vcArray is table of varchar2(1) index by binary_integer; "+
" temp_data2 vcArray; "+
"begin "+
" testchar(temp_data); "+
" for i in 1..temp_data.count loop temp_data2(i) := temp_data(i); end loop; "+
" ? := temp_data2; " +
"end;" );

int elemSqlType = Types.VARCHAR;
int maxLen = 10;
int elemaxLen = 2;
.....

also -- change your plsql test routine to loop to 9, not 10 to avoid a string overwrite...

(note: binding to plsql table types is new with 817 and up OCI jdbc only)



Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

is it resolved in Oracle9i

Push, August 13, 2004 - 2:22 pm UTC

Tom,
We are using Oracle9i Enterprise Edition Release 9.2.0.5.0 -64bit Production , JServer Release 9.2.0.5.0 - Production
and JDK1.4.

Can you please tell me if this constraint is removed in
this version.

Thanks
Push..

Tom Kyte
August 13, 2004 - 6:12 pm UTC

you have access to the same docs and ability to create a test case I do?!?


</code> http://docs.oracle.com/docs/cd/B10501_01/java.920/a96654/oci_func.htm#1017512 <code>


it appears that only varchar2 is supported. (i took the brute force method of "compile supplied example above and run it")

PL/SQL table of CHAR

Push, August 13, 2004 - 2:40 pm UTC

Tom,
We are using Oracle9i Enterprise Edition Release 9.2.0.5.0 -64bit Production ,
JServer Release 9.2.0.5.0 - Production
and JDK1.4.

Can you please tell me if this constraint is removed in
this version.

If not is there any work around for calling the
stored program that has a PL/SQL table of CHAR data type
as IN mode.

Because the same stored program also shared with other application.

Thanks
Push..

Tom Kyte
August 13, 2004 - 6:12 pm UTC

see the original answer, I tried to provide a method.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library