User`s guide
update
7-245
• inventoryDate
conn = database('dbtoolboxdemo','','');
Import all data from inventoryTable using conn. Store the data in a cell
array contained in the cursor object property curs.Data. Display the data from
inventoryTable in this property.
curs = exec(conn,'select * from inventoryTable');
curs = fetch(curs);
curs.Data
ans =
...
[ 5] [9000] [ 3] '2012-09-14 15:00...'
[ 6] [4540] [ 8] '2013-12-25 19:45...'
[ 7] [6034] [ 16] '2014-08-06 08:38...'
[ 8] [8350] [ 5] '2011-06-18 11:45...'
...
Define a cell array containing the column names that you are updating called Quantity
and Price.
colnames = {'Quantity','Price'};
Define a cell array containing the new data.
% new quantities and prices for product numbers 5 and 8
% are separated by a semicolon in the cell array
data = {10000,5.5;9000,10};
Update the columns Quantity and Price in the inventoryTable for the products with
product numbers equal to 5 and 8. Create a cell array whereclause that contains two
WHERE clauses for both products.
tablename = 'inventoryTable';
whereclause = {'where productNumber = 5';'where productNumber = 8'};
update(conn,tablename,colnames,data,whereclause)
Fetch the data again and view the updated contents in the inventoryTable.
curs = exec(conn,'select * from inventoryTable');
curs = fetch(curs);