简体   繁体   English

将选择行保留到变量中,并使用informix访问其字段

[英]Holding a select row into a variable and accessing its fields with informix

Is there a way in Informix to create a ROW type named or unnamed that you can put a row resulted from a select into? 在Informix中,有没有一种方法可以创建命名或未命名的ROW类型,您可以将选择产生的行放入其中? I'm working in a stored procedure. 我正在存储过程中。

What I want is something like this: 我想要的是这样的:

DEFINE ROW rowVar;

SELECT * INTO rowVar FROM myTableName;

Haven't been able to find the correct syntax so far. 到目前为止,尚未找到正确的语法。 I want the row object to behave sort-of like it would be SAMEAS with the table columns. 我希望行对象表现得像表列的SAMEAS。

It is not possible to use an "undefined" ROW type in Informix Stored Procedure Language (SPL). 在Informix存储过程语言(SPL)中不能使用“未定义” ROW类型。 If you try the following (using Informix 12.10.FC8DE): 如果尝试以下操作(使用Informix 12.10.FC8DE):

CREATE PROCEDURE sp_dummy();
DEFINE generic_row ROW;
END PROCEDURE;

It returns the following error: 它返回以下错误:

-999    Not implemented yet.

The Informix manual does not seem to be correct: Informix手册似乎不正确:

The following statements show examples of generic ROW variables and named ROW variables: 以下语句显示了通用ROW变量和命名ROW变量的示例:

DEFINE d ROW; DEFINE d ROW; -- generic ROW variable -通用ROW变量

If you define the fields of the ROW then you can use it inside the SPL. 如果定义ROW的字段,则可以在SPL内使用它。

I do this regularly with Informix. 我经常使用Informix进行此操作。

define o_Row row(cs_nr int not null, addr_nr int, last_name varchar(255));

foreach
  select cs into o_Row from cs where cs_nr = 1234
end foreach;

if you are returning more than one row or are not in a foreach you can use a multiset. 如果返回的行多或不在foreach中,则可以使用多集。

define o_Row multiset(row(cs_nr int not null, addr_nr int, last_name varchar(255))not null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM