DBから取得したデータを1つの変数に格納してJavaコードに戻そうとしています。カーソルを使用する場合のSQL Serverプロシージャ内の変数の範囲
NULL値を戻しています。これは、カーソル内の変数の範囲のためです。誰もそれのためのソリューションを提案することはできますか?ここで
私の手順です:
ALTER PROCEDURE [dbo].[rml_ups_profilerscheduler] @RuleIds varchar(200) output
-- Add the parameters for the stored procedure here
--<@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>,
--<@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @rulescheduleid varchar(50), @scheduletype varchar(50),@finalop varchar(50)
DECLARE cursorName CURSOR GLOBAL
FOR
select distinct rulescheduleid,scheduletype
from rml_ups_ruleschedulemaster
OPEN cursorName -- open the cursor
FETCH NEXT FROM cursorName
INTO @rulescheduleid, @scheduletype
set @finalop=''
if(lower(@scheduletype) ='daily')
set @[email protected]+','+(SELECT CONVERT(varchar(150),
(select ruleid from rml_ups_ruleschedulemaster a,rml_ups_rulescheduletimemapping b
where a.rulescheduleid=b.rulescheduleid and b.schedulestarthour <= (SELECT DATEPART(hh, GETDATE()))
and scheduleendhour >=(SELECT DATEPART(hh, GETDATE()))
and a.rulescheduleid=1)))
-- PRINT @rulescheduleid + ' ' + @scheduletype -- print the name
if(lower(@scheduletype) ='weekly')
set @[email protected]+','+(SELECT CONVERT(varchar(150),
(select ruleid from rml_ups_ruleschedulemaster a,rml_ups_rulescheduletimemapping b
where a.rulescheduleid=b.rulescheduleid and b.schedulestarthour <= (SELECT DATEPART(hh, GETDATE()))
and scheduleendhour >=(SELECT DATEPART(hh, GETDATE())) and a.scheduledayofweek =(SELECT DATEPART(dw, GETDATE()))
and [email protected])))
if(lower(@scheduletype) ='monthly')
set @[email protected]+','+(SELECT CONVERT(varchar(150),
(select ruleid from rml_ups_ruleschedulemaster a,rml_ups_rulescheduletimemapping b
where a.rulescheduleid=b.rulescheduleid and b.schedulestarthour <= (SELECT DATEPART(hh, GETDATE()))
and scheduleendhour >=(SELECT DATEPART(hh, GETDATE())) and a.scheduledayofmonth =(SELECT DATEPART(dd, GETDATE()))
and [email protected])))
if(lower(@scheduletype) ='yearly')
set @[email protected]+','+(SELECT CONVERT(varchar(150),
(select ruleid from rml_ups_ruleschedulemaster a,rml_ups_rulescheduletimemapping b
where a.rulescheduleid=b.rulescheduleid and b.schedulestarthour <= (SELECT DATEPART(hh, GETDATE()))
and scheduleendhour >=(SELECT DATEPART(hh, GETDATE())) and a.scheduledayofmonth =(SELECT DATEPART(dd, GETDATE())) and
a.schedulemonth=(SELECT DATEPART(mm, GETDATE()))
and [email protected])))
if(lower(@scheduletype) ='on at time')
set @[email protected]+','+(SELECT CONVERT(varchar(150),
(select ruleid from rml_ups_ruleschedulemaster a,rml_ups_rulescheduletimemapping b
where a.rulescheduleid=b.rulescheduleid and b.schedulestarthour <= (SELECT DATEPART(hh, GETDATE()))
and scheduleendhour >=(SELECT DATEPART(hh, GETDATE())) and a.scheduledayofmonth =(SELECT DATEPART(dd, GETDATE()))
and schedulemonth=(SELECT DATEPART(mm, GETDATE())) and
a.scheduleyear=(SELECT DATEPART(yy, GETDATE()))
and [email protected])))
--PRINT @rulescheduleid + ' ' + @scheduletype -- print the name
--PRINT @@FETCH_STATUS
WHILE @@FETCH_STATUS = 0
BEGIN
---PRINT @@FETCH_STATUS
FETCH NEXT FROM cursorName
INTO @rulescheduleid, @scheduletype
if(lower(@scheduletype) ='daily')
set @[email protected]+','+(SELECT CONVERT(varchar(150),
(select ruleid from rml_ups_ruleschedulemaster a,rml_ups_rulescheduletimemapping b
where a.rulescheduleid=b.rulescheduleid and b.schedulestarthour <= (SELECT DATEPART(hh, GETDATE()))
and scheduleendhour >=(SELECT DATEPART(hh, GETDATE()))
and [email protected])))
-- PRINT @rulescheduleid + ' ' + @scheduletype -- print the name
if(lower(@scheduletype) ='weekly')
set @[email protected]+','+(SELECT CONVERT(varchar(150),
(select ruleid from rml_ups_ruleschedulemaster a,rml_ups_rulescheduletimemapping b
where a.rulescheduleid=b.rulescheduleid and b.schedulestarthour <= (SELECT DATEPART(hh, GETDATE()))
and scheduleendhour >=(SELECT DATEPART(hh, GETDATE())) and a.scheduledayofweek =(SELECT DATEPART(dw, GETDATE()))
and [email protected])))
if(lower(@scheduletype) ='monthly')
set @[email protected]+','+(SELECT CONVERT(varchar(150),
(select ruleid from rml_ups_ruleschedulemaster a,rml_ups_rulescheduletimemapping b
where a.rulescheduleid=b.rulescheduleid and b.schedulestarthour <= (SELECT DATEPART(hh, GETDATE()))
and scheduleendhour >=(SELECT DATEPART(hh, GETDATE())) and a.scheduledayofmonth =(SELECT DATEPART(dd, GETDATE()))
and [email protected])))
if(lower(@scheduletype) ='yearly')
set @[email protected]+','+(SELECT CONVERT(varchar(150),
(select ruleid from rml_ups_ruleschedulemaster a,rml_ups_rulescheduletimemapping b
where a.rulescheduleid=b.rulescheduleid and b.schedulestarthour <= (SELECT DATEPART(hh, GETDATE()))
and scheduleendhour >=(SELECT DATEPART(hh, GETDATE())) and a.scheduledayofmonth =(SELECT DATEPART(dd, GETDATE())) and
a.schedulemonth=(SELECT DATEPART(mm, GETDATE()))
and [email protected])))
if(lower(@scheduletype) ='on at time')
set @[email protected]+','+(SELECT CONVERT(varchar(150),
(select ruleid from rml_ups_ruleschedulemaster a,rml_ups_rulescheduletimemapping b
where a.rulescheduleid=b.rulescheduleid and b.schedulestarthour <= (SELECT DATEPART(hh, GETDATE()))
and scheduleendhour >=(SELECT DATEPART(hh, GETDATE())) and a.scheduledayofmonth =(SELECT DATEPART(dd, GETDATE()))
and schedulemonth=(SELECT DATEPART(mm, GETDATE())) and
a.scheduleyear=(SELECT DATEPART(yy, GETDATE()))
and [email protected])))
PRINT @finalop
set @[email protected]
PRINT @RuleIds
-- print the name
END
--set @[email protected]
--PRINT @RuleIds
CLOSE cursorName
-- close the cursor
--PRINT @RuleIds
DEALLOCATE cursorName
-- Deallocate the cursor
END
カーソルが必要かどうかについての良い点は、常に言及する価値は+1です。 –
私は私のコードを変更しましたプロシージャはエラーなしで実行されていますが、ループの終わりに(condititinsに基づいてデータベースからretrived)変数にasaignedループが完了した後に空になっています私の変更されたコード – ameenulla