mysql - How do I set the NEW trigger values using a stored procedure? -


how set new trigger values using stored procedure? instance, before insert on mytable, want set new value of mytable.somecolumn given value. when trying so, 1193 error when trying create procedure. thank you

delimiter $$  create procedure `myproc` () begin     //how set new.somecolumn of mytable?     set new.somecolumn=123; end$$  create trigger mytrig before insert on mytable each row begin     //set new.somecolumn=123; //this works, want setting within stored procedure     call myproc(); end$$  delimiter ;  insert mytable(id,data) values (1,"hello"); //above "should" insert mytable(id,data,somecolumn) values (1,"hello",123); 

1193 - unknown system variable 'somecolumn'

edit. following work.

delimiter $$  create procedure `myproc` (inout myid int) begin     set myid =123; end$$  create trigger mytrig before insert on mytable each row begin     call myproc(new.somecolumn); end$$  delimiter ; 

you can not way started. might able achieve looking having stored procedure give value, , use value within trigger:

delimiter //  create procedure myproc (out param1 int)  begin    set @value = 123;  end//  delimiter ; 

then can have trigger call stored procedure , use it's value:

create trigger mytrig before insert on mytable each row  begin     call myproc(@columnvalue);     set new.somecolumn = @columnvalue; end$$ 

i haven't tested it, typing straight out of head. if doesn't work, please let me know, , revise answer.

also, let me know, if not looking for, or not complete enough, , revise answer.

(p.s. have no idea why thought not question.)


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -