database - MYSQL: UNDECLARED VARIABLE NEW -


is there wrong code? think it's alright, error "undeclared variable new". once again i'm converting oracle mysql in project need few on language , syntax

create trigger `customer_before_insert` before insert on `customer` each row begin   select concat('c', substr(new.name,1,1),substr(new.name,instr(new.name,' ')+1,1),                                    lpad(coalesce(max                                                 (substr(customer_id, 5, 5))+1, 1                                                 ), 5, 0))   customer    new.customer_id   new.customer_id concat('c', substr(new.name,1,1),   substr(new.name,instr(new.name,' ')+1,1), '%'); end 

if name : robert william code should "crw00001"

13.2.9.1 select ... syntax

...

the clause can name list of 1 or more variables, can user-defined variables, stored procedure or function parameters, or stored program local variables. ...

...

try:

drop trigger if exists `customer_before_insert`;  delimiter |  create trigger `customer_before_insert` before insert on `customer` each row begin     /*     declare tempkode varchar(10);     declare temp varchar(5);     set temp := concat('c', substr(new.name, 1, 1), substr(new.name, instr(new.name, ' ') + 1, 1));     */     declare temp varchar(5) default concat('c', substr(new.name, 1, 1), substr(new.name, instr(new.name, ' ') + 1, 1));      /*     select concat(temp, lpad(coalesce(max(substr(customer_id, 5, 5)) + 1, 1), 5, 0)) tempkode     customer      customer_id concat(temp,'%');      set new.customer_id := tempkode;     */     set new.customer_id := (                             select concat(temp, lpad(coalesce(max(substr(customer_id, 5, 5)) + 1, 1), 5, 0))                             customer                             customer_id concat(temp, '%')                            ); end|  delimiter ; 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -