【问题标题】:Java Stored proc giving an errorJava Stored proc给出错误
【发布时间】:2017-06-27 11:09:21
【问题描述】:

我正在尝试通过以下方式创建存储过程:

DROP procedure IF EXISTS plus1inout
/;
CREATE procedure plus1inout (IN arg int, OUT res int)
BEGIN ATOMIC
    set res = arg + 1;
END
/;

我收到以下错误:

Msg 156, Level 15, State 1.
Incorrect syntax near the keyword 'IF'.
Msg 156, Level 15, State 1.
Incorrect syntax near the keyword 'IN'. (Line 3)

【问题讨论】:

  • 这不是Sql Server 语法
  • 提示:create or replace procedure.
  • 您使用的是 Oracle 语法,但错误消息肯定来自 Ms Sql-server。检查您是否连接到正确的服务器

标签: sql oracle java-stored-procedures


【解决方案1】:

您的语法在 sql server 中无效。

使用object_id函数检查是否存在

IF OBJECT_ID('plus1inout', 'P') IS NOT NULL
    DROP PROCEDURE plus1inout

对于输入参数,您不必提及IN 关键字。对于OUTPUT 参数,在末尾使用关键字OUTSql Server中的参数也以@开头

CREATE PROCEDURE Plus1inout (@arg INT,
                             @res INT output)
AS
  BEGIN
      SET @res = @arg + 1;
  END 

SQL SERVER 2016 中,他们介绍了您用于检查过程是否存在的语法

DROP procedure IF EXISTS plus1inout

【讨论】:

    【解决方案2】:

    几件事。那个“/”来自oracle。如果你愿意,你可以使用GO这个词。要检查是否存在:您使用以下代码:

    IF OBJECT_ID('plus1inout', 'P') IS NOT NULL
            DROP PROC plus1inout
    GO
    

    然后创建过程。 在创建中,参数声明错误。

    CREATE procedure plus1inout (@arg int, @res int out)
    BEGIN ATOMIC
        set @res = @arg + 1;
    END;
    

    【讨论】:

    • 参数列表中的IN也不是sql-server。您可能还会提到
    • CREATE PROC 应该是什么样子
    • 取决于它是 oracle 还是 sql-server 或其他数据库
    猜你喜欢
    • 1970-01-01
    • 2012-01-23
    • 2015-07-08
    • 2020-08-10
    • 2020-05-25
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多