简体   繁体   English

在过程MySql中创建临时表

[英]Create temporary table in procedure, MySql

I need create a simple procedure, but after create a temporary table, mysql wants put 'end' after semicolon. 我需要创建一个简单的过程,但是在创建临时表后,mysql希望在分号后放置“ end”。

 CREATE procedure zad2()

    begin
    drop temporary table if exists temp;
    create temporary table temp as (select table_name, column_name 
      from information_schema.columns  where table_schema = 'lista3' and table_name not like 'lista');

    declare i int default 0;
    end$$

SQL Stored procedure have a block where you will put all code/logic .. and that block is BEGIN and END , if you have an opening block which is BEGIN , you need to close it with END , that's why MySql wants you to put END after semi colon. SQL存储过程有一个块,您将在其中放置所有代码/逻辑..那个块是BEGINEND ,如果您有一个开始块,即BEGIN ,则需要用END将其关闭,这就是MySql希望您放入END在半冒号之后。

Below link can help with the syntax: 下面的链接可以帮助语法:

CREATE PROCEDURE and CREATE FUNCTION Syntax 创建过程和创建函数语法

I think that what is missing is to declare the DELIMITER $$ at the start of the statement: 我认为缺少的是在语句开始时声明DELIMITER $$:

DELIMITER $$ /*To tell MySQL that your delimiter is now '$$'    */
CREATE procedure zad2()

        begin
        drop temporary table if exists temp;
        create temporary table temp as (select table_name, column_name 
          from information_schema.columns  where table_schema = 'lista3' and table_name not like 'lista');

        declare i int default 0;
        end$$
DELIMITER ; /*To tell your MySQL that you delimiter is back ';'     */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM