In one table there is a Фамилия , first Имя , Отчество student. Question. How to make a function to display all three columns in the format Фамилия.А.А. (initials).
And then display in a related table.
You can do the following. To execute the query, you need to install a separator // in the client, for example, in the console mysql client, this is done using the DELIMITER // command DELIMITER //
DROP FUNCTION IF EXISTS fio// CREATE FUNCTION fio( `name` TEXT CHARSET utf8, `surname` TEXT CHARSET utf8, `patronymic` TEXT CHARSET utf8 ) RETURNS TEXT CHARSET utf8 READS SQL DATA BEGIN RETURN CONCAT( `surname`, ' ', SUBSTRING(`name`, 1, 1), '. ', SUBSTRING(`patronymic`, 1, 1), '.'); END// You can use the function as follows.
SELECT fio(name, surname, patronymic) FROM users; Source: https://ru.stackoverflow.com/questions/528651/
All Articles
concat(фамилия,'.',subtr(имя,1,1),'.',substr(отчество,1,1),'.')Should return approximately what you apparently want. But what it means to “display in a related table”, I don’t put my mind on it, you can write it down in a table and read it from it, there’s no such thing. And connected by the way by what criterion - Mike