gpt4 book ai didi

mysql - 截断并插入存储过程mysql

转载 作者:行者123 更新时间:2023-11-30 00:04:05 26 4
gpt4 key购买 nike

有人可以告诉我为什么我的语法错误吗?

我将分隔符设置为 $$ do Prevent ;成为一个问题。我不想创建表,截断就可以了。

DELIMITER $$
create procedure create persistent_views
begin

truncate table vwt_total_overview_last3days;
truncate table vwt_total_overview_last30days:
truncate table vwt_total_overview_last7days;
truncate table vwt_total_overview_lastday;

insert into vwt_total_overview_last3days
select * from total_overview_last3days;

insert into vwt_total_overview_last30days
select * from total_overview_last30days;

insert into vwt_total_overview_last7days
select * from total_overview_last7days;

insert into vwt_total_overview_lastday
select * from total_overview_lastday;

END $$

我得到:

#1064 - 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 'create persistent_views begin truncate table vwt_total_overview_last3days; trun' at line 1

我将语句更改为以下内容,但它也不起作用(尝试使用或不使用括号和 AS )

DELIMITER $$
create procedure persistent_views() AS
begin

truncate table vwt_total_overview_last3days;
truncate table vwt_total_overview_last30days:
truncate table vwt_total_overview_last7days;
truncate table vwt_total_overview_lastday;

insert into vwt_total_overview_last3days
select * from total_overview_last3days;

insert into vwt_total_overview_last30days
select * from total_overview_last30days;

insert into vwt_total_overview_last7days
select * from total_overview_last7days;

insert into vwt_total_overview_lastday
select * from total_overview_lastday;

END $$

最佳答案

您已经使用了CREATE一词两次。只需删除第二个即可。这可能会解决你的问题。之后是一对括号和 AS 关键字。

关于mysql - 截断并插入存储过程mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24754904/

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