The question uses some ambiguous terminology that makes it unclear what needs to be done. Fortunately, DB2 offers robust support for a variety of SQL templates.
To limit the number of rows that have been modified using UPDATE :
UPDATE ( SELECT t.column1 FROM someschema.sometable t WHERE ... FETCH FIRST ROW ONLY ) SET column1 = 'newvalue';
The UPDATE never sees the underlying table, just an expression that filters it, so you can control which rows are updated.
INSERT limited number of newlines:
INSERT INTO mktg.offeredcoupons( cust_id, coupon_id, offered_on, expires_on ) SELECT c.cust_id, 1234, CURRENT TIMESTAMP, CURRENT TIMESTAMP + 30 DAYS FROM mktg.customers c LEFT OUTER JOIN mktg.offered_coupons o ON o.cust_id = c.cust_id WHERE .... AND o.cust_id IS NULL FETCH FIRST 1000 ROWS ONLY;
<h / "> So DB2 supports SELECT from an UPDATE , INSERT or DELETE :
SELECT column1 FROM NEW TABLE ( UPDATE ( SELECT column1 FROM someschema.sometable WHERE ... FETCH FIRST ROW ONLY ) SET column1 = 'newvalue' ) AS x;
SELECT will only return data from modified rows.
source share