Main Content


(To be removed) Return number of rows in fetched data set

The rows function will be removed in a future release. There is no replacement for this functionality. To import data, use the fetch function. For details, see Compatibility Considerations.



numrows = rows(curs) returns the number of rows in the fetched data set curs.


collapse all

After executing an SQL statement, return the number of rows in the cursor object generated by fetch.

Establish the connection conn to a MySQL® database with the user name username and password pwd.

conn = database('MySQL','username','pwd');

Execute a SELECT query on the table productTable for product numbers 1 through 5 inclusive.

curs = exec(conn,['SELECT * FROM productTable'...
            ' WHERE productNumber >= 1 AND productNumber <= 5']);

exec returns the cursor object curs.

Fetch the data in curs.

curs = fetch(curs);

The Data property of curs contains the fetched data from the SELECT query.

Return the number of rows in the Data property of curs.

numrows = rows(curs)
numrows =


Display the rows of data in the Data property of curs.

ans = 

    [2]    [400314]    [1002]    [ 9]    'Painting Set'   
    [4]    [400339]    [1008]    [21]    'Space Cruiser'  
    [1]    [400345]    [1001]    [14]    'Building Blocks'
    [5]    [400455]    [1005]    [ 3]    'Tin Soldier'    
    [3]    [400999]    [1009]    [17]    'Slinky'         

After you finish working with the cursor object, close it.


Close the connection.


Input Arguments

collapse all

Database cursor, specified as a cursor object created using the exec function.

Output Arguments

collapse all

Number of rows in the database cursor, returned as a numeric scalar.

Compatibility Considerations

expand all

Warns starting in R2021a

See Also

| | | | |

Introduced before R2006a