## pSqlCreateFunction
```mermaid
%%{init: {
'theme': 'base',
'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
'themeVariables': {
'fontSize': '11px',
'fontFamily': 'Arial'
}
}}%%
flowchart LR
pSqlCreateFunction_start((START))
pSqlCreateFunction_start --> pSqlCreateFunction_0_0[CREATE]:::quoted
pSqlCreateFunction_0_0 --> pSqlCreateFunction_0_1[OR]:::quoted
pSqlCreateFunction_0_1 --> pSqlCreateFunction_0_2[REPLACE]:::quoted
pSqlCreateFunction_0_2 --> pSqlCreateFunction_0_3[pSqlFunctionSpec]
pSqlCreateFunction_0_3 --> pSqlCreateFunction_end((END))
```
## Purpose
The create function statement creates a PSQL block that executes the code and returns a value to the caller using the 'return' statement. An error is raised when a function, procedure or package with the same name already exists. When 'or replace' is specified, a previously existing function with the same name is dropped before creating the new function.
When using the replace clause, a previous version of the identical named function is replaced. Otherwise an error is raised when a function with the same name already exists. When using the if not exists clause (available from 25.0.41 and 24.0.778), the function is only created when a previous version of the identical named function did not exist.
## pSqlCreateProcedure
```mermaid
%%{init: {
'theme': 'base',
'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
'themeVariables': {
'fontSize': '11px',
'fontFamily': 'Arial'
}
}}%%
flowchart LR
pSqlCreateProcedure_start((START))
pSqlCreateProcedure_start --> pSqlCreateProcedure_0_0[CREATE]:::quoted
pSqlCreateProcedure_0_0 --> pSqlCreateProcedure_0_1[OR]:::quoted
pSqlCreateProcedure_0_1 --> pSqlCreateProcedure_0_2[REPLACE]:::quoted
pSqlCreateProcedure_0_2 --> pSqlCreateProcedure_0_3[pSqlProcedureSpec]
pSqlCreateProcedure_0_3 --> pSqlCreateProcedure_end((END))
```
## Purpose
The create function statement creates a PSQL block that executes code when called. An error is raised when a function, procedure or package with the same name already exists. When 'or replace' is specified, a previously existing procedure with the same name is dropped before creating the new procedure.
When using the replace clause, a previous version of the identical named procedure is replaced. Otherwise an error is raised when a procedure with the same name already exists. When using the if not exists clause (available from 25.0.41 and 24.0.778), the procedure is only created when a previous version of the identical named procedure did not exist.
## pSqlFunctionSpec
```mermaid
%%{init: {
'theme': 'base',
'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
'themeVariables': {
'fontSize': '11px',
'fontFamily': 'Arial'
}
}}%%
flowchart TD
pSqlFunctionSpec_start((START))
pSqlFunctionSpec_start --> pSqlFunctionSpec_0_0[FUNCTION]:::quoted
pSqlFunctionSpec_0_0 --> pSqlFunctionSpec_0_1[pSqlVariableName]
pSqlFunctionSpec_0_1 --> pSqlFunctionSpec_0_2["("]:::quoted
pSqlFunctionSpec_0_2 --> pSqlFunctionSpec_0_3[pSqlArgumentList]
pSqlFunctionSpec_0_3 --> pSqlFunctionSpec_0_4[")"]:::quoted
pSqlFunctionSpec_0_4 --> pSqlFunctionSpec_0_5[RETURN]:::quoted
pSqlFunctionSpec_0_5 --> pSqlFunctionSpec_0_6[pSqlDataType]
pSqlFunctionSpec_0_6 --> pSqlFunctionSpec_0_7[AS]:::quoted
pSqlFunctionSpec_0_7 --> pSqlFunctionSpec_0_8[IS]:::quoted
pSqlFunctionSpec_0_8 --> pSqlFunctionSpec_0_9[pSqlBlockOptionalDeclare]
pSqlFunctionSpec_0_9 --> pSqlFunctionSpec_end((END))
```
## pSqlProcedureSpec
```mermaid
%%{init: {
'theme': 'base',
'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
'themeVariables': {
'fontSize': '11px',
'fontFamily': 'Arial'
}
}}%%
flowchart TD
pSqlProcedureSpec_start((START))
pSqlProcedureSpec_start --> pSqlProcedureSpec_0_0[PROCEDURE]:::quoted
pSqlProcedureSpec_0_0 --> pSqlProcedureSpec_0_1[pSqlVariableName]
pSqlProcedureSpec_0_1 --> pSqlProcedureSpec_0_2["("]:::quoted
pSqlProcedureSpec_0_2 --> pSqlProcedureSpec_0_3[pSqlArgumentList]
pSqlProcedureSpec_0_3 --> pSqlProcedureSpec_0_4[")"]:::quoted
pSqlProcedureSpec_0_4 --> pSqlProcedureSpec_0_5[AS]:::quoted
pSqlProcedureSpec_0_5 --> pSqlProcedureSpec_0_6[IS]:::quoted
pSqlProcedureSpec_0_6 --> pSqlProcedureSpec_0_7[pSqlBlockOptionalDeclare]
pSqlProcedureSpec_0_7 --> pSqlProcedureSpec_end((END))
```