execute - Execute SQL statement using SQLite database connection - MATLAB (original) (raw)

Main Content

Execute SQL statement using SQLite database connection

Since R2022a

Syntax

Description

execute([conn](#mw%5F5f2f47d5-7ada-48c5-999c-518aadf91141%5Fsep%5Fshared-conn),[sqlquery](#mw%5Fb1057fea-8d99-41e2-936b-16cb009c63e9)) executes an SQL query that contains a non-SELECT SQL statement by using the SQLite database connection with the MATLAB® interface to SQLite.

example

Examples

collapse all

Execute Non-SELECT SQL Statement

Using an SQLite database connection and the MATLAB® interface to SQLite, create and execute a non-SELECT SQL statement that creates a temporary view in the database and imports its contents.

Create an SQLite database connection to the SQLite database file tutorial.db.

dbfile = "tutorial.db"; conn = sqlite(dbfile);

Create an SQL statement that creates a temporary view named PRODUCTNAMES. The view selects all product names using the productDescription column of the productTable database table. Execute the CREATE SQL statement.

sqlquery = strcat("CREATE TEMP VIEW PRODUCTNAMES AS", ... " SELECT productDescription FROM productTable"); execute(conn,sqlquery)

Import the product names using the new temporary view and display the first three names.

sqlquery = "SELECT * FROM PRODUCTNAMES"; results = fetch(conn,sqlquery); head(results,3)

productDescription
__________________

 "Victorian Doll" 
 "Train Set"      
 "Engine Kit"     

Close the database connection.

Input Arguments

collapse all

SQLite database connection, specified as an sqlite object created using the sqlite function.

sqlquery — SQL statement

character vector | string scalar

SQL statement, specified as a character vector or string scalar. The SQL statement can be any valid non-SELECT SQL statement. For information about the SQL query language, see the SQL Tutorial.

Example: "DROP VIEW PRODUCTNAMES"

Data Types: char | string

Version History

Introduced in R2022a