今天写了一个测试的存储过程:
create or replace procedure preparedData_up
as
modSql varchar2(500); --修改sql语句
tempValue number(18,4);
begin
modSql:='update t_mms_staff_stat_test set ';
tempValue:=0;
--sm01_sales_amnt;
select sum(amount_td) into tempValue from items_sales
where store='csst1';
modSql := modSql [color=red]||[/color]' sm01_sales_amnt=' [color=red]||[/color] tempValue;
--sm02_sales_amnt;
select sum(amount_td) into tempValue from items_sales
where store='csst2';
modSql :=modSql[color=red]||[/color]',sm02_sales_amnt=' [color=red]||[/color] to_char(tempValue,'FM9999999999999999990.00');
--sm03_sales_amnt;
select sum(amount_td) into tempValue from items_sales
where store='csst3';
modSql :=modSql[color=red]||[/color]',sm03_sales_amnt=' [color=red]||[/color] to_char(tempValue,'FM9999999999999999990.00');
--modSql :='update t_mms_staff_stat_test set '[color=red]+[/color]modSql;
execute immediate modSql;
end preparedData_up;
编译通过,可执行的时候报ora-06502 charactor to number convertion error,
以为是数字类型该转成字符串的,所以用了to_char,但依然报错,郁闷了半天,最后终于发现是连接符的问题,我用了‘+’而不是‘||’,汗了一把,好像碰到好几回了……
create or replace procedure preparedData_up
as
modSql varchar2(500); --修改sql语句
tempValue number(18,4);
begin
modSql:='update t_mms_staff_stat_test set ';
tempValue:=0;
--sm01_sales_amnt;
select sum(amount_td) into tempValue from items_sales
where store='csst1';
modSql := modSql [color=red]||[/color]' sm01_sales_amnt=' [color=red]||[/color] tempValue;
--sm02_sales_amnt;
select sum(amount_td) into tempValue from items_sales
where store='csst2';
modSql :=modSql[color=red]||[/color]',sm02_sales_amnt=' [color=red]||[/color] to_char(tempValue,'FM9999999999999999990.00');
--sm03_sales_amnt;
select sum(amount_td) into tempValue from items_sales
where store='csst3';
modSql :=modSql[color=red]||[/color]',sm03_sales_amnt=' [color=red]||[/color] to_char(tempValue,'FM9999999999999999990.00');
--modSql :='update t_mms_staff_stat_test set '[color=red]+[/color]modSql;
execute immediate modSql;
end preparedData_up;
编译通过,可执行的时候报ora-06502 charactor to number convertion error,
以为是数字类型该转成字符串的,所以用了to_char,但依然报错,郁闷了半天,最后终于发现是连接符的问题,我用了‘+’而不是‘||’,汗了一把,好像碰到好几回了……