gpt4 book ai didi

mysql - SQL Server 存储过程到 MySQL

转载 作者:行者123 更新时间:2023-11-29 15:25:04 25 4
gpt4 key购买 nike

我需要将SQL Server存储过程转换为MySQL,找到了这个工具:http://www.sqlines.com/online但转换后,工作台给我一个错误,其中的 DELIMITER 表示它在此位置无效:创建预期的。

不幸的是,SQL Server 数据库无法迁移,因此我需要转换此过程的整个代码 - 有没有简单的方法来转换此代码,或者有人知道为什么我会收到 DELIMITER 错误吗?

        DELIMITER //

CREATE PROCEDURE CreateQuestionnairForCourse (

p_courseId bigint,
p_openDate bigint /* = 1573884000 */, -- 16 Nov 2019
p_closeDate bigint /* = 1575150900 */, -- 30 Nov 2019

p_servey_etalon bigint /* =20 */, -- Greek English together
p_questionnair_etalon bigint/* =20 */)

sp_lbl:

BEGIN
DECLARE NOT_FOUND INT DEFAULT 0;
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.


DECLARE v_surveyId bigint;
DECLARE v_questionnairId bigint;
DECLARE v_courseModuleId bigint;
DECLARE v_sequence longtext;
DECLARE v_section bigint;
DECLARE v_added bigint;
DECLARE v_questionId bigint;
DECLARE v_new_questionId bigint;
DECLARE v_IsVisible tinyint DEFAULT 1

declare curs cursor local;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET NOT_FOUND = 1;;


if p_courseId = 0 then
LEAVE sp_lbl;
end if;
ELSE

DECLARE v_UnixTS bigint DEFAULT [dbo].[DTtoUnixTS](NOW());

BEGIN TRAN T1;

INSERT INTO mdl_questionnaire_survey
(
`name`,
`courseid`,
`realm`,
`status`,
`title`,
`email`,
`subtitle`,
`info`,
`theme`
)
SELECT
name,
p_courseId,
'private',
`status`,
title,
email,
subtitle,
info,
theme
FROM mdl_questionnaire_survey
WHERE id = p_servey_etalon;

SET v_surveyId = LAST_INSERT_ID();

INSERT INTO mdl_questionnaire
(`course`,
`name`,
intro,
`qtype` ,
`respondenttype`,
`resp_eligible`,
`resp_view`,
`opendate`,
`closedate`,
`resume`,
`navigate`,
`grade`,
`sid`
)
Select
p_courseId,
name,
intro,
qtype,respondenttype,
resp_eligible,
resp_view,
p_openDate,
p_closeDate,
resume,
navigate,
grade,
v_surveyId
FROM mdl_questionnaire
WHERE id=p_questionnair_etalon;

SET v_questionnairId = LAST_INSERT_ID();

fast_forward for
select id
FROM `mdl_questionnaire_question`
where deleted='n' and survey_id=p_servey_etalon
open curs;
fetch next from; curs into v_questionId

while Not_found = 0
do


INSERT INTO mdl_questionnaire_question (survey_id,name ,type_id,result_id,`length`,`precise`,`position` ,`content` ,`required` ,`deleted`)
SELECT v_surveyId,`name`,`type_id` ,`result_id`,`length`,`precise`,`position` ,`content` ,`required` ,`deleted`
FROM mdl_questionnaire_question where id = v_questionId;

SET v_new_questionId = LAST_INSERT_ID();


INSERT INTO mdl_questionnaire_quest_choice
SELECT v_new_questionId
,`content`
,`value`
FROM mdl_questionnaire_quest_choice where question_id = v_questionId;

fetch next from; curs into v_questionId
end while;

CLOSE curs;


SELECT TOP 1 id INTO v_section from mdl_course_sections where course=p_courseId
ORDER By id ASC;

INSERT INTO mdl_course_modules
(
course,
module,
instance,
section,
idnumber,
added,
score,
indent,
visible,
visibleold,
groupmode,
groupingid,
-- groupmembersonly,
completion,
completionview,
completionexpected,
`showdescription`,
`availability`
)
VALUES (
p_courseId,
23,
v_questionnairId,
v_section,
0,
0,
0,
0,
v_IsVisible,
v_IsVisible,
0,
0,
-- 0,
0,
0,
0,
0,
''
);

SET v_courseModuleId = LAST_INSERT_ID();

SELECT sequence INTO v_sequence from mdl_course_sections where id = v_section;

if v_sequence = '' then
SET v_sequence = CAST(v_courseModuleId as varchar(1));
ELSE
SET v_sequence = Concat(v_sequence , ',' , CAST(v_courseModuleId as varchar(1)));
end if; -- COLLATE DATABASE_DEFAULT

UPDATE mdl_course_sections
SET sequence = v_sequence
WHERE id=v_section;



UPDATE mdl_course
SET cacherev = (;CASE
WHEN cacherev IS NULL THEN v_UnixTS
WHEN cacherev < v_UnixTS THEN v_UnixTS
WHEN cacherev > v_UnixTS + 3600 THEN v_UnixTS
ELSE cacherev + 1 END) WHERE id = p_courseId


COMMIT; T1;

END;

END IF;
//

DELIMITER ;

最佳答案

在我看来,问题出在代码中的注释。可能是转换工具无法处理/* = Whatewer.. */

此外,在根据建议进行转换后重构代码 - varchar(1) 始终是一个坏主意...在您的情况下,它可能也是错误的,因为我预计类(class)模块将比从 int 转换的 1 个字符长。 ..

关于mysql - SQL Server 存储过程到 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59137486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com