CREATE PROCEDURE sp1 (x VARCHAR(5)) BEGIN DECLARE newname VARCHAR(5);
SELECT xname INTO newname FROM table1 WHERE xname = x; END;
在拼串里面可以把变量传出来吗? 例如我新建的存储过程: create procedure proc_get_use_score ( userID int ,yyyymm varchar(30) ) declare sql1 varchar(2000); set sql1='select sum(amount) from expense where 1=1 '; if userID<>0 then set sql1=Contact(sql1,' and userID=\'',userID,'\''); end if if (yyyymm is not null and yyyymm<>'') set sql=Contact(sql1,' and date_format(generate_dt,\'%Y%m\')=\'',yyyymm,'\''); end if set @sql=sql1; prepare sl from @sql; execute sl; deallocate prepare sl; end 我想获得sum(amount)的值,一边参与运算,应该如何写啊?
BEGIN
DECLARE newname VARCHAR(5);
SELECT xname INTO newname
FROM table1 WHERE xname = x;
END;
例如我新建的存储过程:
create procedure proc_get_use_score
(
userID int
,yyyymm varchar(30)
) declare sql1 varchar(2000);
set sql1='select sum(amount) from expense where 1=1 ';
if userID<>0 then
set sql1=Contact(sql1,' and userID=\'',userID,'\'');
end if
if (yyyymm is not null and yyyymm<>'')
set sql=Contact(sql1,' and date_format(generate_dt,\'%Y%m\')=\'',yyyymm,'\'');
end if
set @sql=sql1;
prepare sl from @sql;
execute sl;
deallocate prepare sl;
end
我想获得sum(amount)的值,一边参与运算,应该如何写啊?