-- type to match emp record create or replace type emp_scalar_type as object (EMPNO NUMBER(4) , ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7, 2), COMM NUMBER(7, 2), DEPTNO NUMBER(2) ) / -- table of emp records create or replace type emp_table_type as table of emp_scalar_type / declare tb emp_table_type; deptnoList sys.OdciNumberList; BEGIN select emp_scalar_type(empno, ename, job, mgr, hiredate, sal, comm, deptno) bulk collect into tb from emp; SELECT deptno bulk collect INTO deptnoList FROM dept where deptno not in (select deptno from table(tb)); for i in 1..deptnoList.count loop dbms_output.put_Line(deptnoList(i)); end loop; END; 40
963281 wrote:Why do you create an associative array?
I am calling a pl/sql stored procedure from a java program passing two arrays (p_employees) and (p_departments) as parameters to the procedure. Within the procedure I have stored the arrays in a table of records like this:
type t_emp_type is record (employee_id number, department_id number);
type t_emp_tbl_type is table of t_emp_type index by binary_integer;
Now I would like to compare my l_employee_tbl with a SQL table in the database. Basically I would like to join my l_employee_tbl table with a SQL table named departments on department_id, returning all department_id:s that was not found in table departments.Of course, not possible as the SQL engine does not support PL/SQL user defined types. PL/SQL however support user defined SQL types. Which makes SQL defined types a lot more flexible.
However, it is not possible to select from a user-defined table type. I have also tried to use the table() function and to cast l_employee_tbl, but found out it can't be done with records.Never mind SQL and PL/SQL - as a generic programming data structure principle. How do you expect being able to cast an associative array (name-value pairs) to a standard array? The two data structures are very different. So I'm puzzled in how you expect to move a non-scalar name-value pair data structure into a non-scalar value only data structure?
And I would really like to use records or some other type where define my PL/SQL data.Why exactly? If the Java or PL/SQL data structure is populated using SQL data and database data, and wanting to use that data structure in SQL, what is the point? Why pull SQL data into a client data structure at all then - surely it is far more performant and scalable to rather keep that data in the database, and do the joins/selects/filters/etc using SQL?