Defines the definition for a stored procedure. This command is better to use for creating procedures than the raw SQL command because it will not attempt to strip comments or break up lines.

Often times it is best to use the CREATE OR REPLACE syntax along with setting runOnChange=’true’ on the enclosing changeset tag. That way if you need to make a change to your procedure you can simply change your existing code rather than creating a new REPLACE PROCEDURE call. The advantage to this approach is that it keeps your change log smaller and allows you to more easily see what has changed in your procedure code through your source control system’s diff command.

Available attributes

Name Description Required for Supports
catalogName Name of the catalog all
comments all
dbms Logical expression of database type(s) on which the change must be applied. Valid database type names are listed on the supported databases page. It can be a comma separated list of multiple databases. Or You can also specify that a change is NOT applicable to a particular database type by prefixing with !. The keywords all and none are also available. all
encoding Encoding used in the file defined in the `path` attribute all
path File containing the procedure text. Either this attribute or a nested procedure text is required. all all
procedureText The SQL creating the procedure. Either this or the path attribute needs to be defined. all all
procedureName Name of the procedure. Required if replaceIfExists = true mssql
relativeToChangelogFile Whether the file path relative to the root changelog file rather than to the classpath. all
replaceIfExists If the stored procedure defined by procedureName already exits alter it instead of creating it. mssql
schemaName Name of the schema all

XML example

<changeSet  author="liquibase-docs"  id="createProcedure-example">  
    <createProcedure  catalogName="cat"  
            comments="A String"  
            dbms="h2, !oracle, mysql"  
            schemaName="public">CREATE OR REPLACE PROCEDURE testHello
      DBMS_OUTPUT.PUT_LINE('Hello From The Database!');

YAML example

  id:  createProcedure-example  
  author:  liquibase-docs  
  -  createProcedure:  
      catalogName:  cat  
      comments:  A String  
      dbms:  h2, !oracle, mysql  
      encoding:  UTF-8  
      path:  com/example/my-logic.sql  
      procedureText:  |-  
              DBMS_OUTPUT.PUT_LINE('Hello From The Database!');  
      procedureName: new_customer  
      relativeToChangelogFile: true  
      replaceIfExists: false  
      schemaName: public

JSON example

{  "changeSet":  {  "id":  "createProcedure-example",  "author":  "liquibase-docs",  "changes":  [  {  "createProcedure":  {  "catalogName":  "cat",  "comments":  "A String",  "dbms":  "h2, !oracle, mysql",  "encoding":  "UTF-8",  "path":  "com/example/my-logic.sql",  "procedureText":  "CREATE OR REPLACE PROCEDURE testHello\n    IS\n    BEGIN\n      DBMS_OUTPUT.PUT_LINE('Hello From The Database!');\n    END;",  "procedureName":  "new_customer",  "relativeToChangelogFile":  true,  "replaceIfExists":  false,  "schemaName":  "public"  }  }]  }  }

Database support

Database Notes Auto rollback
DB2/LUW Supported No
DB2/z Supported No
Derby Supported No
Firebird Supported No
H2 Supported No
HyperSQL Supported No
INGRES Supported No
Informix Supported No
MariaDB Supported No
MySQL Supported No
Oracle Supported No
PostgreSQL Supported No
SQL Server Supported No
SQLite Supported No
Sybase Supported No
Sybase Anywhere Supported No