2011-01-13 94 views
1

我想知道如何定义或声明的内部表在MySQL如何在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做这样

之前申报表内

,因为我希望把插入语句

IF actioncode = 1 
    Insert into @tbTemp 

所以请,如果你知道的告诉我如何为每一个

最诚挚的问候。

回答

4
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; 
+0

COOOOOOOOOL非常感谢你,这是解决我的问题! – HAJJAJ 2011-01-17 08:51:17

0

你的意思是CREATE TEMPORARY TABLE?这是一个特定于运行语句的连接的内存表,因此除非您运行持久连接,否则您不必担心名称冲突。

+0

校正:CREATE TABLE TEMPORARY不表示该表驻留在存储器中。这是通过创建语句末尾的type = MEMORY附录完成的。如果不指定类型,临时表将成为MyISAM表。与普通表唯一的区别是,当运行CREATE TEMPORARY TABLE的连接关闭时,会收集临时表(它的作用域为连接)。 – 0xCAFEBABE 2011-01-13 14:17:10