在使用变量进行拼接sql时,需要使用动态sql执行,execute immediate 动态sql;如果动态sql中具有单引号,需要将 单引号 变成 单引号单引号 ;如:
execute immediate 'insert into visit
(visitid,
begintime,
endtime,
pages,
tvcard,
provinceareacode,
cityareacode,
statdate,
channelcode)
Select id,
Min(visitDate),
Max(visitDate),
count(distinct url) pages,
v.tv_card_id,
v.provinceareacode,
v.cityareacode,
to_date(to_char(v.visitdate, ''yyyy-MM-DD''), ''yyyy-MM-DD''),
v.channelcode
from visit_month_'||v_tableName||' v
group by id,
v.tv_card_id,
v.provinceareacode,
v.cityareacode,
to_char(v.visitdate, ''yyyy-MM-DD''),
v.channelcode';
在存储过程中抛出异常:raise_application_error('-20002', 'you can not change the data !');调试的时候常用;