Demos
The series of commands used to import a column of data, X from table Y:
% connect to specified database, specifying username and password
connectionA = database('database', 'user',
'password')
% open cursor and issue SQL statement to select data
cursorA = exec(connectionA, 'select X from Y')
% retrieve R rows of data
cursorA = fetch(cursorA, R)
The SQL statement in the exec command can include a where clause to further define the data
to be imported. The fetch statement can retrieve all data at once or a subset of the
selected rows. This process takes only a few minutes and, can be automated if you save the
commands in an M-file. Once the data is in MATLAB, you can view attributes of the imported
data, as well as the data itself, and you can use all of the MATLAB commands to process the
data.
Exporting your results is easy, too. Put the data to be exported into a cell array and
define the database column names to which you will be writing. For example:
insert(connectionA, 'tablename', {'columnname'},
'cell_array')
Instead of an insert command, which adds data, you can use an update command, which
replaces data. With the update command, you can use a where clause to specify exactly which
data to replace. There is also an option for requiring a commit command in order to write
data.
|