User-defined Table Variables in MySQL 5.5?

colonel_px picture colonel_px · Aug 29, 2011 · Viewed 7.8k times · Source

I've recently moved from MSSQL to MySQL.

I would like to use a table variable (or equivalent) inside a MySQL 5.5 stored routine, to populate a dataset for an online report.

In MS SQL, I would do it this way

...
...
DECLARE @tblName TABLE
WHILE <condition>
BEGIN
    Insert Row based on iteration value
END
...
...

From what I understand, I can't declare table variables in MySQL (correct me if I'm wrong) How do I implement the above logic in a MySQL stored procedure?

Answer

Devart picture Devart · Aug 29, 2011

You could create a table or temporary table and populate it with data you need.

CREATE TABLE Syntax