如何在H2中创建存储的Proc

时间:2019-03-05 11:31:03

标签: stored-procedures h2

我对Hibernate来说还很陌生。您能否在下面帮助我。我正在尝试在h2(在内存数据库中)中使用ALIAS创建存储过程。我已经在下面实现的基础上查看了h2数据库手册。

Java类:

    public class H2StoredProcedures {

          public static void load(Connection conn,String sql) {
               System.out.print("");
            //  File file = new File("src/test/resources/data/proc.sql");
              try {
                  conn.createStatement().execute(sql);
              } catch (SQLException e) {
                  e.printStackTrace();
              }
          }

当前我正在使用休眠版本:1.4.197。以下是h2引擎代码,正在调用java方法。

H2引擎(我有架构和表脚本的sql文件):

DROP ALIAS IF EXISTS PROC;
CREATE ALIAS PROC FOR "com.util.h2.H2StoredProcedures.load";
CALL PROC('CREATE OR REPLACE PROCEDURE procPrintHelloWorld
IS
BEGIN

  DBMS_OUTPUT.PUT_LINE(''Hello World!'');

END');

错误:

  

SQL语句“ CREATE OR REPLACE PROCEDURE [*]

”中的语法错误

完整错误消息:

org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "CREATE OR REPLACE PROCEDURE[*] LOADTEST (P_NAME IN VARCHAR2)
IS
BEGIN
DBMS_OUTPUT.PUT_LINE ('Welcome '|| P_NAME);
END; "; expected "FORCE, VIEW, ALIAS, SEQUENCE, USER, TRIGGER, ROLE, SCHEMA, CONSTANT, DOMAIN, TYPE, DATATYPE, AGGREGATE, LINKED, MEMORY, CACHED, LOCAL, GLOBAL, TEMP, TEMPORARY, TABLE, SYNONYM, PRIMARY, UNIQUE, HASH, SPATIAL, INDEX"; SQL statement:
CREATE OR REPLACE PROCEDURE LOADTEST (p_name IN VARCHAR2)
IS
BEGIN
dbms_output.put_line ('Welcome '|| p_name);
END; [42001-197]

0 个答案:

没有答案