Funkcja - MariaDB

0

Witam, potrzebuję funkcji, która weźmie mi dowolny znak, i zwróci go podwójnie. Mam coś takiego, lecz to mi nie działa -

delimiter //
create function data() returns varchar(2) deterministic
-> set @a = substr('qwertyuiopasdfghjklzxcvbnm',rand()*25+1,1);
-> return @a + @a;
-> //

Błąd mam taki -
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'set @a = substr('qwertyuiopasdfghjklzxcvbnm',rand()*25+1,1);
return @a + @a' at line 2

Co jest nie tak z tą funkcją?

0

return @a || @a;
albo
return CONCAT(@a, @a);

0

Przy kontatenacji, czyli takiej funkcji wyskakuje mi to samo:

 create function data() returns varchar(2) deterministic
    -> set @a = substr('qwe',rand()*2+1,1);
    -> return concat(@a,@a);
    -> //
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'set @a = substr('qwe',rand()*2+1,1);
return concat(@a,@a)' at line 2

Także z tego co widze, to zapisywanie substringa do zmiennej mi nie wychodzi w ogóle

0

Porównaj swój kod do tego:

CREATE TEMPORARY TABLE counter (c INT);
INSERT INTO counter VALUES (0);
DELIMITER //
CREATE FUNCTION counter () RETURNS INT
  BEGIN
    UPDATE counter SET c = c + 1;
    RETURN (SELECT c FROM counter LIMIT 1);
  END //
DELIMITER ;

dostępnego z https://mariadb.com/kb/en/library/create-function/

0

co to za zapis rand()2+1?

1 użytkowników online, w tym zalogowanych: 0, gości: 1