odbc_execute/2 is a non-deterministic predicate, returning one row of the result set each time on backtracking. If you want to have a number 1… along with these rows, you can use call_nth/2 as in
First of all, if you want the number of rows, indeed you should use COUNT. That avoids a lot of work in the database, interface and Prolog.
But, I don’t think you understand the idea of non-determinism, i.e., a predicate call returning multiple answers on backtracking. The simplest example is
?- member(X, [a,b,c]).
X = a ;
X = b ;
X = c.
odbc_execute works like member/2. If you want to count its solutions, use