【问题标题】:procedure or function '' expects parameter '' which was not supplied过程或函数''需要未提供的参数''
【发布时间】:2018-04-26 11:56:18
【问题描述】:

请问如何解决这个问题。消息错误是:

过程或函数“ROHAN_GetPKList”需要未提供的参数“@char_id”

我有SP

ALTER procedure [dbo].[ROHAN_GetPKList]
    @char_id    int
as      
set nocount on      
select top 100 k.pk_char_id,  c.[name], k.pk_char_type, k.pk_second, k.isKill, k.PKRecall, k.RecallRecharge, k.mode_type
    from TKill k, TCharacter c  
    where k.pk_char_id = c.[id] 
        and k.char_id = @char_id
        and c.[user_id] > 0
    order by k.[date]   

return @@error  

这是表'TKill'

    [char_id] [int] NOT NULL,
    [pk_char_id] [int] NOT NULL,
    [pk_char_type] [int] NOT NULL,
    [pk_second] [int] NOT NULL,
    [isKill] [tinyint] NOT NULL,
    [PKRecall] [tinyint] NOT NULL,
    [RecallRecharge] [tinyint] NOT NULL,
    [date] [smalldatetime] NOT NULL,
    [mode_type] [int] NOT NULL

这是表格'TCharacter'

    [id] [int] IDENTITY(1000,1) NOT NULL,
    [name] [nvarchar](20) NULL,
    [ctype_id] [int] NOT NULL,
    [cface_id] [int] NOT NULL,
    [chair_id] [int] NOT NULL,
    [user_id] [int] NOT NULL,
    [mode] [tinyint] NOT NULL,
    [create_date] [datetime] NOT NULL,
    [flag] [tinyint] NOT NULL,
    [cstyle_type] [tinyint] NOT NULL,
    [cstyle_index] [tinyint] NOT NULL,
    [world_id] [tinyint] NOT NULL,
    [reward_time] [int] NOT NULL,
    [isSelling] [int] NULL,
    [pvppoint] [int] NULL,
    [pvppointoa] [int] NULL,

【问题讨论】:

  • 向我们展示调用 proc 的代码。常见原因(以 ADO.NET API 为例)是 1) 未指定 CommandType.StoredProceedure,2) 未将具有该名称的参数添加到参数集合中,3) 参数值为 null(而不是 DBNull。值)。
  • 抱歉应用打包了,看不到源代码,但是出现错误信息,但是可以编辑数据库
  • 这似乎是应用程序问题,因此您需要联系作者。在服务器端,你不能单方面做很多事情。
  • 好的,谢谢回复

标签: sql sql-server sql-server-2008


【解决方案1】:

您的错误似乎是在调用过程时出现的,而不是在定义过程时出现的。但我建议将代码编写为:

alter procedure [dbo].[ROHAN_GetPKList] (
    @char_id    int  -- something called "char_id" with a type of "int" is strange
) as 
begin     
    set nocount on;  

    select top 100 k.pk_char_id, c.[name], k.pk_char_type, k.pk_second, k.isKill, k.PKRecall, k.RecallRecharge, k.mode_type
    from TKill k join
         TCharacter c  
         on k.pk_char_id = c.id
    where k.char_id = @char_id and c.user_id > 0
    order by k.[date]; 
    return @@error;
end;  -- ROHAN_GetPKList

注意BEGIN/END 的使用和正确的JOIN 语法。

【讨论】:

  • BEGINEND 包围 proc 主体是可选的和多余的。
  • @KwaranUngaranBarat 。 . .如果调用时没有提供默认值,您可以提供默认值。
  • 不能,因为调用时需要数据
猜你喜欢
  • 2011-02-05
  • 2013-01-24
  • 1970-01-01
  • 2018-06-22
相关资源
最近更新 更多