A stored procedure is a group of SQL statements and optional control-of-flow (if,
else,
while
statements) that form a logical unit and perform a particular task. Stored procedures encapsulate a set of operations or queries to execute on a database server.
PrerequisitesÂ
To create a SQL Anywhere or Sybase IQ stored procedure skeleton using Database Development, establish a connection profile to the data server.
-
In the Databases folder in Enterprise Explorer, under the database connection profile,
expand
the
tree for a database, expand the
Schemas folder and then the tree for the appropriate schema owner.
-
Right-click the
Stored Procedures folder, and choose
.
-
Enter the
Name for the stored procedure.
-
(Optional) Enter a description in the
Comments field.
-
Select the
SQL Dialect:
Transact-SQL or
Watcom-SQL.
-
Click
Next to add parameters.
-
Select the parameter used by your stored procedure:
Table 1. Parameter types
Type |
Action |
User-Defined |
You define the output parameter. |
SQLCODE |
Outputs the SQLCODE value when the procedure ends. |
SQLSTATE |
Outputs the SQLSTATE value when the procedure ends. |
Note: If you specify a SQLCODE or SQLSTATE parameter as output, its special value can be checked immediately after a procedure call to test the return status of the procedure.
-
If you selected
User-Defined, enter a parameter name in the
Name column.
Otherwise, go to step 11.
-
Select a Datatype.
-
Select the
IN/OUT option.
-
Select
Finish if you have no variables to declare; otherwise, click
Next.
-
(Optional) Specify the default value for the parameter you are defining, or select Finish if you have no variables to declare.
-
Enter the
Name for any local variables that you want to declare.
-
Select the
Datatype.
-
(Optional) Specify the default value for the parameter you are defining.
-
(Watcom-SQL only) Click
Next.
If you are developing Watcom-SQL, the Provide Optional Return Results Information page is displayed.
-
In the
Results table, specify any number of columns that are part of the result set by entering each result variable name in the
Name column (for example, myCalculation1) and selecting its Datatype.
-
Click
Next and specify save and execution
properties.
Field |
Description |
Generate Script |
Generate a SQL file for the object. |
Enter or Select the Parent Folder |
Specify an existing project or create a new project in
which to save the SQL file. |
File Name |
Enter the file name in which to store the
SQL code. |
Execute Immediately |
Execute the SQL code immediately. If you do not select this
option, you must complete execution of the SQL file later to create the object. |
Open in Editor After Creation |
Create the object and open it in its associated editor. |
-
Click
Finish to create the stored procedure.