MySQL stored procedure cursor for prepared statements

后端 未结 2 713
予麋鹿
予麋鹿 2021-02-06 03:20

I have a two tables:

people_en: id, name
people_es: id, name

(please, dont bother about normalization. the design is normalized. the tables are

2条回答
  •  一整个雨季
    2021-02-06 03:38

    @clickstefan, you will have problems with two or more users trying to execute your script at the same time. The second user will get error message 'View vw_myproc already exists' for the line:

    SET @select = concat('CREATE VIEW vw_myproc as SELECT * FROM ', lang, ' limit 3');
    

    The solution is temporary table - it exists for the lifetime of current connection only, and users may simultaneously create temporary tables with the same name. So, code may looks like:

    DROP TABLE IF EXISTS vw_myproc;
    SET @select = concat('CREATE TEMPORARY TABLE vw_myproc AS SELECT * FROM ', lang, ' limit 3');
    

提交回复
热议问题