mysql custom global defined variable

前端 未结 4 1587
逝去的感伤
逝去的感伤 2021-01-21 00:10

In my database design, I tend to store some variable that is meant to be acting as a ROLE or TYPE as SMALLINT. For example :



        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 00:55

    Since MySQL 5.5 it's not possible to set a global user-defined variable.

    A work-around might be to create a stored procedure that would return what you need.

    DROP PROCEDURE IF EXISTS HOUSE_SMALL_TYPE;
    DELIMITER //
    CREATE PROCEDURE HOUSE_SMALL_TYPE ()
    BEGIN 
    SELECT 0;
    END//
    DELIMITER ;
    

    and then call it.

    CALL HOUSE_SMALL_TYPE();
    

    The DROP statement is required in order to be able to modify it.

提交回复
热议问题