Documentation

This is machine translation

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

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

rows

Return number of rows in fetched data set

Syntax

numrows = rows(curs)

Description

example

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

Examples

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 =

     5

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

curs.Data
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(curs)

Close the connection.

close(conn)

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?