Using the 'sqlca.sqlerrd2' Option

The 'sqlca.sqlerrd2' option returns a single integer that provides the number of rows that SELECT, INSERT, DELETE, UPDATE, EXECUTE PROCEDURE, and EXECUTE FUNCTION statements processed. To ensure valid results, use this option after SELECT, EXECUTE PROCEDURE, and EXECUTE FUNCTION statements have completed executing. In addition, to ensure valid results when you use this option within cursors, make sure that all rows are fetched before the cursors are closed.

The following example shows an SPL routine that uses the 'sqlca.sqlerrd2' option to determine the number of rows that are deleted from a table:
CREATE FUNCTION del_rows (pnumb INT)
RETURNING INT;

DEFINE nrows INT;

DELETE FROM fst_tab WHERE part_number = pnumb;
LET nrows = DBINFO('sqlca.sqlerrd2');
RETURN nrows;

END FUNCTION;

For more information about the SQL Communications Area (SQLCA) data structure, within which sqlca.sqlerrd2 is a field, see the HCL OneDB™ Guide to SQL: Tutorial.