In the SQL/PSM portion of the ISO standard, a MODULE is a top-level program unit that bundles related routines, user-defined types, global variables, cursors and exception handlers under a single namespace. Similar to a package in Oracle or a schema-bound library in other languages, a module helps you:- Separate application logic from table schemas- Avoid name collisions by introducing an extra qualifier (module_name.routine_name)- Grant or revoke EXECUTE privileges on all contained routines in one step- Version or deploy business logic as an atomic unitA module is created with CREATE MODULE, optionally specifying an AUTHORIZATION clause to set the definer and an implicit owner. Inside the module, you declare routines with the ordinary CREATE PROCEDURE / CREATE FUNCTION syntax but omit the schema prefix. Those internal objects become implicitly part of the module and can be referenced by external callers using the qualified name .. Modules live in the data dictionary like schemas. Dropping a module removes every contained object. Because MODULE is standardized but not universally implemented, behaviour details (such as whether a module can access objects outside itself by default, or whether variables persist across sessions) differ by vendor.
• module_name
(identifier) - Required name of the module.• AUTHORIZATION
(role name) - Optional. Owner that implicitly receives privileges on all contained objects.• LANGUAGE
(identifier) - Optional language of routines. Default is SQL.• Declarations block
- Optional BEGIN…END section for global variables, cursors or conditions.CREATE MODULE, DROP MODULE, PACKAGE (Oracle), SCHEMA, CREATE PROCEDURE, CREATE FUNCTION, SQL/PSM
SQL:1999 (SQL/PSM)
A schema groups database objects such as tables and views, while a module specifically groups programmatic objects like procedures, functions and variables. A module can live inside a schema.
No. Global variables declared in the module exist only for the duration of the session or routine that references them. Their lifetime is not permanent like table data.
Yes. GRANT EXECUTE ON MODULE module_name TO role grants the privilege on every contained procedure and function in compliant databases like Db2.
Use DROP MODULE module_name; only after confirming that external applications no longer depend on its routines, because the command deletes all contained objects.