mysql - MySQL中如何声明内表?

标签 mysql sql

我想知道如何在MySQL中定义或声明内表

我是 MySQL 新手,我不知道语法

如您所见,我创建了存储过程

CREATE DEFINER=`root`@`localhost` PROCEDURE `MySP`(
    actioncode VARCHAR(5),
    TNewsID BIGINT
)

BEGIN

IF actioncode = 1 then -- Retrive all from the database --
    select *
    from emp.tbnews;
elseIF actioncode = 2 then -- Retrive all from the database By NewsID --
    select NewsID,NewsSubject,NewsSubjectAR,NewsDetails,NewsDetailsAR,CreatedOn,DisplayOrder,
           AllowDisplay,img  
    from emp.tbnews
    Where NewsID=TNewsID;
elseIF actioncode = 3 then -- fkjskldfjklsdf --
    select NewsID,NewsSubject,NewsSubjectAR,NewsDetails,NewsDetailsAR,CreatedOn,DisplayOrder,
           AllowDisplay,img  
    from emp.tbnews;

 END IF;
 END

我真正想要的是在 IF 语句之前声明内部表

在 Sql Server 中我这样做

declare  @tbTemp table (
 a as int,
 b as char...etc.
)

因为我想在后面添加插入语句

IF actioncode = 1
    Insert into @tbTemp

如果你知道的话请告诉我怎么做

向大家致以最诚挚的问候。

最佳答案

create temporary table tmp
(
id int unsigned not null,
name varchar(32) not null
)
engine=memory; -- change engine type if required e.g myisam/innodb

insert into tmp (id, name) select id, name from foo... ;

-- do more work...

select * from tmp order by id;

drop temporary table if exists tmp;

create temporary table tmp engine=memory select id, name from foo... ;

-- do more work...

select * from tmp order by id;

drop temporary table if exists tmp;

关于mysql - MySQL中如何声明内表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4680886/

相关文章:

sql - 将查询结果返回到 Grails 中的 View

java - 在 Hibernate 中提取 *HQL*

java - 在表中保留最新的 n 个条目

php - 从多个表复制列值并插入 Laravel 中的第三个表

php - 在 Doctrine : curious database generation 中使用抽象子类

php - For循环检索相同的mysql行

php扩展类连接mysql问题

mysql - 选择一个表中的每一行以及另一个表中的相关行

c# - 如何实现历史版本控制?

mysql - 使用左连接或右连接连接四个表