Error code: 1054. Unknown column "SPA" in the section "where where"
This happens when you do not insert the input string in quotation marks, and the SQL engine tries to identify it as a column in the requested table. But he fails because he cannot find him.
But what happens when he finds such a column?
It retrieves the results if it finds some matches of the column values.
Obviously, this is not what they expected.
How to overcome this? Use prepared expressions with dynamic input values.
In stored procedures can you also use a placeholder, for example ? , for dynamic input values ββfor use with Prepared Statements . The engine will process escape characters and other string values ββwhen assigning or comparing in SQL expressions.
You just need to reassign the procedure entry to one or more session variables, if necessary.
An example of your procedure :
CREATE PROCEDURE `test1`( IN tab_name VARCHAR(40), IN w_team VARCHAR(40) ) BEGIN SET @t1 = CONCAT( 'SELECT * FROM ', tab_name, ' where team = ?' );
source share