Question

This question is a part of my question how to pass javascript array to oracle store procedure by ado parameter object

I think divide it to 3 small parts will get answer faster.

For this question.

I know we can declare a table type and use

select last_name 
from employees in (select * from table(cast(my_table_type_var as my_table_type));

but I always get error from create new package which include a procedure has this. and I read some thread said I need to declear a sql(in schema) type because sql and pl/slq are not using same engine. I try create type in schema by spl*plus, but still get same errors so I need a working package example for this first please.

Was it helpful?

Solution

You need a SQL object to call the TABLE operator from a SELECT. Here's a small example (9iR2):

SQL> CREATE TYPE table_number is TABLE OF NUMBER;
  2  /

Type created.

SQL> SELECT * FROM TABLE(table_number(1,2,3));

COLUMN_VALUE
------------
           1
           2
           3

You can use a function here instead (note that my TYPE is still defined outside the package):

SQL> CREATE OR REPLACE PACKAGE pkg AS
  2     FUNCTION f RETURN table_number;
  3  END;
  4  /

Package created.

SQL> CREATE OR REPLACE PACKAGE BODY pkg AS
  2     FUNCTION f RETURN table_number IS
  3     BEGIN
  4        RETURN table_number(4,5,6);
  5     END;
  6  END;
  7  /

Package body created.

SQL> SELECT * FROM table(pkg.f);

COLUMN_VALUE
------------
           4
           5
           6
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top