Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

285
Views
declaraciones preparadas mysql con múltiples variables

Usar una variable no me da un error. con dos variables me da error de sintaxis.

 set @a= '...'; set @b = '...'; PREPARE stm1 FROM 'SELECT * FROM ? WHERE username = ?'; EXECUTE stm1 USING @a, @b;
 Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? WHERE username = ?' at line 2

otras preguntas no ayudaron.

Gracias

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No puede usar un parámetro para un nombre de tabla. Tienes que usar la concatenación para sustituir una variable por la tabla.

 PREPARE stm1 FROM CONCAT( 'SELECT * FROM `', @a, '` WHERE username = ?'); EXECUTE stmt1 USING @b;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!