stored procedures - Why does MySQL find an error in the CONCAT statement? -


i'm trying write stored procedure in mysql, need loop on cursor, , execute sql statement uses piece of data cursor gets fetched variable, executed sql. cursor orders_cur sorted on this_addr; in given block of this_addr records, first record skipped, , rest need flagged setting duplicateorder="1".

for reason, cannot line concat function work without giving me error:

            open orders_cur;             order_loop: loop                 -- loop on orders_cur until this_addr = match_addr                 find_addr_loop: repeat                     fetch orders_cur this_addr,this_orderid;                 until this_addr = match_addr                 end repeat;                 -- skip first order matched performing fetch                 fetch orders_cur this_addr,this_orderid;                 -- start next loop real work; set duplicateorder on remaining records in cursor,                 -- using orders_cur.order_id locate actual record in reservations table.                  set_dupe_loop: while this_addr = match_addr                     set @sql = concat('update reservations set duplicateorder = \'1\' order_id=',this_orderid);                     prepare runme @sql;                     execute runme;                     fetch orders_cur this_addr,this_orderid;                 end while set_dupe_loop:;                 deallocate prepare runme;             end loop order_loop; 

i have tried every variation possible on escaping literals need around '1' no avail, , going cross-eyed...if sees error lies, appreciate it...

--rixter

you don't need cursor operation. can do:

update reservations r join        (select this_addr, min(order_id) minoi         reservations r2          this_addr = match_addr         group this_addr        ) dups        on r.this_addr = dups.this_addr , r.order_id > dups.minoi     set r.duplicateorder = 1; 

in general, should avoid cursors, require dynamic sql. when can express logic set operation, best so.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -