|
81 | 81 | </indexterm>
|
82 | 82 |
|
83 | 83 | <para>
|
84 |
| - A procedure is a database object similar to a function. The difference is |
85 |
| - that a procedure does not return a value, so there is no return type |
86 |
| - declaration. While a function is called as part of a query or DML |
87 |
| - command, a procedure is called in isolation using |
88 |
| - the <xref linkend="sql-call"/> command. If the CALL command is not |
89 |
| - part of an explicit transaction, a procedure in many server-side |
90 |
| - languages can commit, rollback, and begin new transactions during |
91 |
| - its execution, which is not possible in functions. |
| 84 | + A procedure is a database object similar to a function. |
| 85 | + The key differences are: |
| 86 | + |
| 87 | + <itemizedlist> |
| 88 | + <listitem> |
| 89 | + <para> |
| 90 | + Procedures are defined with the <xref linkend="sql-createprocedure"/> |
| 91 | + command, not <command>CREATE FUNCTION</command>. |
| 92 | + </para> |
| 93 | + </listitem> |
| 94 | + <listitem> |
| 95 | + <para> |
| 96 | + Procedures do not return a function value; hence <command>CREATE |
| 97 | + PROCEDURE</command> lacks a <literal>RETURNS</literal> clause. |
| 98 | + However, procedures can instead return data to their callers via |
| 99 | + output parameters. |
| 100 | + </para> |
| 101 | + </listitem> |
| 102 | + <listitem> |
| 103 | + <para> |
| 104 | + While a function is called as part of a query or DML command, a |
| 105 | + procedure is called in isolation using |
| 106 | + the <xref linkend="sql-call"/> command. |
| 107 | + </para> |
| 108 | + </listitem> |
| 109 | + <listitem> |
| 110 | + <para> |
| 111 | + A procedure can commit or roll back transactions during its |
| 112 | + execution (then automatically beginning a new transaction), so long |
| 113 | + as the invoking <command>CALL</command> command is not part of an |
| 114 | + explicit transaction block. A function cannot do that. |
| 115 | + </para> |
| 116 | + </listitem> |
| 117 | + <listitem> |
| 118 | + <para> |
| 119 | + Certain function attributes, such as strictness, don't apply to |
| 120 | + procedures. Those attributes control how the function is |
| 121 | + used in a query, which isn't relevant to procedures. |
| 122 | + </para> |
| 123 | + </listitem> |
| 124 | + </itemizedlist> |
92 | 125 | </para>
|
93 | 126 |
|
94 | 127 | <para>
|
95 |
| - The explanations on how to define user-defined functions in the rest of |
96 |
| - this chapter apply to procedures as well, except that |
97 |
| - the <xref linkend="sql-createprocedure"/> command is used instead, there is |
98 |
| - no return type, and some other features such as strictness don't apply. |
| 128 | + The explanations in the following sections about how to define |
| 129 | + user-defined functions apply to procedures as well, except for the |
| 130 | + points made above. |
99 | 131 | </para>
|
100 | 132 |
|
101 | 133 | <para>
|
|
0 commit comments