How to call a stored procedure using select statement in mysql

后端 未结 2 1241
借酒劲吻你
借酒劲吻你 2020-12-16 03:16

I have call statement like

 CALL report_procedure
(\'2013-02-01\',now(),\'2015-01-01\',\'1\');

and i want to use it in a select query. i h

2条回答
  •  情深已故
    2020-12-16 03:51

    --Firstly your store procedure should look something like this:

    CREATE PROCEDURE report_procedure(
    IN d1 DATE,
    dnow DATE,
    d2 DATE,
    val INT
    ) 
    BEGIN SELECT * 
    FROM yourtablename
    WHERE date1 = d1
    AND datenow > dnow
    AND date2 > d2
    AND value = val;
    
    END
    --The store procedure contains the select statement.
    
    -- then you can call the store procedure like that:
     CALL report_procedure('2013-02-01',now(),'2015-01-01','1');
    
    --hope it helps
    

提交回复
热议问题