Limiting the Number of Retrieved Records

Goal

You want your application to limit the number of records that are retrieved from a data source.

Implementation

To limit the size of a result set, you can use either SAS syntax or standard JDBC syntax. Because there are implementation differences between the two types of syntax, you should use the syntax that best suits your needs.
The sample code in the table can be used to produce a result set that contains a maximum of 20 rows.
Two Ways to Limit a Result Set
Method
Sample Code
Action
SAS syntax1
stmt.executeUpdate("reset outobs=20")
  • Limits the number of rows that the server sends back.
  • The limit remains for the duration of the connection, as long as the limit is not changed with subsequent code.
Standard JDBC syntax
stmt.setMaxRows(20)
  • Limits the number of rows that the client asks for.
  • The limit remains for the duration of the statement, as long as the limit is not changed with subsequent code.
1Simple queries of the form SELECT * FROM TABLE are not affected by the OUTOBS= option. You must explicitly select the columns or provide a WHERE clause.
Note: In addition, standard JDBC syntax is more portable than SAS syntax.