user1508893
user1508893

Reputation: 9783

meaning of "?" in mysql query

I've seen some (my)sql queries written like this:

SELECT ? + 4;

What's the meaning of ? ? My guess is it's some kind of parameter, but how does one specify the value for it?

Upvotes: 3

Views: 1797

Answers (2)

Paul Bellora
Paul Bellora

Reputation: 55213

? is a placeholder for parameter values in the syntax for prepared statements. The linked article gives the following example:

mysql> PREPARE stmt1 FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
mysql> SET @a = 3;
mysql> SET @b = 4;
mysql> EXECUTE stmt1 USING @a, @b;
+------------+
| hypotenuse |
+------------+
|          5 |
+------------+
mysql> DEALLOCATE PREPARE stmt1;

Since you also tagged , it's worth linking to the Prepared Statement Wikipedia article for further reading independent of MySQL.

Upvotes: 8

sorpigal
sorpigal

Reputation: 26086

In mysql a ? is a placeholder in a prepared statement. It will be replaced by whatever value is bound from the client before the statement is executed.

Upvotes: 3

Related Questions