存储过程和游标问题提问?

blackicewolf 2002-11-08 04:40:39
执行存储过程出错:
服务器: 消息 2801,级别 16,状态 1,过程 GetRMSysData,行 107
对象 'GetRMSysData' 的定义在编译后已有更改。

什么意思?'GetRMSysData' 是存储过程的名字,107行是最后一行

另:存储过程里有游标,提示:
服务器: 消息 16915,级别 16,状态 1,过程 GetRMSysData,行 15
名为 'date_cursor' 的游标已存在。
但我在程序后面有关闭和释放游标啊
...全文
74 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
blackicewolf 2002-11-11
  • 打赏
  • 举报
回复
以下是代码,估计没人有耐心看完吧


----------该存储过程用于生成T_RMSysData表的数据-----------------

CREATE PROCEDURE GetRMSysData
AS
declare @date datetime,@class char(1),@booked int,@noshow int,@goshow1 int,@goshow2 int,@goshow21 int,@goshow22 int,@actual int,@ActualbyClass int,@BookedbyClass int
declare @datenum int,@flightnum int,@fln char(4),@upgrade int,@missconnection int,@denied int
declare @origin char(3),@destination char(3),@pnr varchar(6),@flytime char(5)
declare @datetime datetime,@datetime1 datetime,@datetime2 datetime

create table #tb1(class char(1),booked int,noshow int,goshow1 int,goshow2 int,actual int)

--------以下根据日期定义游标----------------

declare date_cursor cursor for select distinct fdt from cj_pnrp
open date_cursor -----打开游标
fetch next from date_cursor into @date ------从游标取出日期
while @@fetch_status=0 ------循环
begin
----------------以下根据航班号定义游标---------------------------

declare fln_cursor cursor for select distinct fln from cj_pnrp where fdt=@date
open fln_cursor --------打开游标
fetch next from fln_cursor into @fln --------从游标取出航班号
while @@fetch_status=0 --------循环
begin
declare od_cursor cursor for select distinct bpt,opt from cj_pnrp where fdt=@date and fln=@fln
open od_cursor
fetch next from od_cursor into @origin,@destination
while @@fetch_status=0
begin
select @flytime=left(StartTime,2)+':'+right(StartTime,2) from t_zhflight where flight=@fln and startcity=@origin and endcity=@destination
select @datetime=@date+' '+@flytime
select @datetime1=dateadd(mi,-90,@datetime) -----飞机离港前90分钟
select @datetime2=dateadd(mi,-30,@datetime) -----飞机离港前30分钟

declare class_cursor cursor for select distinct idp from cj_pnrp where fdt=@date and fln=@fln
open class_cursor
fetch next from class_cursor into @class
while @@fetch_status=0
begin
declare pnr_cursor cursor for select distinct ipn from cj_pnrp where fdt=@date and fln=@fln and bpt=@origin and opt=@destination and idp=@class
open pnr_cursor
fetch next from pnr_cursor into @pnr
while @@fetch_status=0
begin

---------------以下剔除bidt表里面的重复数据------------------------------

if exists(select * from Tempdb..sysobjects where id=object_id( 'tempdb..#tmp') and type='U')
drop table #tmp
set nocount on
select top 1 * into #tmp from bidt where flydate=@date and flight=@fln and seatclass=@class and startcity=@origin and endcity=@destination and recordno=@pnr

--------统计定座数
select @BookedbyClass=count(*) from #tmp where flydate=@date and seatclass=@class and flight=@fln and issuedate<=@datetime1 ----各舱位定座数
select @booked=count(*) from #tmp where flydate=@date and flight=@fln and issuedate<=@datetime1 ----总定座数

-------统计GOSHOW2数据(其中@goshow21是航班结载前90~30的数据;@goshow22是航班结载前30内的数据,两部分的和就是GOSHOW2数据)
select @goshow21=count(*) from #tmp where flydate=@date and seatclass=@class and flight=@fln and issuedate>@datetime1 and issuedate<=@datetime2
if exists(select * from T_RMSysData where flydate=@date and class=@class and planeno=@fln)
select @goshow22=goshow2,@goshow1=goshow1,@upgrade=upgrading,@missconnection=missconnect,@denied=denied from T_RMSysData where flydate=@date and class=@class and planeno=@fln
else
select @goshow22=0,@goshow1=0,@upgrade=0,@missconnection=0, @denied=0
select @goshow2=@goshow21+@goshow22

---------统计实际承运人数
select @ActualbyClass=count(*) from cj_pnrp where fdt=@date and fln=@fln and idp=@class -----各舱位人数
select @actual=count(*) from cj_pnrp where fdt=@date and fln=@fln -----总人数

--------统计NOSHOW数据--------------
select @noshow=@goshow1+@goshow2+@booked-@actual

set nocount on
insert into #tb1 values(@class,@bookedbyClass,@noshow,@goshow1,@goshow2,@actualbyClass)

fetch next from pnr_cursor into @pnr
end
close pnr_cursor
deallocate pnr_cursor

fetch next from class_cursor into @class
end
close class_cursor
deallocate class_cursor

fetch next from od_cursor into @origin,@destination
end
close od_cursor
deallocate od_cursor

---------取下个航班号
fetch next from fln_cursor into @fln
end
close fln_cursor -----------关闭航班号游标
deallocate fln_cursor -----------释放航班号游标

-------取出下一个日期

fetch next from date_cursor into @date
end

set nocount off
select * from #tb1

close date_cursor ----------关闭日期游标
deallocate date_cursor ----------释放日期游标
GO
lyyrw 2002-11-11
  • 打赏
  • 举报
回复
太长了,我只看了大概,语法没什么问题
1.服务器: 消息 2801,级别 16,状态 1,过程 GetRMSysData,行 107
对象 'GetRMSysData' 的定义在编译后已有更改。
你看看你所定义的参数在赋予值时类型是否相一致;

2.服务器: 消息 16915,级别 16,状态 1,过程 GetRMSysData,行 15
名为 'date_cursor' 的游标已存在。
改个名试试。
tombaby 2002-11-10
  • 打赏
  • 举报
回复
有以下可能
1、游标未关闭和释放的情况下又执行了游标(大多数是这样)当用完游标时应关闭和释放,摸板如下
DECLARE CURNAME CURSOR FOR ...
OPEN CURNAME
//其他语句
CLOSE CURNAME
DEALLOCATE CURNAME

2、存储过程的游标名和触发器的游标名相同了(情况较少)
该成不同的游标名
注:如果满意要给分呀!
blackicewolf 2002-11-09
  • 打赏
  • 举报
回复
楼上两位,代码很长,估计你们也没耐心看吧
如果有的话我就帖
pengdali 2002-11-09
  • 打赏
  • 举报
回复
你肯定是代码有误!贴出看看!!!
AlphaII 2002-11-08
  • 打赏
  • 举报
回复
paste the source code

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧