Read some or all of a table from an ODBC database into a data frame.
1 2 3
connection handle returned by
a database table name accessible from the connected DSN. This should be either a literal character string or a character vector of length 1.
additional arguments to be passed to
logical: retrieve column names from first row of table?
(For use when
either logical or character.
If logical, retrieve row names from the first column
Note the ‘table’ includes whatever table-like objects are provided by the DBMS, in particular views and system tables.
sqlFetch by default retrieves the the entire contents of the table
sqtable. Rownames and column names are restored as indicated
(assuming that they have been placed in the table by the corresponding
sqlFetch can fetch the first
max rows, in
sqlFetchMore will retrieve further result rows,
provided there has been no other ODBC query on that channel in the
These functions try to cope with the peculiar way the Excel ODBC
driver handles table names, and to quote Access table names which
contain spaces. Dotted table names, e.g.
allowed on systems that support them, unless the connection was opened
interpretDot = FALSE.
Useful additional parameters to pass to
limit on the number of rows to fetch, with
0 (the default) indicating no limit.
character string to be used when reading
SQL_NULL_DATA character items from the database:
character string(s) to be mapped to
NA when reading character data: default
The character for the decimal place to be assumed when converting character columns to numeric.
Allow for multiple rows to be retrieved at
A data frame on success, or a character or numeric error code (see
If the table name desired is not a valid SQL name (alphanumeric plus
_) and these functions are not able to interpret the name, you
sqlQuery with whatever quoting mechanism
your DBMS vendor provides (e.g.
[ ] on some Microsoft
products and backticks on MySQL).
Michael Lapsley and Brian Ripley
1 2 3 4 5 6 7 8 9 10 11
## Not run: channel <- odbcConnect("test") sqlSave(channel, USArrests) sqlFetch(channel, "USArrests") # get the lot sqlFetch(channel, "USArrests", max = 20, rows_at_time = 10) sqlFetchMore(channel, max = 20) sqlFetchMore(channel) # get the rest sqlDrop(channel, "USArrests") close(channel) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.