2014-12-09 4 views
1

테이블 열을 단일 열에 연결하는 트리거를 만들려고하지만 오류를 찾을 수 없습니다.concat 값을 삽입하는 트리거를 만들 수 없습니다.

코드 : 당신이 당신의 update 문 뒤에 ;begin와 "여러 문"블록을 시작했지만, 때문에 당신은이 오류가

create trigger molecule_trigger After insert on molecule 
For each row 
begin 

Update molecule 
Set molecule_text= CONCAT(mid,',',ULCHEm_ID,',',IUPAC_name,',',Inchi,',',inchi_key,',',smiles,',',can_smiles,',',Molecular_formula,',',Molecular_weight,',',vendor,',',CAS,',',links,',',image); 
end; 

ERROR: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6

답변

1

end; 문 앞에 create trigger 문을 종료 .
당신은 구분 기호를

DELIMITER $$ 
create trigger molecule_trigger After insert on molecule 
For each row 
begin 

Update molecule 
Set molecule_text= CONCAT(mid,',',ULCHEm_ID,',',IUPAC_name,',',Inchi,',',inchi_key,',',smiles,',',can_smiles,',',Molecular_formula,',',Molecular_weight,',',vendor,',',CAS,',',links,',',image); 
end $$ 
DELIMITER ; 

을 변경 중 하나가 아니면 beginend를 제거합니다.

create trigger molecule_trigger After insert on molecule 
For each row 
Update molecule 
Set molecule_text= CONCAT(mid,',',ULCHEm_ID,',',IUPAC_name,',',Inchi,',',inchi_key,',',smiles,',',can_smiles,',',Molecular_formula,',',Molecular_weight,',',vendor,',',CAS,',',links,',',image); 

이제 다른 문제가 있습니다. 트리거가 작동하는 것과 동일한 테이블의 트리거에서 작업을 수행하려고합니다. 허용되지 않습니다. 트리거를 다음으로 변경하십시오.

create trigger molecule_trigger BEFORE insert on molecule 
For each row 
SET NEW.molecule_text= CONCAT_WS(',', NEW.mid, NEW.ULCHEm_ID, NEW.IUPAC_name, NEW.Inchi, NEW.inchi_key, NEW.smiles, NEW.can_smiles, NEW.Molecular_formula, NEW.Molecular_weight, NEW.vendor, NEW.CAS, NEW.links, NEW.image); 

삽입 된 열에 대해서만 molecule_text를 설정합니다. 행이 삽입 될 때마다 트리거가 전체 테이블을 업데이트했습니다. 그리고 한 문장에 3 개의 행을 삽입하면 테이블이 3 번 업데이트됩니다. 이것은 당신이 어쨌든하고 싶은 것이 아닙니다 :)

+0

해결 된 내 문제 :) 훌륭한 설명 주셔서 감사합니다 btw! –

관련 문제