我如何从 Informix 中的 SELECT 进行更新?

How do I UPDATE from a SELECT in Informix?

我正在尝试使用来自另一个 table 的数据进行更新。我试过 this answer(第二部分),但它对我不起作用。我收到一条语法错误的一般错误消息。

我也试过 this solution 并且也收到了语法错误消息。

如果我尝试只更新一列,它会起作用:

UPDATE dogs
SET name = 
    (
        SELECT 'Buddy'
        FROM systables 
        WHERE tabid = 1
     );

但我需要更新多个列。不幸的是,这不起作用:

UPDATE dogs
SET (name, breed) = 
    (
        SELECT 'Buddy', 'pug'
        FROM systables 
        WHERE tabid = 1
    );

Informix版本为12.10.FC8

您还缺少一组围绕子查询的括号。 来自 Informix manual:

The subquery must be enclosed between parentheses. These parentheses are nested within the parentheses that immediately follow the equal ( = ) sign. If the expression list includes multiple subqueries, each subquery must be enclosed between parentheses, with a comma ( , ) separating successive subqueries:

UPDATE ... SET ... = ((subqueryA),(subqueryB), ... (subqueryN))

The following examples show the use of subqueries in the SET clause:

UPDATE items    
SET (stock_num, manu_code, quantity) = 
  ( 
    (
      SELECT stock_num, manu_code 
       FROM stock     
       WHERE description = 'baseball'
    ),
    2
  )    
WHERE item_num = 1 AND order_num = 1001;

UPDATE table1    
SET (col1, col2, col3) =
  (
    (
      SELECT MIN (ship_charge), MAX (ship_charge) 
      FROM orders
    ),
    '07/01/2007'
  )
WHERE col4 = 1001;

因此,为了让 Informix 接受您的更新,它必须是:

UPDATE dogs
SET (name, breed) = 
  (
    (
      SELECT 'Buddy', 'pug'
      FROM systables 
      WHERE tabid = 1
    )
  );