如何将 UDT 对象读入结果查询?
How to read UDT object into result query?
我有一个具有许多属性的用户定义类型,如下所示:
create or replace type MyObject is object
(
attribute 1,
attribute 2,
attribute 3
...
)
我有一个函数returns那个对象:
create or replace function GetMyObject
(...params...)
return MyObject
is
...
现在我尝试使用 Oracle.ManagedDataAccess.Client
从 C# 应用程序调用该函数。因为 MyObject
不是 C# 的已知类型,所以我尝试调用 OracleCommand.ExecuteReader()
并从结果查询中一一读取属性值:
select GetMyObject(...) from dual;
我在 Oracle 中得到的是这个 table:
| GetMyObject(...) |
--------------------------------
1 | [UserName.MyObject] |
相反,我希望得到这个:
| attribute 1 | attribute 2 | attribute 3 | ...
------------------------------------------------------
1 | value 1 | value 2 | value 3 | ...
select 语句应该是什么样的?
"objects" 的重点在于它们是复合数据,被视为单个单元。这就是为什么你看到你所看到的。
如果您想查看各个组件,您将需要 SELECT
三列(或任意多列),而不是一列。要访问单个属性,每列一个,您必须使用 "dot" 表示法。
select GetMyObject(...).attribute1 as attribute1
, GetMyObject(...).attribute2 as attribute2
-- (etc.)
from dual;
显然,我假设您实际上在属性名称中没有空格。
我有一个具有许多属性的用户定义类型,如下所示:
create or replace type MyObject is object
(
attribute 1,
attribute 2,
attribute 3
...
)
我有一个函数returns那个对象:
create or replace function GetMyObject
(...params...)
return MyObject
is
...
现在我尝试使用 Oracle.ManagedDataAccess.Client
从 C# 应用程序调用该函数。因为 MyObject
不是 C# 的已知类型,所以我尝试调用 OracleCommand.ExecuteReader()
并从结果查询中一一读取属性值:
select GetMyObject(...) from dual;
我在 Oracle 中得到的是这个 table:
| GetMyObject(...) |
--------------------------------
1 | [UserName.MyObject] |
相反,我希望得到这个:
| attribute 1 | attribute 2 | attribute 3 | ...
------------------------------------------------------
1 | value 1 | value 2 | value 3 | ...
select 语句应该是什么样的?
"objects" 的重点在于它们是复合数据,被视为单个单元。这就是为什么你看到你所看到的。
如果您想查看各个组件,您将需要 SELECT
三列(或任意多列),而不是一列。要访问单个属性,每列一个,您必须使用 "dot" 表示法。
select GetMyObject(...).attribute1 as attribute1
, GetMyObject(...).attribute2 as attribute2
-- (etc.)
from dual;
显然,我假设您实际上在属性名称中没有空格。