MySQL local variables

前端 未结 4 2108
失恋的感觉
失恋的感觉 2021-02-05 02:44

I am trying to define and initialize a MySQL variable for a query.

I have the following:

declare @countTotal int;
SET @countTotal = select COUNT(*)
 from         


        
4条回答
  •  青春惊慌失措
    2021-02-05 03:42

    Function example:

    DROP FUNCTION IF EXISTS test;
    
    DELIMITER $$
    CREATE FUNCTION test(in_number INT) RETURNS INT
        BEGIN
            DECLARE countTotal INT;
            SET countTotal = SELECT COUNT(*) FROM nGrams;
        RETURN countTotal + in_number;
    END $$
    DELIMITER ;
    

提交回复
热议问题