I tried a lot of ways to use user defined variables in MariaDB version 10.3.22. After failing to use it in my application, I wanted to try with a simple example:
DECLARE @EmpName1 NVARCHAR(50)
SET @EmpName1 = 'Ali'
PRINT @EmpName1
gives Unrecognized statement type. (near "DECLARE" at position 0)
After some digging around I tried using it between delimiters and as a created function:
DELIMITER //
CREATE FUNCTION test
DECLARE @EmpName1 VARCHAR(50)
SET @EmpName1 = 'Ali'
PRINT @EmpName1
END //
DELIMITER;
This gives
- Unrecognized data type. (near ")" at position 54)
- A "RETURNS" keyword was expected. (near "END" at position 110)
I cannot figure out where the issue might be coming from, as the MariaDB documentation has the same syntax as far as I can see.
Can anyone help solving this issue? My final goal would be to assign the single result of a query to a variable as a string.