This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Return number of rows in fetched data set


numrows = rows(curs)



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 connection conn to a MySQL® database with user name username and password pwd.

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

Execute a SELECT query on the 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.

Introduced before R2006a

Was this topic helpful?