当前位置:网站首页>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
边栏推荐
- install ompl.sh
- pcl install
- SQL function
- What you need to know to test -- URL, weak network, interface, automation
- Daily-used English phrases
- 使用递归或while循环获取父/子层级结构的名称
- Introduction to QPM
- SQL query duplicate record
- Leetcode basic calculator 224 227. follow up 394
- Differences between VI and vim and common commands
猜你喜欢
c语言语法基础之——局部变量及存储类别、全局变量及存储类别、宏定义 学习
Redis notes (13) - scan and keys search for specific prefix key fields (command format, usage examples, locating large keys)
Single sign on logic
druid数据源实现后台监控
Champions League data set (Messi doesn't cry - leaving Barcelona may reach another peak)
Industrial and enterprise patent matching data (hundreds of thousands of data) 1998-2014
My creation anniversary
十万行事务锁,开了眼界了。
mysql 数据库字段查询区分大小写设置
Jz2440 - - - utiliser le programme de gravure uboot
随机推荐
install opencv-contrib-dev to use aruco code
Jz2440--- using uboot burning program
自动化测试——关于unitest与pytest初始化共存问题
测试实践——app 测试注意点
LeetCode 958. Completeness checking of binary tree
Flutter's brain map notes are easy to find and search!
爬虫相关文章收藏:pyppeteer 、Burpsuite
The basis of C language grammar -- pointer (multidimensional array, function, summary) learning
工企专利匹配数据(数十万数据量)1998-2014年
Use recursion or a while loop to get the name of the parent / child hierarchy
力扣------从数组中移除最大值和最小值
Single sign on logic
Testing practice - App testing considerations
国际化配置
js---获取对象数组中key值相同的数据,得到一个新的数组
SQL 函数
A concise tutorial for getting started with go generics
十万行事务锁,开了眼界了。
druid数据源实现后台监控
LeetCode 0710. Random numbers in the blacklist - preprocessing implementation o (1) value