如何运行SQL脚本

时间:2019-06-29 09:49:53

标签: mysql mysql-workbench

当我尝试执行所有脚本时,以下部分将被忽略。如果我单独执行它,则不会有任何问题。

您能看看我是n00b吗,也许您会发现问题吗?

非常感谢!

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 STARTING BY '/' TERMINATED BY '/\n'
(@data_achizitie, @ora_achizitie, nume, prenume, cantitate, 
unitate_masura, piesa)
SET data_achizitie = STR_TO_DATE(@data_achizitie,'%m:%Y:%d'),
    ora_achizitie = replace(@ora_achizitie, ',', '');

这就是我之前所拥有的:

DELIMITER $ create trigger fulldate before insert on Tabela_veche for each
 row begin if new.fulldate is null then set new.fulldate = data_corecta 
 (new.data_achizitie, new.ora_achizitie); end if; END $ 

1 个答案:

答案 0 :(得分:1)

我无法重现您的错误

drop table if exists t;
create table t
(data_achizitie  date,
ora_achizitie time,
fulldate datetime,
nume varchar(100), prenume varchar(100), cantitate varchar(100), 
unitate_masura varchar(100), piesa varchar(100)
);

drop trigger if exists t;

dELIMITER $ 
create trigger t before insert on t
for each row 
begin 
    if new.fulldate is null then 
        set new.fulldate = f(new.data_achizitie,new.ora_achizitie); 
    end if; 
END $ 
delimiter ;

drop function if exists f;
create function f(d text, t text) 
returns datetime deterministic 
return str_to_date(concat(d, ' ', t), '%Y-%m-%d' '%H:%i:%s');

#select f('2019-06-24','06:54:05');


truncate table t;
LOAD DATA INFILE 
'C:\\Program Files\\MariaDB 10.1\\data\\sandbox\\data.txt'
INTO TABLE t
CHARACTER SET latin1
FIELDS TERMINATED BY '/$/'
OPTIONALLY ENCLOSED BY '$'
LINES STARTING BY '/' TERMINATED BY '\r\n'
ignore 1 lines
(@data_achizitie, @ora_achizitie, nume, prenume, cantitate, 
unitate_masura, piesa)
SET data_achizitie = STR_TO_DATE(@data_achizitie,'%m:%Y:%d'),
    ora_achizitie = replace(@ora_achizitie, ',','');

select * from t

+----------------+---------------+---------------------+------+---------+-----------+----------------+------------+
| data_achizitie | ora_achizitie | fulldate            | nume | prenume | cantitate | unitate_masura | piesa      |
+----------------+---------------+---------------------+------+---------+-----------+----------------+------------+
| 2016-04-27     | 06:54:05      | 2016-04-27 06:54:05 | Page | Bob     | 24        | Bax            | Reper 10/  |
+----------------+---------------+---------------------+------+---------+-----------+----------------+------------+
1 row in set (0.02 sec)

请研究此内容,如果我的操作与您的操作之间存在实质性差异,请添加评论。