Last active
July 10, 2020 15:09
-
-
Save mikelemus27/8fc4bf3a4ee7b3ca7f8cdfc1a06b5869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#'\\' is a delimiter | |
select version() as 'mysql version'; | |
drop function if exists test; | |
create function test (opcion int,num1 int, num2 int) | |
returns int | |
BEGIN | |
declare res INT DEFAULT 0; | |
declare mensaje TEXT; | |
IF opcion=1 THEN | |
#SELECT concat(num1, " + ", num2, " = ", num1 + num2) AS "suma"; # ERROR Not allowed to return a result set from a function | |
SELECT concat(num1, " + ", num2, " = ", num1 + num2) into mensaje; #meter el resultdo del select en una variable | |
#CREATE TABLE t1 AS SELECT concat(num1, " + ", num2, " = ", num1 + num2) ; #ERRORcrear tabla temporal y meter el resultado del select en ella | |
#SELECT @MSG:= concat(num1, " + ", num2, " = ", num1 + num2) AS "suma"; #ERROR | |
set res = num1 + num2; | |
return res; | |
END IF; | |
end \\ | |
select concat("resultado de suma: ",test(1,5,5)) as resultado; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment