程序返回'光标已关闭'

时间:2014-10-09 14:01:44

标签: sql oracle stored-procedures plsql cursor

我正在编写关于获取票证列表的存储过程。我想控制我的输入参数null或不为null我曾经如果elsif例如第一个输入(用户名)是null而第二个输入(ticketid)可以为null然后第三个输入(userid)必须是非NULL当我执行此程序,它将直接结束我得到“光标已关闭”错误。

create or replace 
PROCEDURE "TICKETLISTSEARCH" 
(
  p_UserName VARCHAR2,
  p_TicketID NUMBER,
  p_UserID NUMBER, 
  p_Cursor OUT SYS_REFCURSOR
) AS 
BEGIN
-- TicketID değeri dolu olan aramalarda
if (p_UserName = '' AND p_TicketID <> 0 AND  p_UserID = 0) THEN
IF NOT p_Cursor%ISOPEN THEN
OPEN p_Cursor FOR
SELECT TicketID
      ,CreateDate
      ,dateStart
      ,DealerUser
      ,(select UserID from ProductUser where UserID = T.NextUser) as UserID
      ,case when NextUser = 0 then 'ATAMA YOK' else (select UserName from Users where UserID = T.NextUser) END as FollowUser
      ,case when StatusID = 0 then 'Durum Bilgisi Girilmemiş' else (select Name from Status where StatusID = T.StatusID) END as Status
      ,P.Name as Product
      ,case when T.TalepID = 0 then 'Talep Türü Belirtilmemiş ' else (select Name from Talepler where TalepID = T.TalepID) END as Talep
      ,T.StatusID
      ,T.ProductID
      ,T.TalepID
      ,Title
      ,Explanation
      ,DateClose
  FROM Ticket T
  inner join Product P on (T.ProductID = P.ProductID)
--  inner join Status S on (T.StatusID = S.StatusID)
--  inner join Users U on (U.UserID = T.NextUser)
  WHERE
  T.TicketID = p_TicketID and T.StatusID not in (8)
  ORDER BY T.TicketID DESC;

END IF;
-- UserID değeri 0 olan kayıtları getir.
elsif (p_UserName = '' AND p_TicketID = 0 AND p_UserID <> 0) THEN
IF NOT p_Cursor%ISOPEN THEN
OPEN p_Cursor FOR
SELECT TicketID
      ,CreateDate
      ,dateStart
      ,DealerUser
      ,(select UserID from ProductUser where UserID = T.NextUser) as UserID
      ,case when NextUser = 0 then 'ATAMA YOK' else (select UserName from Users where UserID = T.NextUser) END as FollowUser
      ,case when StatusID = 0 then 'Durum Bilgisi Girilmemiş' else (select Name from Status where StatusID = T.StatusID) END as Status
      ,P.Name as Product
      ,case when T.TalepID = 0 then 'Talep Türü Belirtilmemiş ' else (select Name from Talepler where TalepID = T.TalepID) END as Talep
      ,T.StatusID
      ,T.ProductID
      ,T.TalepID
      ,Title
      ,Explanation
      ,DateClose
  FROM Ticket T
--  inner join Talepler TT on (T.TalepID=TT.TalepID)
  inner join Product P on (T.ProductID = P.ProductID)
--  inner join Status S on (T.StatusID = S.StatusID)
 -- inner join ProductUsers PU on (PU.UserID = T.NextUser)
  WHERE
  T.NextUser = p_UserID and T.StatusID not in (8)
  ORDER BY T.TicketID DESC;
END IF;

else dbms_output.put_line('HATA');
END IF;
END TICKETLISTSEARCH;

0 个答案:

没有答案