I continue to transfer stored procedures to php.
In one I came across such a request:

WHILE ( i < node_cnt ) DO SET i = i + 1; INSERT `tblnodesaccount`( `plc_id`, `node_num`, `active` ) VALUES( in_plc_id, i, i = 1 ); END WHILE; 

I'm confused by i = 1 .
Shouldn't this lead to an eternal cycle?

  • 2
    Maybe this is not an assignment, but a comparison? Is the column type active random not BOOLEAN ? - VladD pm

2 answers 2

There will be no infinite loop, because when inserting a change in the value of a variable does not occur. i = 1 is a logical expression and, apparently, something true / false (0/1) will be written to the table.

    What kind of DBMS? In MS SQL Server, a similar request in theory should produce an error in the place that confuses you - "i = 1", because we need to assign some value to a variable using the set keyword.

    • MySQL No error occurs. - zenith