当前位置:网站首页>Introduction to stored procedure testing
Introduction to stored procedure testing
2022-06-26 09:54:00 【Miming】
CREATE PROCEDURE `test`.`new_procedure` ()
BEGIN
-- Need to define variables to receive cursor data
DECLARE a CHAR(16);
-- The cursor
DECLARE cur CURSOR FOR SELECT i FROM test.t;
-- Traversal data end flag
DECLARE done INT DEFAULT FALSE;
-- Bind the end flag to the cursor
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-- Open cursor
OPEN cur;
-- Start the cycle
read_loop: LOOP
-- Extract the data in the cursor , There's only one , It's the same with more than one ;
FETCH cur INTO a;-- Grab FETCH When , If cur by null(SELECT i FROM test.t), It triggers SET done = TRUE
-- At the end of the statement
IF done THEN
LEAVE read_loop;
END IF;
-- Here's what you want to do with the cyclic events
INSERT INTO test.t VALUES (a);
END LOOP;
-- Close cursor
CLOSE cur;
END
stay MySQL We often see this sentence in the stored procedure of :DECLARE CONTINUE HANDLER FOR NOT FOUND.
It means : If no data is returned , The program continues , And change the IS_FOUND Set to 0 , This happens when select XX into XXX from tablename It happened when .
-- start by lxm
DROP PROCEDURE IF EXISTS loan_contract_no_rule_init;
CREATE PROCEDURE loan_contract_no_rule_init()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE ruleId VARCHAR(32) DEFAULT '1528655117129572354';
DECLARE rule_detail_id_insert VARCHAR(32);
DECLARE rule_vale_insert VARCHAR(512);
-- Define cursors
DECLARE cur CURSOR FOR
SELECT rule_detail_id as rule_detail_id_insert,rule_vale as rule_vale_insert FROM trade_rule_detail_h WHERE rule_key = 'ATTACHMENT_TYPE' AND rule_detail_id IN (SELECT rule_detail_id FROM ent_trade_rule_info t WHERE
1 = 1 AND trade_code = 'REGISTER' AND STATUS = 1 AND prod_id = 'C01P00001' AND institution_id IN ( SELECT ent_id FROM prod_cif.cif_ent_type_ext WHERE ent_type = 9 AND prod_type = '01' ));
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
-- Open cursor
OPEN cur;
-- Extract the data in the cursor ;
FETCH cur INTO rule_detail_id_insert,rule_vale_insert;
WHILE done<>1 DO
-- Historical snapshot insert details
IF (rule_vale_insert = 'SELL_PROTOCOL') THEN
-- Financing agreement > initialization > Financing Contract No
INSERT INTO trade_rule_detail_h(id,rule_detail_id,rule_id,rule_key,rule_status,rule_vale)VALUES
(REPLACE(UUID(),'-',''),rule_detail_id_insert,ruleId,'LOAN_CONTRACT_NO',1,'LOAN_CONTRACT_NO');
ELSEIF (rule_vale_insert = 'LAST_TRADE_BACK') THEN
-- Last hand trade background materials > Initialize to > Trade Contract No
INSERT INTO trade_rule_detail_h(id,rule_detail_id,rule_id,rule_key,rule_status,rule_vale)VALUES
(REPLACE(UUID(),'-',''),rule_detail_id_insert,ruleId,'LOAN_CONTRACT_NO',1,'BACKGROUND_CONTRACT_NO');
ELSEIF (rule_vale_insert ='SELL_PROTOCOL,LAST_TRADE_BACK') THEN
-- Select the financing agreement and the last-hand trade background materials > initialization > Financing Contract No
INSERT INTO trade_rule_detail_h(id,rule_detail_id,rule_id,rule_key,rule_status,rule_vale)VALUES
(REPLACE(UUID(),'-',''),rule_detail_id_insert,ruleId,'LOAN_CONTRACT_NO',1,'LOAN_CONTRACT_NO');
ELSE
-- Nothing else
INSERT INTO trade_rule_detail_h(id,rule_detail_id,rule_id,rule_key,rule_status,rule_vale)VALUES
(REPLACE(UUID(),'-',''),rule_detail_id_insert,ruleId,'LOAN_CONTRACT_NO',1,'');
END IF;
FETCH cur INTO rule_detail_id_insert,rule_vale_insert;
END WHILE;
CLOSE cur;
END;
CALL loan_contract_no_rule_init();
-- end by lxm
边栏推荐
- Problems encountered by jupyter notebook
- A concise tutorial for getting started with go generics
- 力扣------从数组中移除最大值和最小值
- npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.npm ER
- Industrial and enterprise patent matching data (hundreds of thousands of data) 1998-2014
- Redis 新手入门
- 国际化配置
- Teach you to use shell script to check whether the server program is running
- Go learning notes (83) - code specification and common development skills
- This new change of go 1.16 needs to be adapted: the changes of go get and go install
猜你喜欢

2021-11-22 运动规划杂记

Basic grammar of C language -- pointer (character, one-dimensional array) learning

我的创作纪念日

MapReduce & yarn theory

mysql学习总结

Go learning notes (83) - code specification and common development skills

How does flutter transfer parameters to the next page when switching pages?

Several connection query methods of SQL (internal connection, external connection, full connection and joint query)

Jz2440 - - - utiliser le programme de gravure uboot

c语言语法基础之——指针(字符、一维数组) 学习
随机推荐
mysql 数据库字段查询区分大小写设置
2021-11-12 vrep视觉传感器配置
SQL query duplicate record
Jz2440--- using uboot burning program
Record a time when the server was taken to mine
What you need to know to test -- URL, weak network, interface, automation
Basic grammar of C language -- pointer (character, one-dimensional array) learning
Redis master-slave replication in win10 system
调用api接口生成不同颜色的微信小程序二维码
Speed test of adding, deleting, modifying and querying 5million pieces of data in a single MySQL table
从tf 1.x到tf 2.6(遇到的就过来更新更新)
WGCLOUD的web ssh服务端口是多少
自动化测试——pytest框架介绍及示例
Industrial and enterprise patent matching data (hundreds of thousands of data) 1998-2014
2021-11-29 轨迹规划五次多项式
OpenCV depthframe -> pointcloud 导致 segmentation fault!
Redis notes (12) - single thread architecture (non blocking IO, multiplexing) and multiple asynchronous threads
Redis notes (13) - scan and keys search for specific prefix key fields (command format, usage examples, locating large keys)
Leetcode refers to offer II 091 Paint house - modify in place
我在中山,到哪里开户比较好?在线开户安全么?