MyCATApache / Mycat-Server

GNU General Public License v2.0
9.51k stars 3.85k forks source link

不能使用mycat2.0创建存储过程吗 #2952

Open z18539749496 opened 5 months ago

z18539749496 commented 5 months ago
CREATE PROCEDURE `poly_pay_transaction_max_concurrency`()
BEGIN
        DECLARE currentDate DATE;
    DECLARE endDate DATE;

    -- 获取开始和结束日期
    SELECT MIN(DATE(create_time)), (MAX(DATE(create_time))- INTERVAL 1 DAY) INTO currentDate, endDate
    FROM poly_pay_transaction;

    -- 创建临时表用于存储结果
    CREATE TABLE IF NOT EXISTS poly_pay_transaction_max_concurrency (
        day DATE,
                max_concurrency_time INT,
        max_concurrency INT
    );

    -- 循环计算每一天的活跃商户数
    WHILE currentDate <= endDate DO
                -- 添加条件判断,确保不重复统计已经处理过的日期
        IF NOT EXISTS (SELECT 1 FROM poly_pay_transaction_max_concurrency WHERE day = currentDate)
                THEN
                    INSERT INTO poly_pay_transaction_max_concurrency (day,max_concurrency_time, max_concurrency)
                    SELECT currentDate, DATE_FORMAT(create_time,'%H') '时间节点', COUNT(id) AS count
                    FROM poly_pay_transaction
                    WHERE DATE_FORMAT(create_time,'%Y-%m-%d') = currentDate
                    GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S')
                    ORDER BY count DESC
                    LIMIT 1;
                END IF;

        -- 更新日期
        SET currentDate = currentDate + INTERVAL 1 DAY;
    END WHILE;

    -- 选择结果
    SELECT * FROM poly_pay_transaction_max_concurrency;

    -- 删除临时表
    -- DROP TABLE IF EXISTS poly_pay_transaction_max_concurrency;
END;

报错信息:

CREATE PROCEDURE `poly_pay_transaction_max_concurrency`()
BEGIN
        DECLARE currentDate DATE;
    DECLARE endDate DATE;

    -- 获取开始和结束日期
    SELECT MIN(DATE(create_time)), (MAX(DATE(create_time))- INTERVAL 1 DAY) INTO currentDate, endDate
    FROM poly_pay_transaction;

    -- 创建临时表用于存储结果
    CREATE TABLE IF NOT EXISTS poly_pay_transaction_max_concurrency (
        day DATE,
                max_concurrency_time INT,
        max_concurrency INT
    );

    -- 循环计算每一天的活跃商户数
    WHILE currentDate <= endDate DO
                -- 添加条件判断,确保不重复统计已经处理过的日期
        IF NOT EXISTS (SELECT 1 FROM poly_pay_transaction_max_concurrency WHERE day = currentDate)
                THEN
                    INSERT INTO poly_pay_transaction_max_concurrency (day,max_concurrency_time, max_concurrency)
                    SELECT currentDate, DATE_FORMAT(create_time,'%H') '时间节点', COUNT(id) AS count
                    FROM poly_pay_transaction
                    WHERE DATE_FORMAT(create_time,'%Y-%m-%d') = currentDate
                    GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S')
                    ORDER BY count DESC
                    LIMIT 1
> 0 - com.alibaba.druid.sql.parser.ParserException: syntax error, error in :'IMIT 1', expect END, actual null, pos 1036, line 28, column 14, token EOF