两个表
 CREATE TABLE `test2` (               
          `c1` int(11) DEFAULT NULL          
        ) ENGINE=InnoDB DEFAULT CHARSET=gbk   CREATE TABLE `test3` (               
          `str` varchar(100) DEFAULT NULL    
        ) ENGINE=InnoDB DEFAULT CHARSET=gbk  
test2
c1"13"
"2"
"14"
"4"
"5"
"6"
"7"
"8"
"9"
"10"
"11"
"12"
"13"
"14"test3 内容
str
会员你好,你*天的请假已经到期,请了解。存储过程:
DELIMITER$$
drop PROCEDURE if EXISTS proc_t1$$
create PROCEDURE proc_t1()
begin 
declare _str varchar(100);
select str into _str from test3;
-- select _str;
-- set _str='会员你好,你*天的请假已经到期,请了解。';
select replace(_str,'*',convert(c1,char(4)))
from test2;
end $$
DELIMITER ; call proc_t1;的结果为:
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
而不是我想要的结果:
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你2天的请假已经到期,请了解。"
"会员你好,你14天的请假已经到期,请了解。"
"会员你好,你4天的请假已经到期,请了解。"
"会员你好,你5天的请假已经到期,请了解。"
"会员你好,你6天的请假已经到期,请了解。"
"会员你好,你7天的请假已经到期,请了解。"
"会员你好,你8天的请假已经到期,请了解。"
"会员你好,你9天的请假已经到期,请了解。"
"会员你好,你10天的请假已经到期,请了解。"
"会员你好,你11天的请假已经到期,请了解。"
"会员你好,你12天的请假已经到期,请了解。"
"会员你好,你13天的请假已经到期,请了解。"
"会员你好,你14天的请假已经到期,请了解。"不知道为什么。

解决方案 »

  1.   

    直接试一下
    select replace('会员你好,你*天的请假已经到期,请了解。','*',convert(c1,char(4))) from test2;看结果是否是你要求的?
      

  2.   

    环境有问题? 我的测试结果:select * from test2;
    select * from test3;
    call proc_t1;
    query result(3 records)
    c1 
    13 

    3 query result(1 records)
    str 
    会员你好,你*天的请假已经到期,请了解。 
    query result(3 records)
    replace(_str,'*',convert(c1,char(4))) 
    会员你好,你13天的请假已经到期,请了解。 
    会员你好,你2天的请假已经到期,请了解。 
    会员你好,你3天的请假已经到期,请了解。 
    我的版本为:5.1.36-community-log
      

  3.   

    可以直接
    select replace(b.str,'*',convert(a.c1,char(4))) 
    from test2 a, test3 b ; 
    的出来想要的结果。