CREATE PROCEDURE Syntax
Parameters
<schema name>
<schema name>
Name of the schema in which this SQL procedure will be created.
<procedure name>
<procedure name>
Name to give to the created SQL procedure; must adhere to the supported
naming criteria for tables, and cannot be named the
same as any existing table or view.
<sql statements>
<sql statements>
Semicolon-separated list of
supported SQL statements. If the final statement
in the SQL procedure is an output-generating statement
(SQL query, SHOW command, etc.), the output of that statement alone will be returned
to the user; all other statements that generate output will be ignored.
OR REPLACE
OR REPLACE
Drop any existing SQL procedure with the same name before creating this one.
LANGUAGE
LANGUAGE
Optional language specification. Only
SQL is supported at this time.EXECUTE FOR EVERY
EXECUTE FOR EVERY
Allows specification of an interval in seconds, minutes, hours, or days, at which the
SQL procedure should be executed. Fractional values for
<number> are accepted.By default, the procedure will be run immediately and every specified interval after
that; this can be modified with the following options:STARTING AT: specify a date or timestamp at which the first execution should occurSTOP AFTER: specify a date, timestamp, or time interval after which executions should end
WITH OPTIONS
WITH OPTIONS
Optional indicator that a comma-delimited list of option/value assignments will follow.
The following options are available:
| Option | Description |
|---|---|
EXECUTE AS | Executes the SQL procedure as the given user with that user’s privileges. If this user doesn’t exist at the time of execution, the SQL procedure will be executed as the creating user, and and, failing that, the system administration user. |
Examples
To create asqlp SQL procedure:
CREATE PROCEDURE Example
sqlp_weekly SQL procedure that executes once per week:
CREATE PROCEDURE (Scheduled) Example