如何在SQL Developer中执行SQL Server存储过程?

发布于 2024-10-01 13:44:37 字数 512 浏览 7 评论 0原文

我获得了一个 SQL Server 数据库的用户帐户,该帐户仅具有执行存储过程的权限。我将 JTDS SQL Server JDBC jar 文件添加到 SQL Developer 中,并将其添加为第三方 JDBC 驱动程序。我可以成功登录SQL Server数据库。我得到了运行该过程的语法:

EXEC proc_name 'paramValue1' 'paramValue2'

当我将其作为语句或脚本运行时,我收到此错误:

Error starting at line 1 in command:
EXEC proc_name 'paramValue1' 'paramValue2'
Error report:
Incorrect syntax near the keyword 'BEGIN'.

我尝试将语句包装在 BEGIN/END 中,但收到相同的错误。是否可以从 SQL Developer 调用该过程?如果是这样,我需要使用什么语法?

I've been given a user account to a SQL Server database that only has privileges to execute a stored procedure. I added the JTDS SQL Server JDBC jar file to SQL Developer and added it as a Third Party JDBC driver. I can successfully log in to the SQL Server database. I was given this syntax for running the procedure:

EXEC proc_name 'paramValue1' 'paramValue2'

When I run this as either a statement or a script, I get this error:

Error starting at line 1 in command:
EXEC proc_name 'paramValue1' 'paramValue2'
Error report:
Incorrect syntax near the keyword 'BEGIN'.

I tried wrapping the statement in BEGIN/END, but get the same error. Is it possible to call the procedure from SQL Developer? If so, what syntax do I need to use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

娇柔作态 2024-10-08 13:44:37

您不需要 EXEC 子句。只需使用

proc_name paramValue1, paramValue2

(并且您需要逗号,如误称)

You don't need EXEC clause. Simply use

proc_name paramValue1, paramValue2

(and you need commas as Misnomer mentioned)

幽梦紫曦~ 2024-10-08 13:44:37

您缺少 ,

EXEC proc_name 'paramValue1','paramValue2'

You are missing ,

EXEC proc_name 'paramValue1','paramValue2'
演出会有结束 2024-10-08 13:44:37

你需要这样做:

exec procName 
@parameter_1_Name = 'parameter_1_Value', 
@parameter_2_name = 'parameter_2_value',
@parameter_z_name = 'parameter_z_value'

You need to do this:

exec procName 
@parameter_1_Name = 'parameter_1_Value', 
@parameter_2_name = 'parameter_2_value',
@parameter_z_name = 'parameter_z_value'
难理解 2024-10-08 13:44:37
EXECUTE [or EXEC] procedure_name
@parameter_1_Name = 'parameter_1_Value', 
@parameter_2_name = 'parameter_2_value',
@parameter_z_name = 'parameter_z_value'
EXECUTE [or EXEC] procedure_name
@parameter_1_Name = 'parameter_1_Value', 
@parameter_2_name = 'parameter_2_value',
@parameter_z_name = 'parameter_z_value'
深爱不及久伴 2024-10-08 13:44:37

您需要在 paramValue1 和 paramValue2 之间添加 ,。你错过了。

EXEC proc_name 'paramValue1','paramValue2'

You need to add a , between the paramValue1 and paramValue2. You missed it.

EXEC proc_name 'paramValue1','paramValue2'
哥,最终变帅啦 2024-10-08 13:44:37

我知道这是旧的。但这可能对其他人有帮助。

我在BEGIN/END之间添加了SP调用功能。这是一个工作脚本。

ALTER Proc [dbo].[DepartmentAddOrEdit]
@Id int,
@Code varchar(100),
@Name varchar(100),
@IsActive bit ,
@LocationId int,
@CreatedBy int,
@UpdatedBy int
AS
    IF(@Id = 0)

    BEGIN
    INSERT INTO Department (Code,Name,IsActive,LocationId,CreatedBy,UpdatedBy,CreatedAt)
        VALUES(@Code,@Name,@IsActive,@LocationId,@CreatedBy,@UpdatedBy,CURRENT_TIMESTAMP)

    EXEC dbo.LogAdd @CreatedBy,'DEPARTMENT',@Name
    END

    ELSE

    UPDATE Department SET
        Code = @Code,
        Name = @Name,
        IsActive = @IsActive,
        LocationId = @LocationId,
        CreatedBy = @CreatedBy,
        UpdatedBy = @UpdatedBy,
        UpdatedAt =  CURRENT_TIMESTAMP 
    where Id = @Id 

I know this is the old one. But this may help others.

I have added SP calling function between BEGIN/END. Here is a working script.

ALTER Proc [dbo].[DepartmentAddOrEdit]
@Id int,
@Code varchar(100),
@Name varchar(100),
@IsActive bit ,
@LocationId int,
@CreatedBy int,
@UpdatedBy int
AS
    IF(@Id = 0)

    BEGIN
    INSERT INTO Department (Code,Name,IsActive,LocationId,CreatedBy,UpdatedBy,CreatedAt)
        VALUES(@Code,@Name,@IsActive,@LocationId,@CreatedBy,@UpdatedBy,CURRENT_TIMESTAMP)

    EXEC dbo.LogAdd @CreatedBy,'DEPARTMENT',@Name
    END

    ELSE

    UPDATE Department SET
        Code = @Code,
        Name = @Name,
        IsActive = @IsActive,
        LocationId = @LocationId,
        CreatedBy = @CreatedBy,
        UpdatedBy = @UpdatedBy,
        UpdatedAt =  CURRENT_TIMESTAMP 
    where Id = @Id 
最丧也最甜 2024-10-08 13:44:37
EXEC proc_name @paramValue1 = 0, @paramValue2 = 'some text';
GO

如果存储过程的目标是在声明了 Identity 字段的表上执行 INSERT,则应声明该字段(在本例中为 @paramValue1),然后将其传递给值 0,因为它会自动递增。

EXEC proc_name @paramValue1 = 0, @paramValue2 = 'some text';
GO

If the Stored Procedure objective is to perform an INSERT on a table that has an Identity field declared, then the field, in this scenario @paramValue1, should be declared and just pass the value 0, because it will be auto-increment.

关于从前 2024-10-08 13:44:37
--worked for me in sql 5.731
--use db;
call procedureName;
--worked for me in sql 5.731
--use db;
call procedureName;
七秒鱼° 2024-10-08 13:44:37

我们可以通过两种方式调用存储过程

  1. CALL 数据库名称'。 '存储过程名称(参数值);
    示例:- 调用dbs_nexopay_sisd1_dec_23spr_v2_invoice_details_for_invoice_receipt_sub_swiss(1, 1, 1, 1);

  2. 从您的 MySQL 工作台您也可以做到这一点。
    我。右键单击存储过程。
    二.发送到 SQL 编辑器
    三.过程调用。

There are two ways we can call stored procedure

  1. CALL database name'. 'stored procedure name(parameter values);
    example:- CALL dbs_nexopay_sisd1_dec_23.spr_v2_invoice_details_for_invoice_receipt_sub_swiss(1, 1, 1, 1);

  2. From your MySQL workbench also you can do that.
    i. Right-click on stored procedure.
    ii. Send to SQL editor
    iii. Procedure call.

一江春梦 2024-10-08 13:44:37

如果您只需要执行存储过程
proc_name 'paramValue1', 'paramValue2'...
同时您正在执行多个查询,例如一个选择查询和存储过程,您必须添加
从表名中选择*
EXEC proc_name paramValue1,paramValue2...

If you simply need to excute your stored procedure
proc_name 'paramValue1' , 'paramValue2'...
at the same time you are executing more than one query like one select query and stored procedure you have to add
select * from tableName
EXEC proc_name paramValue1 , paramValue2...

南风几经秋 2024-10-08 13:44:37

存储过程可以使用以下语法

BEGIN 在 sql Developer 工具中运行
程序名();
结尾;

如果有任何参数,则必须传递它。

The stored procedures can be run in sql developer tool using the below syntax

BEGIN
procedurename();
END;

If there are any parameters then it has to be passed.

冷默言语 2024-10-08 13:44:37
Select * from Table name ..i.e(are you save table name in sql(TEST) k.

Select * from TEST then you will execute your project.
Select * from Table name ..i.e(are you save table name in sql(TEST) k.

Select * from TEST then you will execute your project.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文