美文网首页
mysql命令行执行创建存储过程报错

mysql命令行执行创建存储过程报错

作者: 西谷haul | 来源:发表于2022-11-12 12:55 被阅读0次

其实是mysql ;(分号的问题)。
可以采用delimiter //解决问题

image.png

然后回车,那么MySQL将立即执行该语句。
但有时候,不希望MySQL这么做。在为可能输入较多的语句,且语句中包含有分号。比如说我想创建一个存储过程

CREATE PROCEDURE `count_orthopedic`(in column_id VARCHAR(20))
begin
 declare sample_count int default 0;
 declare count_pre_t int default 0;
 declare count_tn int default 0;
 declare count_fn int default 0;
 declare count_fp int default 0;
 declare count_tp int default 0;

 select count(1) from model_orthopedic_column_log m where m.column_id=column_id into sample_count;
 select count(1) from model_log where model_type = '10' and score ='1' into count_pre_t;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 0 and ml.model_type = '10' and ml.score ='0' into count_tn;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 1 and ml.model_type = '10' and ml.score ='0' into count_fn;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 0 and ml.model_type = '10' and ml.score ='1' into count_fp;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 1 and ml.model_type = '10' and ml.score ='1' into count_tp;

 select 1 'id',sample_count, count_pre_t,count_tn,count_fn,count_fp,count_tp;
end

这时候就一定会报错了,以为mysql检索到分号,就会执行sql语句,这里我们来告诉mysql,检索到//再执行,也就是修改成以下,在sql执行的末尾,加上"//"。

delimiter //
CREATE PROCEDURE `count_orthopedic`(in column_id VARCHAR(20))
begin
 declare sample_count int default 0;#样本数
 declare count_pre_t int default 0;#预测好转数
 declare count_tn int default 0;
 declare count_fn int default 0;
 declare count_fp int default 0;
 declare count_tp int default 0;

 select count(1) from model_orthopedic_column_log m where m.column_id=column_id into sample_count;
 select count(1) from model_log where model_type = '10' and score ='1' into count_pre_t;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 0 and ml.model_type = '10' and ml.score ='0' into count_tn;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 1 and ml.model_type = '10' and ml.score ='0' into count_fn;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 0 and ml.model_type = '10' and ml.score ='1' into count_fp;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 1 and ml.model_type = '10' and ml.score ='1' into count_tp;

 select 1 'id',sample_count, count_pre_t,count_tn,count_fn,count_fp,count_tp;
end //

相关文章

  • mysql命令行执行创建存储过程报错

    其实是mysql ;(分号的问题)。可以采用delimiter //解决问题 然后回车,那么MySQL将立即执行该...

  • 存储过程

    创建存储过程 mysql: 执行存储过程 mysql: 使用OUT参数和INOUT参数: PREPARE和EXEC...

  • mysql存储过程

    一、执行过程1、创建数据库表 2、写入存储过程 3、执行 [mysql 存储过程海量数据写入和查询] 循环插入10...

  • MySQL存储过程创建及调用方法

    MySQL存储过程是一个sql语句,那么我们如何创建呢,MySQL存储过程创建及修改,删除操作。 1,存储过程创建...

  • MySQL 获取游标结果报错:1193-Unknown syst

    MySQL执行以下存储过程 报错: 错误原因:存储过程中使用的变量done未声明。 解决方案:先对done变量进行...

  • Mysql存储过程

    阅读目录:MySQL存储过程_创建-调用-参数 存储过程:SQL中的“脚本” 创建存储过程 调用存储过程 存储过程...

  • MySQL批量添加数据

    创建存储过程 执行存储过程 删除存储过程

  • mysql创建定时执行存储过程任务

    sql语法很多,是一门完整语言。这里仅仅实现一个功能,不做深入研究。 目标:定时更新表或者清空表。 案例:曾经做过...

  • MySQL存储过程

    1.1 创建存储过程 MySQL中,创建存储过程的基本形式如下: CREATEPROCEDUREsp_name([...

  • mysql 技术点汇总

    MYSQL存储引擎介绍 索引 mysql 执行过程 mysql 语句解析过程 https://www.cnblog...

网友评论

      本文标题:mysql命令行执行创建存储过程报错

      本文链接:https://www.haomeiwen.com/subject/mbffxdtx.html