mysql uuid的值全部都一样

98 阅读1分钟

解决方法

CONCAT(SUBSTR(REPLACE(uuid(),'-','') FROM 5 FOR 15),SUBSTR(UUID_SHORT() FROM -17 FOR 17)) AS send_point_id,

为什么搞这么复杂?不能直接uuid吗?

不能,有bug。数据全部都一样。

UUID_SHORT() FROM -17 FOR 17是错误用法

-17是起始位置,但是起始位置不能为负数。

但是这里的错误用法,反而导致每次生成的uuid不一样。反而解决了问题。

完整sql示例


INSERT INTO steward_send_car_point (
    send_point_id, 
    send_point_name, 
    steward_shop_id, 
    send_point_address, 
    send_point_longitude, 
    send_point_latitude, 
    send_point_status, 
    service_type, 
    veh_send_fee, 
    send_distance, 
    send_point_coordinates, 
    data_flag, 
    remark, 
    create_user, 
    create_time, 
    update_user, 
    update_time, 
    import_date, 
    import_send_distance
)
SELECT 
    -- REPLACE(UUID(), '-', '') AS send_point_id,  -- 使用 UUID() 函数生成唯一的送车点ID,并去掉连字符
    CONCAT(SUBSTR(REPLACE(uuid(),'-','') FROM 5 FOR 15),SUBSTR(UUID_SHORT() FROM -17 FOR 17)) AS send_point_id,
    shop_name AS send_point_name, 
    steward_shop_id, 
    shop_address AS send_point_address, 
    shop_longitude AS send_point_longitude, 
    shop_latitude AS send_point_latitude, 
    shop_status AS send_point_status, 
    1 AS service_type, 
    COALESCE(veh_send_fee, '0') AS veh_send_fee,  -- 如果 veh_send_fee 为 NULL,则设置为 0
    send_distance, 
    shop_coordinates AS send_point_coordinates, 
    data_flag, 
    remark, 
    create_user, 
    create_time, 
    update_user, 
    update_time, 
    import_date, 
    import_send_distance
FROM steward_shop

参考

www.yangjie.pro/2019/06/16/…