Using @Query to execute a MySQL function as follows. Here is an example that uses Spring Data @Query to execute a MySQL function that returns a string value. Let’s say we have a MySQL function that returns a predefined text.
MySQL Function
hello_world() returns ‘Hello World’ in German.
1 2 3 4 5 6 7 8 9 | DELIMITER $$ CREATE FUNCTION hello_world() RETURNS TEXT LANGUAGE SQL BEGIN RETURN 'Hallo Welt'; END; $$ DELIMITER ; |
Using @Query
Using Spring Data, we can use @Query
with nativeQuery = true
.
1 2 3 | @Query(nativeQuery = true, value = "select hello_world() from fakedual") List<String> getNextCustomGroupSequence();<code> |