简体   繁体   中英

Informix equivalent to Oracle's UPDATE … RETURNING INTO statement

In Oracle I can return information from an UPDATE statement like so:

UPDATE SOME_TABLE
SET SOME_COL = SYSDATE
WHERE
    ...
RETURNING SOME_COL INTO :OutParameter

Combined with the number of affected rows this allows to check whether a row exists, update it, then return some information about the updated row (like the newly updated value, or the row id, or whatever), all in one query.

This can also be accomplished in SQL Server using the OUTPUT clause.

Is there anything like this in Informix? I've checked Informix's UPDATE syntax and it doesn't look like it has anything equivalent... Any alternatives?

The number of affected rows is available from the SQLCA record, which is available in plain SQL or SPL via DBINFO('sqlca.sqlerrd2')

eg:

UPDATE table SET foo = 'bar' WHERE baz = 'quux';
INSERT INTO log_table (date_stamp, msg, row_count)
  VALUES (CURRENT, "Updated foo to bar", DBINFO('sqlca.sqlerrd2'));

See the fine manual .

There's no equivalent to the RETURNING clause in Informix. The concept seems odd to me - how would that work when multiple rows have been updated, with dynamic content, like SET foo = baz * bar where foo, baz and bar are all columns, and there's no single value shared by all affected tuples?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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