存储过程初试

DROP procedure IF EXISTS `proc_carAndCashScore`;
DELIMITER $$
create Procedure proc_carAndCashScore(
in accountName varchar(255),
in pathCode varchar(255),
in indecies text
)
begin

CREATE TEMPORARY TABLE IF NOT EXISTS temp_split
(
   col varchar(20)
);
DELETE FROM temp_split;
while(instr(indecies,',')<>0) DO
insert temp_split(col) values (substring(indecies,1,instr(indecies,',')-1)); //截取第一个逗号之前的字符串
set indecies = INSERT(indecies,1,instr(indecies,','),''); //更新字符串,把取到的字符串及逗号换为cut掉,第一次循环后变成”CP0001,CP0002,CP2004“
END WHILE;
insert temp_split(col) values (indecies);//最后一次字符为CP2004,只剩一个字符是没有逗号分割,不能进入循环,在此处插入表中

insert into ac_interface_index (`account_id`,`interface_id`,`index_id`,`created_at`) values (
(select id from account where account =accountName),
(select id from sys_interface where code=pathCode),
(select group_concat(id) from sys_index where code in (select * from temp_split)),
now());
end;$$

调用时执行如下命令:

call proc_carAndCashScore("00000001","queryCarScore","BP1013,CP0001,CP0002,CP2004");

**DELIMITER ∗ ∗ : 告 诉 解 释 器 碰 到 ** : 告诉解释器碰到 代表结束,可以执行命令,默认的的结束符号是";" 但是存储过程中的分号不代表指令结束,因此用这个命令转换一下。

创建存储过程

create procedure proc_name()
begin
.........
end

注意:存储过程名称后面必须加括号,哪怕该存储过程没有参数传递

insert(str,pos,len,newstr)
把字符串str由位置pos起len个字符长的子串替换为字符串
newstr并返回

三.删除存储过程
1.基本语法:

drop procedure sp_name

instr() :返回子字符串在字符串中的位置

SELECT INSTR('hello world', 'l') FROM DUAL;        --结果:3  
SELECT INSTR('hello world', 'l', 5) FROM DUAL;     --结果:10 (从左向右第5位开始检索'l'在'hello world'中出现的位置) 
SELECT INSTR('hello world', 'l', -1) FROM DUAL;    --结果:10 (从右向左第1位开始检索'l'在'hello world'中出现的位置) 
SELECT INSTR('hello world', 'l', 2, 2) FROM DUAL;  --结果:4  (从左向右第2位开始检索'l'在'hello world'中第2次出现的位置) 
SELECT INSTR('hello world', 'l', -3, 3) FROM DUAL; --结果:0  (从右向左第3位开始检索'l'在'hello world'中第3次出现的位置)

mysql函数
https://www.cnblogs.com/xuyulin/p/5468102.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值