Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return the number of affected rows in a HANA stored procedure?

Tags:

sql

hana

How does one return the number of rows affected from an insert or update statement while inside a SAP HANA stored procedure?

In oracle one would use sql%rowcount but I can't find an equivalent for HANA in their documentation?

For example:

CREATE PROCEDURE procedure_name (p_input)
LANGUAGE SQLSCRIPT AS
BEGIN
   define c integer;
   insert into some_table values (somevalues);
   c := sql%rowcount;
END

UPDATE:

I found the answer on an SAP thread finally. You can run this statement after the insert or update to get the rowcount:

SELECT ::ROWCOUNT into L_C FROM DUMMY;
like image 954
Chip Allen Avatar asked May 14 '14 06:05

Chip Allen


1 Answers

Not trying to steal internet points, but this should have an answer that's not just in the description of the question. To select row count, use the following:

SELECT ::ROWCOUNT INTO someVariable FROM DUMMY;

DUMMY is a special keyword in HANA and is used to select variables vs selecting from a table. You cannot simply SELECT ::ROWCOUNT INTO someVariable in HANA.

like image 153
Peder Rice Avatar answered Dec 28 '22 19:12

Peder Rice