如何在MySQL中声明内部表?
我想知道如何在MySQL中定义或声明内部表 我是MySQL新手,不知道语法 如您所见,我创建了存储过程如何在MySQL中声明内部表?,mysql,sql,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.tbnew
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.
)
因为我想把insert语句放在
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;
或
更正:创建临时表并不表示该表驻留在内存中。这是通过creation语句末尾的type=MEMORY appendum完成的。如果不指定类型,则临时表将是MyISAM表。与普通表的唯一区别是,当运行创建临时表的连接关闭时,临时表被收集,它的作用域是连接。非常感谢,这就解决了我的问题!!
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;