Stored procedure Mariadb 10.1 variable assignment

0

I have a stored procedure works great ... but I want to optimize it .. what I need is to declare a variable, assign that variable a value of a field in a table ... but the simple fact of making any change in that procedure throws me an error 1064

-------- more or less that's what I want to implement

declare alf int ;
set alf = (SELECT configurar.dias_vaca from configurar)

despues viene el 

select *****  

en el cual deseo introducir la variable Alf

****
he probado con:
delimiter
begin .. end

and nothing for certain use:

  

mariadb 10.1.21 phpmyadmin 4.6.5.2

thanks

    
asked by Jose Padron 11.10.2018 в 16:34
source

1 answer

0

One option is:

MariaDB [test]> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 10.3.10   |
+-----------+
1 row in set (0.000 sec)

MariaDB [test]> DROP PROCEDURE IF EXISTS 'sp_test';
Query OK, 0 rows affected (0.000 sec)

MariaDB [test]> DELIMITER //

MariaDB [test]> CREATE PROCEDURE 'sp_test'()
    -> BEGIN
    ->   DECLARE 'alf' INT DEFAULT (
    ->     SELECT 'configurar'.'dias_vaca'
    ->     FROM (SELECT 5 'dias_vaca') 'configurar'
    ->   );
    ->   SELECT 'alf';
    -> END//
Query OK, 0 rows affected (0.000 sec)

MariaDB [test]> DELIMITER ;

MariaDB [test]> CALL 'sp_test';
+-------+
| 'alf' |
+-------+
|     5 |
+-------+
1 row in set (0.001 sec)

Query OK, 0 rows affected (0.001 sec)
    
answered by 02.11.2018 в 17:28