• 存储过程中的select into from是干什么的


    select into  赋值:

    select 0 into @starttime
    select @starttime from DUAL



    into后边应该还有个变量名,into前面也还要带上筛选字段,例如
    select count(*) into v_count from dual;
    这条语句的意思是查询dual表的所有记录数,将查询结果存入v_count变量中,也就是给变量设值的用法

    可以给变量赋值

    CREATE PROCEDURE cp_p_recived ()
    BEGIN
    SELECT
    IFNULL(MAX(recived_time), 0) INTO @starttime
    FROM
    p_recived_before;

    DELETE FROM p_recived_before;

    INSERT INTO p_recived_before (
    user_id,
    recived_time,
    recived_count,
    create_time,
    city_id
    ) SELECT
    cp.user_id,
    cp.recived_time,
    cp.recived_count,
    cp.create_time,
    cp.city_id
    FROM
    (
    SELECT
    (
    SELECT
    user_id
    FROM
    addrdb.w_contacts
    WHERE
    phone = w.receiver_mobile
    LIMIT 1

    ) AS user_id,
    w.sign_date AS recived_time,
    1 AS recived_count,
    unix_timestamp(now()) * 1000 AS create_time,
    receiver_city_id AS city_id
    FROM
    tmsdb.w_waybill w
    WHERE
    w.sign_date > @starttime
    AND w. STATUS = 200
    ORDER BY
    w.sign_date ASC
    LIMIT 2000
    ) cp;


    SELECT IFNULL(MAX(recived_time), 0) INTO @mymaxtime FROM p_recived_before;


    INSERT INTO p_recived (
    user_id,
    recived_time,
    recived_count,
    create_time,
    city_id
    ) SELECT
    pr.user_id,
    pr.recived_time,
    pr.recived_count,
    pr.create_time,
    pr.city_id
    FROM
    (
    SELECT
    user_id,
    recived_time,
    recived_count,
    create_time,
    city_id,
    MAX(recived_time)
    FROM
    p_recived_before WHERE user_id is NOT NULL
    GROUP BY
    user_id
    ) pr
    LEFT JOIN (
    SELECT
    user_id
    FROM
    p_recived
    WHERE
    create_time >= UNIX_TIMESTAMP(CAST(SYSDATE() AS DATE)) * 1000
    AND create_time < UNIX_TIMESTAMP(CAST(SYSDATE() AS DATE) + 1) * 1000
    ) p ON pr.user_id = p.user_id
    WHERE
    pr.user_id > 0
    AND pr.city_id > 0
    AND p.user_id IS NULL;

    DELETE
    FROM
    p_recived_before;


    INSERT INTO p_recived_before (
    recived_time
    ) VALUES (@mymaxtime);


    END
    13611227650


    select * from tmsdb.w_waybill w where receiver_id='KH1710260000080'

  • 相关阅读:
    将博客搬至CSDN
    U盘启动盘 安装双系统 详细教程
    vmware安装linux6.3
    hadoop学习之路
    linux重定向总结:如何将shell命令的输出信息自动输出到文件中保存
    AVRO讲解
    MapReduce 工作原理
    lucene索引存储原理
    ES数据库系统
    分流器设备与交换机设备的区别
  • 原文地址:https://www.cnblogs.com/flywang/p/8568780.html
Copyright © 2020-2023  润新知