I have a question for seniors. There is a table. There is a field sfz in the table. The character type has a fixed length of 18 bits. I use a cursor in the storage process to assign this field to a variable vsfz, which is also a character type with a fixed length. 18 bits, I wrote a query statement: select bj from kq201905 where sfz=vsfz;, and it can be queried correctly. Because I want to query multiple tables, the table names need to be assigned values in a variable loop, so I use the prepare statement to splice it together,
set @vsk=concat('select bj from ',vkn,' where sfz=' ,vsfz,';');
prepare stmt from @vsk;
execute stmt;
deallocate prepare stmt;
After execution, it was found that the query result was wrong. I tested that it has nothing to do with the table name variable, and now I suspect it is a problem with the where clause. If anyone knows the reason, please tell me, thank you!