For the uninitiated, Stored Procedures are a series of predefined SQL statements that are configured and stored in the database, and can be easily called from another application, such as Ignition, with a single statement. Conceptually, they are very similar to a scripting function: parameters may be passed to them, they can utilize looping and conditional logic, and can return a value.
Stored Procedure Syntax
Stored procedures are created and maintained in your database. As a result, the creation of a stored procedure is outside the scope of the Ignition User Manual: the commands used to create a stored procedure vary per database.
In regard to calling a Stored Procedure, the syntax can also differ.
SQL Server
The EXEC command is utilized to execute a stored procedure.
Code Block |
---|
language | sql |
---|
title | Pseudocode - Executing a Stored Procedure in SQL Server |
---|
|
EXEC dbo.myStoredProcedure |
Parameters may be passed to the Stored Procedure. SQL Server's documentation has more details on utilizing parameters with Stored Procedures.
Code Block |
---|
language | sql |
---|
title | Pseudocode - Executing a Stored Procedure in SQL Server with Parameters |
---|
|
EXEC dbo.myStoredProcedure @myParam = 100, @AnotherParameters = 'Hello' |
MySQL
MySQL uses the CALL command to execute a Stored Procedure. Note the parentheses characters at the end, as they must be present even when the Stored Procedure is not utilizing parameters.
Code Block |
---|
language | sql |
---|
title | Pseudocode - Executing a Stored Procedure in MySQL |
---|
|
CALL myStoredProcedure() |
If parameters are defined, they can be passed via the parenthesis, similar to how functions work in Python.
Code Block |
---|
language | sql |
---|
title | Pseudocode - Executing a Stored Procedure in MySQL with Multiple Parameters |
---|
|
CALL myStoredProcedure(100, 'Hello') |
For information on the creation of a stored procedure, as well as proper SQL syntax to call a Stored Procedure, reference your database's documentation. Alternatively, if you have a database administrator, they can typically help with the creation and execution of a Stored Procedure.