mysql使用游标进行删除操作的存储过程_MySQL
BEGIN DECLARE hprocessInstanceId bigint DEFAULT 0; -- 历史流程实例id DECLARE hprocessInstanceIdStarttime CHAR default ''; -- 历史流程实例启动时间 DECLARE hprocessInstanceIdEndtime CHAR default ''; -- 历史流程实例结束时间 DECLARE hactinstId BIGINT default 0; -- 历史活动实例id DECLARE htaskId BIGINT default 0; -- 历史人工任务id DECLARE hvarId BIGINT default 0; -- 历史流程变量id DECLARE rexecutionId bigint default 0; -- 正在执行流程实例id DECLARE rvarId bigint default 0; -- 正在执行流程变量id DECLARE rtaskId bigint default 0; -- 正在执行人工任务id DECLARE rswinmlanceId bigint DEFAULT 0; -- 泳道id,为了删除partation表记录,本项目无记录 DECLARE processCompleteFlag int default 0; -- 流程是否结束标识 DECLARE taskCompleteFlag int default 0; -- 任务是否结束标识 DECLARE doneFlag INT DEFAULT 0; -- 完成标识,0:未完成;1:已完成 DECLARE notfound INT DEFAULT 0;-- 是否未找到数据 标记 -- 启动事物 -- START TRANSACTION; /* 声明历史流程实例的游标 */ DECLARE hprocessInstanceRS CURSOR FOR SELECT dbid_,START_,END_ FROM jbpm4_hist_procinst where START_>='2014-0-0 0:0:0' and START_<'2015-0-0 0:0:0'; /* 声明历史活动实例的游标 */ DECLARE hactinstRS CURSOR FOR SELECT dbid_,HTASK_ FROM jbpm4_hist_actinst where HPROCI_=hprocessInstanceId; /* 声明历史活动实例的游标 */ DECLARE htaskRS CURSOR FOR SELECT dbid_ FROM jbpm4_hist_task where DBID_=hactinstId; /* 声明历史活动实例的游标 */ DECLARE hvarRS CURSOR FOR SELECT dbid_ FROM jbpm4_hist_var where HTASK_=rtaskId; /** 声明正在执行流程实例的游标(历史表中因为各种原因未完成的) **/ DECLARE rexecutionRS CURSOR FOR SELECT dbid_ FROM jbpm4_execution where DBID_=hprocessInstanceId; /** 声明正在执行流程变量的游标(只删除2014年条件下由于各种原因未完成的流程实例所对应的流程变量) */ DECLARE rvarRS CURSOR FOR SELECT dbid_ FROM jbpm4_variable where EXECUTION_=hprocessInstanceId; /** 声明正在执行的人工任务的游标(只是2014年开始的流程实例所对应的) **/ DECLARE rtaskRS CURSOR FOR SELECT dbid_ FROM jbpm4_task where DBID_=rtaskId; /** 声明泳道的结果集游标,为了删除paritation表,该项目没有记录,实际删除条数为0 **/ DECLARE rswinmlanceRS CURSOR FOR SELECT dbid_ FROM jbpm4_swimlane where dbid_=rswinmlanceId; /* 异常处理 */ DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET doneFlag = 1; /** 删除s,使用嵌套循环..... **/ OPEN hprocessInstanceRS; FETCH hprocessInstanceRS INTO hprocessInstanceId,hprocessInstanceIdStarttime,hprocessInstanceIdEndtime;-- 获取历史流程实例表的数据数据 REPEAT IF hprocessInstanceIdEndtime='' THEN -- 没有结束,执行删除正在执行的流程实例表 /** 1.查询正在执行的流程实例记录s **/ SET rexecutionId=hprocessInstanceId; -- 未完成的流程实例与正在执行的流程实例id做对应 OPEN rexecutionRS; FETCH rexecutionRS INTO rexecutionId; REPEAT /** 2.查询该流程实例下的所有正在执行的流程变量记录s 2**/ OPEN hvarRS; FETCH hvarRS INTO rvarId; REPEAT /** 3.删除正在执行的流程变量所对应的人工任务记录s 3**/ delete from jbpm4_task where dbid_=rvarId; /** 3.删除正在执行的流程变量所对应的人工任务记录e 3**/ delete from jbpm4_variable where dbid_=rvarId; -- 单条删除流程变量记录 FETCH hvarRS INTO rvarId; UNTIL doneFlag END REPEAT; CLOSE hvarRS; /** 2.查询该流程实例下的所有正在执行的流程变量记录e 2**/ delete from jbpm4_execution where dbid_=rexecutionId; -- 单条删除流程对象记录 FETCH rexecutionRS INTO rexecutionId; UNTIL doneFlag END REPEAT; CLOSE rexecutionRS; END IF; /*** ======删除历史流程记录表相关数据===== **/ /** 1.查询活动实例表 s **/ OPEN hactinstRS; FETCH hactinstRS INTO hactinstId,htaskId; REPEAT /** 2.查询历史人工活动表记录s **/ OPEN htaskRS; FETCH htaskRS INTO htaskId; REPEAT /** 3.删除历史人工任务 **/ delete from jbpm4_hist_task where dbid_=htaskId; FETCH htaskRS INTO htaskId; UNTIL doneFlag END REPEAT; CLOSE htaskRS; /** 2.查询历史人工活动表记录s **/ FETCH hactinstRS INTO hactinstId,htaskId; UNTIL doneFlag END REPEAT; CLOSE hactinstRS; /** 1.查询活动实例表 e **/ /*** ======删除历史流程记录表相关数据===== **/ /** 删除历史活动实例表 **/ delete from jbpm4_hist_actinst where HPROCI_=hprocessInstanceId; SET doneFlag=0; FETCH hprocessInstanceRS INTO hprocessInstanceId,hprocessInstanceIdStarttime,hprocessInstanceIdEndtime;-- 获取历史流程实例表的数据数据 UNTIL doneFlag END REPEAT; CLOSE hprocessInstanceRS; END
使用嵌套之后,10万-百万条数据量删除非常慢,有什么解决方法没有?

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Windows 11 has a seemingly unlimited amount of customization options, from default settings to every third-party app on the Internet. There are even apps that can change the appearance of your mouse cursor. Modifying the cursor is a great way to give your computer a unique look. You don't have to stick the same boring black and white pointer on every computer. But even so, you don't have to download software to change the look of your cursor. How to change the appearance of the cursor? Windows 11 offers a small amount of customization for the cursor. You can change the cursor by going into Control Panel and selecting Mouse Options there. A new window called "Mouse Properties" will appear. In the mouse properties you can change the color scheme, size and design. Your computer will naturally

In Back to the Future 1999, players will face many level challenges, and each level brings completely different challenges. As one of the levels, 6-24 will definitely have many players thinking about it. You know how to challenge this level, so the following will also bring relevant clearance methods. Back to the Future 19996-24 Clearance Method 1. After burning on level 30 in one sentence, wait for the boss to be stunned and give him a heavy beating. 2. Prioritize using main C and 142d to burn in one round. 3. In the second round, use the auxiliary and nanny's small skills to burn and the main C card to build a big move. 4. The boss will be stunned in three rounds, and then he will be beaten directly with his ultimate move and damage skills.

Share how to pass the level of Ming Tide Fantasyland Difficulty 3. Many people in Mingchao are completing level 3 of this fantasyland. This level is actually a bit difficult. Many friends don’t know what to do yet, but don’t worry, the editor brings it to you. If you have read the strategies in it, come and give it a try. How to pass the Bell Turtle character in Difficulty Level 3? Strengthening resonance skills can improve the effect of our aerodynamics. In this way, the attack efficiency will be increased and the damage will be greater. However, if you have Effect replacement can also be exchanged. [Metaphor] Choice for the first three levels: Sun in the Forest: It can greatly increase the damage of Jiyan. If the skill is used more often, it can produce a very good critical hit effect. Protective device: Use resonance technology

Selection sort is an aggressive algorithm used to find the smallest number from an array and place it in the first position. The next array to be traversed will start at the index, close to where the smallest number is placed. The process of selection sort selects the first smallest element in the list of elements and places it in the first position. Repeat the same operation for the remaining elements in the list until all elements are sorted. Consider the following list - first pass Sm=a[0]=30Sma[1]

Many friends want to upgrade their computer systems to win10 system, but they don’t know how long the upgrade process will take. Today I have brought you a detailed introduction to the time required to update to win10. Come and take a look. How long does it take to update to win10: 1. It varies from about 40 minutes to 2/3 hours depending on the performance of each user's machine. 2. The time to configure performance is also different, which is closely related to the amount of data in the old system. 3. If the computer has a lot of stuff and a mechanical keyboard, it will be even slower. 4. If you upgrade from win7/8 to win10, it will take about an hour and a half. 5. Reserve enough time in advance before upgrading to back up important things to avoid loss.

A small adventure is an early branch in Dragon's Dogma, so how can this task be completed? Players first need to go to Mevi, accept this mission at the grocery store here, and buy pills to complete this branch. Generally speaking, it is very simple. The detailed content can be found in this small adventure mission graphic guide. Let’s learn more and take a look together. How to survive a small adventure in Dragon's Dogma 2: 1. First, take the ox cart north of Velenworth to Meve. 2. After arriving in Mevi, go to Lunnai’s props to take you, and talk to the NPC here to start the mission. 3. Then the player enters the store behind the door, talks to the uncle here, and buys pills. 4. After purchasing, return to the door and provide the pills to the NPC. 5. Subsequently

Detailed explanation of Golang compilation process Golang (also known as Go) is a programming language developed by Google. It has the characteristics of simplicity, efficiency, concurrency, etc., so it has received widespread attention and application. When programming with Golang, compilation is a very important link. This article will introduce the Golang compilation process in detail and provide specific code examples. 1. Compilation process of Golang source code Lexical Analysis (LexicalAnalysis) The first step in the compilation process is the word

Friends, what the editor brings to you today is a detailed strategy sharing about the meditation trial of the new Swordsman mobile game. Next, let’s take a look at the meditation trial methods compiled by the editor. If you are interested in this, go and try it in the game. How to pass the meditation trial in the new Swordsman mobile game: The meditation trial is quite demanding. Here are a few tips. 1) When gathering monsters, try to keep the first few waves of monsters in a state of residual health during the last wave. 2) The first attack state is used to refresh the second wave of monsters, and cooperate with the burst of your own skills to quickly reduce the health of the first wave and the second wave of monsters. 3) The second attack state is used to refresh the last wave of monsters in the last 10 seconds. In conjunction with the wave of damage from the unique skill, the screen is instantly cleared. The remaining few monsters use skills.
