gpt4 book ai didi

mysql - 如何在MySQL中声明内表?

转载 作者:行者123 更新时间:2023-11-29 04:57:59 24 4
gpt4 key购买 nike

我想知道如何在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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com