小编ama*_*sko的帖子

在 MySQL 中是否有替代“创建或替换过程”的方法?

MySQL 是否有“创建或替换过程”的版本?如果在重新编译之前没有收到存储过程存在的错误消息,我似乎无法执行此操作或编写删除过程的脚本(如果存在)。

DELIMITER $$

-- would love to be able to drop procedure if exists db.sp_tmp_90days;  
-- or use "create or replace"

create procedure db.sp_tmp_90days()

BEGIN
drop table db.tmp_90days;

create table db.tmp_90days ( 
    user_name varchar(128), 
    first_name varchar(50), 
    last_name varchar(50), 
    system varchar(10), 
    last_login datetime 
);

alter table db.tmp_90days add index idx_user_name(user_name);
alter table db.tmp_90days add index idx_system(system);
alter table db.tmp_90days add index idx_last_login(last_login);

insert into db.tmp_90days (user_name, first_name, last_name, system, last_login)
    SELECT
        [...]
END $$
Run Code Online (Sandbox Code Playgroud)

mysql stored-procedures

23
推荐指数
1
解决办法
3万
查看次数

标签 统计

mysql ×1

stored-procedures ×1