MATLAB: Am I unable to execute a SQL query which uses BEGIN and END statements with the MATLAB Database Toolbox 3.0.1 (R14SP1)

begincompountDatabase Toolboxsyntax

When I attempt to execute an SQL query which uses a BEGIN/END block, such as the following:
{BEGIN
<procedure calls>;
END;}
on a database that uses an ODBC driver, I receive the following result:
curs=exec(conn, sqlData);
curs.Message
ans =
[Microsoft][ODBC driver for Oracle]Syntax error or access violation
This query is able to execute from other SQL software; why is it failing?

Best Answer

Neither the Oracle ODBC driver nor the Microsoft Oracle ODBC driver is able to execute statements of this syntax. These drivers typically run a stored procedure interactively. The introduction of a BEGIN/END block will cause them to fail. To work around this issue, create a stored procedure in the database and then run this procedure from the exec command.
You are also able to use input parameters for the stored procedure call. For
example,
e = exec(c,'{call sp_name(a,b,c)}')
where sp_name is the name of your stored procedure.