duplicate message when executing stored procedure

2

How can I avoid duplicate results on the screen when I execute a stored procedure?

This is the procedure:

CREATE PROCEDURE 'my_procedure'()
BEGIN

declare fecha_aux       varchar(30);
set fecha_aux = Date_format(now(),'%M %d %Y  %h:%i:%s %p');

--Aqui imprimo el texto en la pantalla
select  "%1! SP_PASO_HISTORICO -> Borrado de tablas temporales ", @fecha_aux;

END

Exit:

mysql> call my_procedure;
+--------------------------------------------------------+-------------------------------+
| %1! SP_PASO_HISTORICO -> Borrado de tablas temporales  | @fecha_aux                    |
+--------------------------------------------------------+-------------------------------+
| %1! SP_PASO_HISTORICO -> Borrado de tablas temporales  | November 24 2017  01:35:44 PM |
+--------------------------------------------------------+-------------------------------+
1 row in set (0.00 sec)

Why do 2 messages appear on the screen? How can I avoid the first one? I just want it to appear:

%1! SP_PASO_HISTORICO -> Borrado de tablas temporales  | November 24 2017  01:35:44 PM |

Is this possible?

    
asked by ekom77 24.11.2017 в 13:51
source

1 answer

2

It is not a duplicate.

The first row is to describe the names of the columns and the second row is your result. They seem to be duplicates because you did not assign a name to the columns, so MySQL generated a name according to the expression in SELECT .

But if you modify the SELECT to assign an alias to the 2 columns:

select  "%1! SP_PASO_HISTORICO -> Borrado de tablas temporales " as col1, 
        @fecha_aux as col2;

... then the result would look more normal and it would be obvious that it is not a duplicate row:

mysql> call my_procedure;
+--------------------------------------------------------+-------------------------------+
| col1                                                   | col2                          |
+--------------------------------------------------------+-------------------------------+
| %1! SP_PASO_HISTORICO -> Borrado de tablas temporales  | November 24 2017  01:35:44 PM |
+--------------------------------------------------------+-------------------------------+
1 row in set (0.00 sec)

Even so, if your intention is really to eliminate that initial row with the names of the columns, this can be done by adding the -N option when you launch MySQL in console. Example:

mysql -N -u sstan -p

Then the result would be:

mysql> call my_procedure;
+--------------------------------------------------------+-------------------------------+
| %1! SP_PASO_HISTORICO -> Borrado de tablas temporales  | November 24 2017  01:35:44 PM |
+--------------------------------------------------------+-------------------------------+
1 row in set (0.00 sec)
    
answered by 24.11.2017 / 14:50
source