Skip to Main Content
  • Questions
  • Passing an array to view object as bind variable using IN clause

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Brian.

Asked: September 12, 2017 - 5:58 pm UTC

Last updated: September 13, 2017 - 3:30 am UTC

Version: Jdeveloper 11.1.2.4

Viewed 10K+ times! This question is

You Asked

Hello Tom,

I have an application, designed in Jdeveloper 11.1.2.4.0. In this application I have a view object with many employee ids based upon its query. I then call upon a function, this function uses these ids and returns a yes/no answer based upon some logic. If yes then I place said employee id into an array, upon completion of the method which calls upon the function and so forth I compose an array of said employee ids. I have declared the array as follows and call upon the view object I need to accept the array as bind variable.
ArrayList    empList = null;

empList = new ArrayList();

while (hasNext())

call function.....

if(yes)
  empList.add(empID)

ViewObjectImpl voImpl = (ViewObjectImpl) appMod.findViewObject(empWithYes);
voImpl.setNamedWhereClausePram("EmpIdsArray", empList.toArray());
voImpl.executeQuery;


In the called upon view object I have a defined a bind variable named = EmpIdsArray with a type of ARRAY. The SQL statement does the following:

Select employeeName
From   employees
Where  employees.employee_id IN (:EmpIdsArray);


I have verified the composed array is being populated as expected. However when I try and execute the application I receive the following error and have been at a loss to solve as every example I have found is slightly off in implementation style or my understanding of them.

Error: oracle.jbo.JboException : Cannot insert/update Array with out context information.

I have tried to define the bind variable in the property manager with ColumnType = EmployeeId and ElemType = BigDecimal with no success.





and Connor said...

Some good examples here about the passing of information back and forth

https://asktom.oracle.com/pls/asktom/asktom.search?tag=passing-an-array-from-java-to-plsql

https://asktom.oracle.com/pls/asktom/asktom.search?tag=passing-arrays-into-plsql-stored-procedures

http://www.oracle.com/technetwork/issue-archive/o60asktom-1870725.html

And then when it comes to using an array via "IN", you can use the TABLE operator to cast the array into a row source, eg

SQL> create table t ( x int );

Table created.

SQL>
SQL> insert into t values (1);

1 row created.

SQL> insert into t values (2);

1 row created.

SQL> insert into t values (3);

1 row created.

SQL> insert into t values (4);

1 row created.

SQL> insert into t values (5);

1 row created.

SQL>
SQL> create or replace
  2  type my_num_list is table of number;
  3  /

Type created.

SQL>
SQL> set serverout on
SQL> declare
  2    n my_num_list := my_num_list(2,3,4);
  3  begin
  4    for i in (
  5      select *
  6      from   t
  7      where  x in ( select column_value from table(n) )
  8    )
  9    loop
 10      dbms_output.put_line(i.x);
 11    end loop;
 12  end;
 13  /
2
3
4

PL/SQL procedure successfully completed.


Rating

  (1 rating)

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

Comments

More info needed

Brian Hayman, October 10, 2017 - 10:27 pm UTC

Hello,

So sorry about the slow reply, I was away but am back now.

So to continue, I have dug a little further and found that when a bind variable is declared as type Array in ADF JDeveloper provides under the property inspector two attribute definitions in the "Other" section, titled ColumnType, ElemType.

1. Column Type: I defined this as a 'Table Type' in the database with the following structure.

<create or replace TYPE emp_array_table_type IS TABLE OF emp_array_ojb_type;/>

<create or replace TYPE emp_array_obj_type AS OBJECT ( EMP_ID NUMBER(9,2))/>

2. ElemType defined as oracle.jbo.domain.Array

I was thinking the conversion would be defined at this point but receive the following error.

JBO-29000 Unexpected exception caught: java.sql.SQLException msg=Fail to convert to internal representation 'xxx'

Where 'xxx' is first element in the array. So if I am declaring the table types and defining the column and its type in JDeveloper what conversion am I not making?

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