An Oracle stored procedure accept array(table) parameter in package example needed

别说谁变了你拦得住时间么 提交于 2019-12-25 04:03:42

问题


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.


回答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


来源:https://stackoverflow.com/questions/11435201/an-oracle-stored-procedure-accept-arraytable-parameter-in-package-example-need

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!