Can an Oracle stored procedure that has a nested table parameter be called from ODP.NET?

自闭症网瘾萝莉.ら 提交于 2019-12-18 07:05:04

问题


I've got a stored procedure that has a couple parameters that are nested tables.

CREATE TYPE FOO_ARRAY AS TABLE OF NUMBER;
CREATE TYPE BAR_ARRAY AS TABLE OF INTEGER;

CREATE PROCEDURE Blah(
  iFoos IN FOO_ARRAY,
  iBars IN BAR_ARRAY,
  oResults OUT SOMECURSORTYPE
) AS
BEGIN
  OPEN oResults FOR
    SELECT *
    FROM SomeTable T
    JOIN TABLE(iFoos) foos ON foos.column_value = T.foo
    JOIN TABLE(iBars) bars ON bars.column_value = T.bar;    
END

Using ODP.NET (Oracle.DataAccess.dll), is there a way to call this stored procedure and pass arrays into these parameters? The only way I've found to pass arrays is if the parameter type is an associative array (a different type of collection that isn't accessible within SQL).


回答1:


I made it work this way:

  • Create a type in the database like "create or replace TYPE NT_LNG IS TABLE OF varchar(2);"
  • Create a Class implementing IOracleCustomType and INullable (SimpleStringArray)
  • Create a Class implementing IOracleCustomTypeFactory (SimpleStringArrayFactory). Mark it with this attribute "[OracleCustomTypeMappingAttribute("KNL.NT_LNG")]"

and you pass the parameter like this:

 SimpleStringArray sa1 = new SimpleStringArray();
 sa1.Array = new String[]{"aaa","bbb"};
 OracleParameter param = new OracleParameter("p_lngsrc", OracleDbType.Array, sa1, ParameterDirection.Input);
 param.UdtTypeName = "KNL.NT_LNG";

Good Luck




回答2:


Oracle also offers a free tool to generate a custom .NET class that maps to your nested table type:

Download "Oracle Developer Tools for Visual Studio" (free), open Server Explorer, open "User Defined Types" node, find your user defined type, right click and choose "Generate Custom Class".

Here's a walkthrough to get you started with UDTs in general:

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/hol08/dotnet/udt/udt_otn.htm



来源:https://stackoverflow.com/questions/5557318/can-an-oracle-stored-procedure-that-has-a-nested-table-parameter-be-called-from

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