|
63 | 63 |
|
64 | 64 | <para>
|
65 | 65 | Throughout this chapter, it can be useful to look at the reference
|
66 |
| - page of the <xref linkend="sql-createfunction"/> command to |
| 66 | + page of the <link linkend="sql-createfunction"><command>CREATE |
| 67 | + FUNCTION</command></link> command to |
67 | 68 | understand the examples better. Some examples from this chapter
|
68 | 69 | can be found in <filename>funcs.sql</filename> and
|
69 | 70 | <filename>funcs.c</filename> in the <filename>src/tutorial</filename>
|
|
81 | 82 | </indexterm>
|
82 | 83 |
|
83 | 84 | <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 <link linkend="sql-call"><command>CALL</command></link> command. If the <command>CALL</command> 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. |
| 85 | + A procedure is a database object similar to a function. |
| 86 | + The key differences are: |
| 87 | + |
| 88 | + <itemizedlist> |
| 89 | + <listitem> |
| 90 | + <para> |
| 91 | + Procedures are defined with |
| 92 | + the <link linkend="sql-createprocedure"><command>CREATE |
| 93 | + PROCEDURE</command></link> command, not <command>CREATE |
| 94 | + FUNCTION</command>. |
| 95 | + </para> |
| 96 | + </listitem> |
| 97 | + <listitem> |
| 98 | + <para> |
| 99 | + Procedures do not return a function value; hence <command>CREATE |
| 100 | + PROCEDURE</command> lacks a <literal>RETURNS</literal> clause. |
| 101 | + However, procedures can instead return data to their callers via |
| 102 | + output parameters. |
| 103 | + </para> |
| 104 | + </listitem> |
| 105 | + <listitem> |
| 106 | + <para> |
| 107 | + While a function is called as part of a query or DML command, a |
| 108 | + procedure is called in isolation using |
| 109 | + the <link linkend="sql-call"><command>CALL</command></link> command. |
| 110 | + </para> |
| 111 | + </listitem> |
| 112 | + <listitem> |
| 113 | + <para> |
| 114 | + A procedure can commit or roll back transactions during its |
| 115 | + execution (then automatically beginning a new transaction), so long |
| 116 | + as the invoking <command>CALL</command> command is not part of an |
| 117 | + explicit transaction block. A function cannot do that. |
| 118 | + </para> |
| 119 | + </listitem> |
| 120 | + <listitem> |
| 121 | + <para> |
| 122 | + Certain function attributes, such as strictness, don't apply to |
| 123 | + procedures. Those attributes control how the function is |
| 124 | + used in a query, which isn't relevant to procedures. |
| 125 | + </para> |
| 126 | + </listitem> |
| 127 | + </itemizedlist> |
92 | 128 | </para>
|
93 | 129 |
|
94 | 130 | <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 <link linkend="sql-createprocedure"><command>CREATE PROCEDURE</command></link> command is used instead, there is |
98 |
| - no return type, and some other features such as strictness don't apply. |
| 131 | + The explanations in the following sections about how to define |
| 132 | + user-defined functions apply to procedures as well, except for the |
| 133 | + points made above. |
99 | 134 | </para>
|
100 | 135 |
|
101 | 136 | <para>
|
|
0 commit comments