I am trying to convert some DB2 queries to MySQL . I have tried to find some tools to convert the conversion . Unfortunately i din't find any conversions tools and some of the online tools are not converting properly. So i have tried to convert DB2 queries myself to MySQL .
I have started to create 3 trigger queries in MySQL . Unfortunately i am getting some syntax errors . These are the following queries were i migrated from DB2 to MySQL .
Trigger 1 :
CREATE TRIGGER SAMPLE_TABLE3 AFTER INSERT ON SAMPLE_TABLE4
FOR EACH ROW
BEGIN
INSERT INTO LICENSE_REVISION(LICENSE, LICENSE_REV) VALUES (NEW.ID, (NEXT VALUE FOR REVISION));
END;
Here i am getting syntax error
right syntax to use near 'VALUE FOR REVISION));
END' at line 9
I think the problem due to NEXT VALUE FOR .
Question 1 :
Is it any NEXT VALUE FOR alternative for MySQL ?
In trigger 2 , i am doing
CREATE TRIGGER SAMPLE_TRIGGER AFTER UPDATE OF SUPPORT__SERVER_UPS ON SETTINGS
FOR EACH ROW
BEGIN ATOMIC
FOR d AS SELECT ID AS D_ID FROM DOMAIN
DO UPDATE DOMAIN_REVISION DR SET DR.SERVER_DOMAIN_REV = (NEXT VALUE FOR REVISION) WHERE DR.DOMAIN = D_ID;
END FOR;
END;
and getting error :
right syntax to use near 'OF SUPPORT__SERVER_UPS ON SETTINGS
REFERENCING NEW AS NEW OLD AS OLD
FOR EAC' at line 6
i think the problem is AFTER UPDATE OF with column and i am suspecting FOR d AS line 4 and BEGIN ATOMIC too .
Question 2 :
- Can i use
AFTER UPDATE OFwith column in MySQL ? and any mistakes inFOR d ASline no 4 andBEGIN ATOMICline 3 . - if i have use multiple column values like
trigger :
CREATE TRIGGER SAMPLE_4 AFTER UPDATE OF IPV4_FIRST, IPV4, IPV4_MASK, IPV6_FIRST, IPV6, IPV6_MASK ON VIRTUAL_NETWORK
FOR EACH ROW
BEGIN
FOR d AS SELECT DOMAIN AS D_ID FROM DOMAIN_VIRTUAL_NETWORK WHERE VIRTUAL_NETWORK=NEW.ID
DO UPDATE DOMAIN_REVISION DR SET DR.CLIENT_NETWORK_REV = (NEXT VALUE FOR REVISION) WHERE DR.DOMAIN = D_ID;
END FOR;
END;
How can i approach this problem ? Should i use like this
IF NEW.a <> OLD.a or NEW.b <> OLD.b ?
I am beginner in this and i want to help to migrate . I know these are syntax problem and not valid questions . Please help or suggestion .
Update :
I have tried with last_insert_id and CURSOR . This is the working code now :
CREATE TRIGGER SAMPLE_TRIGGER AFTER UPDATE ON SETTINGS
FOR EACH ROW
BEGIN
DECLARE my_cursor CURSOR FOR SELECT ID AS D_ID FROM DOMAIN;
IF NEW.SUPPORT__SERVER_UPS <=> OLD.SUPPORT__SERVER_UPS THEN
open my_cursor;
my_loop: loop
FETCH my_cursor INTO D_ID;
UPDATE DOMAIN_REVISION DR SET DR.SERVER_DOMAIN_REV = (last_insert_id()) WHERE DR.DOMAIN = D_ID;
end loop my_loop;
close my_cursor;
END IF;
END;
NEXT VALUE FOR REVISIONlooks like it replaceable withSELECT MAX(REVISION) + 1 FROM [table]