**I need to create a Function in Mysql that needs to have 2 parameters type TEXT that needs to format the date and time in MySQL format for all the lines from a .txt file. EX from the .txt file: "19:01:31";"11.38.35";"Kresser";"Lynn";"Credit";"-700";"Hawai"
**then I need to create a Trigger before insert that at each insert calls the Function previously created, with the parameters date and time that are inserted in the table.
I tried the following but without success:
CREATE FUNCTION data_corecta(data TEXT,ora TEXT)
RETURNS DATETIME
DETERMINISTIC
COMMENT 'Receives date, time in a format and returns datetime in the corect format MySql'
BEGIN
DECLARE dataora DATETIME;
SET data=str_to_date('19:01:31','%y:%m:%d');
SET ora=str_to_date('11.38.35','%H.%i.%s');
SET dataora=concat(data,' ',ora);
RETURN dataora;
END /
delimiter ;
DROP TRIGGER if exists TR_DATA;
DELIMITER //
CREATE TRIGGER tr_data
BEFORE INSERT ON Tabela_veche
FOR EACH ROW
BEGIN
CALL data_corecta();
INSERT INTO tabela_veche (fulldate)
VALUES (concat(data,' ',ora));
END //
delimiter ;
load data infile 'C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Uploads\\fisier.txt'
into table Tabela_veche
character set latin1
fields terminated by ';'
optionally enclosed by '"'
lines terminated by '\r\n'
(data,ora,nume,prenume,descriere,valoare,locatia,fulldate);
Can you please correct it or let me know what is wrong?
Thank you, Denisa