0
votes

i'm using MySql Workbench and im unable to figure out this.

      delimiter $$
CREATE function `klientu_copy`() 
 DECLARE v_laiks TIMESTAMP;
 DECLARE v_liet VARCHAR(200);
set v_laiks = now();
set v_liet = current_user;

if (TG_OP = 'DELETE') THEN
insert into kopija_klienti values (v_liet,v_laiks,old.Vards,old.Uzvards,null,null);
ELSEif (TG_OP = 'INSERT') THEN
insert into kopija_klienti values (v_liet,v_laiks,null,null,new.Vards,new.Uzvards);
ELSEif (TG_OP='UPDATE') THEN
insert into kopija_klienti values (v_liet,v_laiks,old.Vards,old.Uzvards,new.Vards,new.Uzvards);
end if;

END; $$

delimiter ;

21:24:22 Error Code: 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 ''klientu_copy' () BEGIN DECLARE v_laiks timestamp; DECLARE v_liet varchar; s' at line 1 0.000 sec

Did try set @variable / declare @variable, cant figure this out. I'm still learning :)

1
You are missing a ) on the line insert into kopija_klienti values (v_liet,v_laiks,old.Vards,old.Uzvards,null,null; - Phillip Beck
Did forget to close ) on your first insert? - mim.
Thanks, didnt even see that... but still got the same problem :) - humble man
Can you use ' to delimit function names? I usually use `, and think " is supported with "ANSI SQL" on; but I've never seen single quotes used. Also, as far as I know, NEW is only valid in the context of certain triggers; and your function has no return type. You may want to start with the official docs here - Uueerdo
well i have the exact same code working on postgresql but i can't seem to make it work on workbench. - humble man

1 Answers

-1
votes

You must specify the length of the varchar variable, like varchar(100)

Also add the closing ( for the first insert.