Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6745437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:12:16+00:00 2026-05-26T12:12:16+00:00

I learned today through this section of the MySQL documentation that prepared statements cannot

  • 0

I learned today through this section of the MySQL documentation that prepared statements cannot be performed in stored functions, but, as of MySQL version 5.0.13, they can be performed in stored procedures.

Today I was putting together a stored procedure and thought initially it might be interesting to try doing an INSERT statement in it as a prepared statement. However, despite this supposedly being possible (I’m using MySQL 5.5.14), the ? parameter marker in the statement string caused MySQL to throw a syntax error.

I threw a couple of simplified examples together using the same exact sort of syntax I used for the prepared INSERT statement. I’m hoping I just have a syntax error somewhere I just haven’t caught. The first block, below, is the procedure that works, i.e. it uses the standard CONCAT(your query string) syntax.

DROP PROCEDURE IF EXISTS TestConc;
DELIMITER $$

CREATE Procedure TestConc()
BEGIN
  SET @sql := CONCAT('CREATE TABLE Foo (FooID INT) ENGINE = InnoDB');
  PREPARE stmt FROM @sql;
  EXECUTE stmt;
  DEALLOCATE PREPARE stmt;

  SET @tn := 'Foo';
  SET @sql := CONCAT('INSERT INTO ', @tn, ' VALUES (5)');
  PREPARE stmt FROM @sql;
  EXECUTE stmt;
  DEALLOCATE PREPARE stmt;
END;
$$
DELIMITER ;

Upon calling the procedure with this code, the expected happens; 5 is stored in the FooID field of the newly-generated Foo table. However, if we change the lines between the two DEALLOCATE PREPARE directives to this:

SET @tn := 'Foo';
SET @sql := 'INSERT INTO ? VALUES (5)';
PREPARE stmt FROM @sql;
EXECUTE stmt USING @tn;

We get an error that tells us to check the syntax of the statement near ‘? VALUES (5)’.

Is it just not possible to substitute a parameter marker for a table name? I haven’t tried doing something along the lines of ‘SELECT ? FROM Foo’ to see if this will work yet. Also, and I don’t know if it’s important, I’ve been trying this using MySQL Workbench 5.2.35 CE, rather than a command line.

I don’t have any specific need to run queries as prepared statements within procedures ATM, I just want to make sure I have the syntax correct for doing so if I ever should need to.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:12:16+00:00Added an answer on May 26, 2026 at 12:12 pm

    The parameter ‘?’ cannot be used for identifiers. Use first variant. From the reference – Parameter markers can be used only where data values should appear, not for SQL keywords, identifiers, and so forth.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I learned today that NetBeans 6.5 should have an on-the-fly compilation of (single) Java
I learned today that there are digraphs in C99 and C++. The following is
Today I just learned that Adobe Air has a local SQL database, which is
Just today learned that one of my websites, TwitPeek.net, is not rendering properly in
Today I learned this JavaScriptSerializer ser = new JavaScriptSerializer(); Foo foo = ser.Deserialize<Foo>(jsonSz); I
Today Recently on Stackoverflow i learned that: reintroduce is used to hide ancestor constructors
Today I learned that one of the .NET libraries I use, OpenTK, requires me
I was working on an html form today, and I learned that keeping the
I learned from books that you should write for loop like this: for(var i=0,
I've just today learned of asp.net mvc, and I'm wondering what is needed from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.