show the affected rows after update/insert/delete in DB2

Viewed 32

hello I used to work with Postgres and there if I want to see the affected rows after a manipulation I used the key word RETURNING

Example to show all the columns of the affected row(s):

UPDATE tblName 
  SET colName='something' 
WHERE colName='something' 
RETURNING *; 

can anyone tell me how I do the same thing with DB2 ?

1 Answers

Example for DB2:

CREATE TABLE MYTABLE (
ID      INTEGER GENERATED ALWAYS AS IDENTITY,
NAME    CHAR(30),
AGE     SMALLINT,
)


SELECT ID, NAME, AGE
FROM FINAL TABLE 
(
    INSERT INTO MYTABLE (NAME, AGE)
    VALUES('Jon Smith', 35)
)

Result: 
ID  NAME        AGE
1   Jon Smith   35
Related