我正在尝试在命令行或 MySql Workbench 编辑器中创建一个存储过程。
在 Mysql WOrkbench 中我没有任何消息,没有成功也没有错误,但是没有创建过程。在命令行中 mysql --host=localhost ... < procedure-script.sql
我收到以下错误:
ERROR 1064 (42000) at line 4: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER' at line 28
第 28 行实际上是空的,但我猜它指的是最后的 DELIMITER ;
在第 31 行。这是完整的代码:
DELIMITER $$;
-- drop procedure if exists updPages$$
CREATE PROCEDURE updPages()
BEGIN
DECLARE _post_id INTEGER;
DECLARE cur_pages CURSOR FOR
select ID
from wp_posts
where post_type='page' and ID not in (select post_id from wp_postmeta);
OPEN cur_pages;
Reading_Pages: LOOP
FETCH cur_pages INTO _post_id;
IF done THEN
LEAVE Reading_Pages;
END IF;
insert into wp_postmeta(post_id, meta_key, meta_value)
values (_post_id, '_wp_page_template', 'default'),
(_post_id, 'upside-show-page-title', '1'),
(_post_id, 'upside-show-breadcrumb', '1'),
(_post_id, 'upside-page-show-document-search', '0'),
(_post_id, 'upside-show-page-title-middle', 'false'),
(_post_id, '_vc_post_settings', 'a:1:{s:10:"vc_grid_id";a:0:{}}');
END LOOP;
CLOSE cur_pages;
END$$
DELIMITER ;
(1) 有没有错误? (2) 你知道如何在Mysql Workbench中显示编译错误吗?另外,(3) 从命令行运行脚本时,我可以在脚本中使用选项卡吗? (我不得不把它们去掉,因为我有错误)
最佳答案
尝试从定界符中删除分号
DELIMITER $$
drop procedure if exists updPages $$
create procedure ..
..
END $$
DELIMITER ;
关于MySql:创建过程错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40613048/