首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql 存储过程 自定义表名异常

2012-05-09 
mysql 存储过程 自定义表名错误建立一个过程CREATE DEFINER`root`@`localhost` PROCEDURE `insert_me`(IN

mysql 存储过程 自定义表名错误
建立一个过程
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_me`(IN `Src` char(80),IN `Dst` char(80),in Uid char(30))
BEGIN
  declare Dbname varCHAR(32) DEFAULT('2012-05-07') ;
  IF Src <> '' and Dst <> '' then
insert into Dbname (calldate,src,dst,tag)
  select `calldata`,`src`,`dst`,`tag` from `ask`.`tome` WHERE uid = Uid;
  end if;
END

怎么在call insert_my('802','13632510278','1333107047.19') 总是提交test.Dbname 不存在呢?过程里Dbname 不是已经设为2012-05-07了吗

[解决办法]
set @asql='insert into Dbname (calldate,src,dst,tag)
select `calldata`,`src`,`dst`,`tag` from `ask`.`tome` WHERE uid = Uid';
prepare stml from @asql;
execute stml;
[解决办法]
set @asql=concat('insert into ',Dbname,' (calldate,src,dst,tag)
select `calldata`,`src`,`dst`,`tag` from `ask`.`tome` WHERE uid = Uid');
prepare stml from @asql;
execute stml;
[解决办法]

SQL code
SET @sqltext=concat('insert into ',Dbname,' (calldate,src,dst,tag)  select `calldata`,`src`,`dst`,`tag` from `ask`.`tome` WHERE uid = Uid'');    PREPARE sqlstr from @sqltext;    Execute sqlstr;
[解决办法]
SQL code
drop PROCEDURE if exists insert_me;CREATE PROCEDURE `insert_me`(IN `Src` char(80),IN `Dst` char(80),in Uid char(30))BEGIN  declare Dbname varCHAR(32) DEFAULT('2012-05-07') ;  SET @UUid = Uid;  IF Src <> '' and Dst <> '' then  SET @sqltext=concat('insert into ',Dbname,' (calldate,src,dst,tag)  select `calldata`,`src`,`dst`,`tag` from `ask`.`tome` WHERE uid = @UUid');    PREPARE sqlstr from @sqltext;    Execute sqlstr;  end if;END; 

热点排行