0

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.

Community
  • 1
  • 1

1 Answers1

1

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
Vincent Malgrat
  • 66,725
  • 9
  • 119
  • 171
  • Thank you very much, after your example I read [table function description](http://www.oracle-base.com/articles/misc/pipelined-table-functions.php), I understand most of this. but I am debugging my own package store procedur, there is no error for creating it, but I got error for calling it. I am new, I don't know how to formate my code in comment. I add all my coed by the next comment. hope you can help me. – Simon Sheng Jul 11 '12 at 18:36
  • CREATE OR REPLACE TYPE t_table IS TABLE of VARCHAR2(255); / CREATE OR REPLACE PACKAGE simon_pkg IS TYPE t_table IS TABLE of VARCHAR2(255); TYPE c_cursor IS ref CURSOR; PROCEDURE f (t_input in t_table,c_out out c_cursor); END; / CREATE OR REPLACE PACKAGE BODY simon_pkg IS PROCEDURE f (t_input in t_table,c_out out c_cursor) IS v_cursor c_cursor; BEGIN OPEN v_cursor FOR SELECT last_name FROM employees WHERE last_name IN (SELECT * FROM TABLE(t_input)); c_out := v_cursor; END f; END; / – Simon Sheng Jul 11 '12 at 18:38
  • I will create a new question.I can formate my code in comment. – Simon Sheng Jul 11 '12 at 18:41