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 281467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:12:20+00:00 2026-05-12T05:12:20+00:00

This is MySQL 5.1. (Note: I realize there are better ways of doing this

  • 0

This is MySQL 5.1.

(Note: I realize there are better ways of doing this particular example, this is not my real code)

Here is what I want to do:
The below procedure gets created, but when I CALL it, I get “ERROR 1210 (HY000): Incorrect arguments to EXECUTE”

 DELIMITER //
 CREATE PROCEDURE get_users_by_state(IN state CHAR(2))
 READS SQL DATA
 BEGIN
 SET @mystate = state;
 SET @sql = CONCAT('SELECT * FROM test_table WHERE state = "?"');
 PREPARE stmt FROM @sql;
 EXECUTE stmt USING @mystate;
 END;
 //

 CALL get_users_by_state('AA')//
 ERROR 1210 (HY000): Incorrect arguments to EXECUTE

Is there a way to pass the procedure’s parameters to the EXECUTE USING statement?
Here is a version that does indeed work, but irks me:

CREATE PROCEDURE get_users_by_state(IN state CHAR(2))
READS SQL DATA
BEGIN
SET @sql = CONCAT('SELECT * FROM test_table WHERE state = "', state, '"')
PREPARE stmt FROM @sql;
EXECUTE stmt;
END;
//

As a side-question, does MySQL have any facilities for escaping strings, like Postgres’ quote_literal() and quote_ident()?

For a point of reference, here’s something somewhat equivalent for Postgres:

CREATE OR REPLACE FUNCTION get_info_by_state(character)
  RETURNS SETOF ret_type AS
$BODY$
DECLARE
    sql text;
BEGIN
    sql := 'SELECT uid, some_data FROM test_table WHERE state = ' || quote_literal($1);
    RETURN QUERY EXECUTE sql;
END
$BODY$
  LANGUAGE 'plpgsql' VOLATILE

Thanks!

  • 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-12T05:12:20+00:00Added an answer on May 12, 2026 at 5:12 am

    I don’t think you need double quotes around the parameter holder.

    Update Here, lest there be no misunderstanding:

    DELIMITER //
    CREATE PROCEDURE get_users_by_state(IN state CHAR(2))
    READS SQL DATA
    BEGIN
    SET @mystate = state;
    SET @sql = CONCAT('SELECT * FROM test_table WHERE state = ?');
    PREPARE stmt FROM @sql;
    EXECUTE stmt USING @mystate;
    END;
    //
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
In this MySQL table definition: CREATE TABLE groups ( ug_main_grp_id smallint NOT NULL default
I want to accomplish this (mysql) query: UPDATE table SET field = field +
i have this MySQL statement from a search page, the user enters there postcode
I have this mysql tables I want to display with jqgrid. The problem appears
Note - this follows my question here: JDBC: Does the connection break if i
Maybe this way it will make more sense. MySQL table Code: id1 | id2
Okay, so here's what I want to do (NOTE: I'm stil new to PHP):
I have a mysql code like this... INSERT INTO `product` (`product_id`, `model`, `sku`) VALUES
I was wondering if there is a way to retrieve the MySQL code for

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.