Kim
Kim

Reputation: 11

How to Declare table to variable in MARIADB/MYSQL for function/procedure?

I don't know how to operate MySQL DECLARE THIS TABLE?

MS_SQL CAN 
DECLARE @TEMP TABLE 
(variable INT)  

But MySQL can't do this! How can i do it?

Syntax error !!

Upvotes: 1

Views: 5085

Answers (2)

Rick James
Rick James

Reputation: 142298

If you need to make a table or database name come from an argument or variable, you will need to

  1. Construct the query, probably using CONCAT.
  2. PREPARE the query.
  3. EXECUTE the query.
  4. DEALLOCATE PREPARE.

Upvotes: 0

Bill Karwin
Bill Karwin

Reputation: 562358

MySQL does not have the feature of declaring a variable for a table. Variables can only be scalars.

If you need a feature that Microsoft SQL Server supports, then you should use Microsoft SQL Server.

Also when you use DECLARE in MySQL, you can't use the @ sigil on variables. Local variables in stored routines don't have that sigil in MySQL. This is another difference from Microsoft SQL Server.

Upvotes: 1

Related Questions