Mysqlprocedure-about mysql5.6 storage and cursor

Source: Internet
Author: User
The following is my process. What I don't understand is that when I use any column in the cursor as a condition to judge the end of the cursor, it will be blank at any time, but it can actually be completed in a loop, think twice about it. For example, WHILE (TYPEISNOTNULL ). The type here is always null. If I use any column, event_value is also null as the while condition event_value. I beg you to answer this question. DELIMITER $ CREATEPROCEDUREtest (INevent_value_nameVARCHAR (20), IN... mysql proceduremysqlmysql serious problem mysql event

The following is my process. What I don't understand is that when I use any column in the cursor as a condition to judge the end of the cursor, it will be blank at any time, but it can actually be completed in a loop, think twice about it.
For example, WHILE (type is not null ). The type here is always null.
If I use any column, event_value is also null as the while condition event_value.
I beg you to answer this question.
DELIMITER $
Create procedure test (IN event_value_name VARCHAR (20), IN datestr VARCHAR (20), IN start_date DATETIME, IN end_date DATETIME)
BEGIN
DECLARE temp VARCHAR (10) DEFAULT "";
DECLARE temps VARCHAR (200) DEFAULT "";
DECLARE report_tim VARCHAR (100) DEFAULT "";
Declare type varchar (50 );
DECLARE event_value VARCHAR (50 );
DECLARE source VARCHAR (50 );
DECLARE event_name VARCHAR (50 );
Declare cot varchar (50 );
DECLARE allrow cursor for select tev. event_value, tev. source, tev. event_name, COUNT (*) as cot, tev. type, DATE_FORMAT (tev. report_time, '% Y-% m-% d') report_tim FROM ts_event_value tev

WHERE tev. name = event_value_name AND tev. report_time BETWEEN start_date AND end_date
Group by tev. event_value, tev. source, tev. event_name, tev. type, report_tim order by cot desc limit 15;
Declare continue handler for not found set type = NULL;
OPEN allrow;
/* Allrowloop: LOOP */
FETCH allrow INTO event_value, source, event_name, COT, TYPE, report_tim;
IF datestr = "all" THEN

        WHILE ( TYPE IS NOT NULL ) DO            SELECT s.name INTO temp FROM statistical s WHERE s.name = event_value_name AND s.source = source AND s.event_name = event_name AND s.event_value = event_value AND s.zt = "all";                IF temp = "" OR temp IS NULL THEN                    INSERT INTO statistical VALUES (source,event_name,event_value,COT,event_value_name,report_tim,"all");                ELSE                    UPDATE statistical s SET s.cot = s.cot + COT WHERE s.name = event_value_name AND s.source = source AND s.event_name = event_name AND s.event_value = event_value AND s.zt = "all";                END IF;            FETCH allrow INTO event_value,source,event_name,COT,TYPE,report_tim;        END WHILE;    END IF;     COMMIT;    SELECT event_value,source,event_name,COT,temp;    /*SELECT temps;*/    /*END LOOP allrowloop;*/CLOSE allrow;

END;
$
DELIMITER;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.