Main Content

exec

Execute SQL statement using SQLite connection

Theexecfunction will be removed in a future release. Use theexecutefunction to manage the SQLite database instead.

Description

example

exec(conn,sqlquery)performs database operations on an SQLite database file by executing the SQL statementsqlqueryfor the SQLite connectionconnusing the MATLAB®interface to SQLite. For example, use this syntax to create database tables in the SQLite database file. To import data into MATLAB from the SQLite database file, use thefetchfunction.

Examples

collapse all

Using the MATLAB® Interface to SQLite, create a table in a new SQLite database file.

Create the SQLite connectionconnto the new SQLite database filetutorial.db. Specify the file name in the current folder.

dbfile = fullfile(pwd,'tutorial.db'); conn = sqlite(dbfile,'create');

Create the tableinventoryTableusingexec.

createInventoryTable = ['create table inventoryTable '...'(productNumber NUMERIC, Quantity NUMERIC, '...'Price NUMERIC, inventoryDate VARCHAR)']; exec(conn,createInventoryTable)

inventoryTableis an empty table intutorial.db.

To insert data into the database file, use theinsertfunction.

Close the SQLite connection.

close(conn)

Input Arguments

collapse all

SQLite database connection, specified as ansqliteobject created using thesqlitefunction.

SQL statement, specified as a character vector or string scalar. The SQL statement can be any valid SQL statement, including nested queries. The SQL statement can be a stored procedure, such as{call sp_name (parm1,parm2,...)}. For stored procedures that return one or more result sets, use theexecfunction. For procedures that return output arguments, userunstoredprocedure.

For information about the SQL query language, see theSQL Tutorial.

Data Types:char|string

版本历史

Introduced in R2016a