存储过程中定义的一个字符串,在to_date函数出错。出错代码如下:望高人解答:
month_str:='select count(t.var_id) from wjc_inde_data_his t where t.var_id like ''%R'' and
t.data_time>=to_date('||start_month||',''YYYY-MM-DD HH24:MI:SS'') and
t.data_time<to_date('||stop_month||',''YYYY-MM-DD HH24:MI:SS'')';错误提示:
ORA-00907: 缺失右括号
ORA-06512: 在 "WJC.CALHISMIS", line 32
ORA-06512: 在 line 1
month_str:='select count(t.var_id) from wjc_inde_data_his t where t.var_id like ''%R'' and
t.data_time>=to_date('||start_month||',''YYYY-MM-DD HH24:MI:SS'') and
t.data_time<to_date('||stop_month||',''YYYY-MM-DD HH24:MI:SS'')';错误提示:
ORA-00907: 缺失右括号
ORA-06512: 在 "WJC.CALHISMIS", line 32
ORA-06512: 在 line 1
外部变量加:
month_str:='select count(t.var_id) from wjc_inde_data_his t where t.var_id like ''%R'' and
t.data_time>=to_date('''||start_month||''',''YYYY-MM-DD HH24:MI:SS'') and
t.data_time<to_date('''||stop_month||''',''YYYY-MM-DD HH24:MI:SS'')';
declare
month_str varchar2(200);
begin
month_str:='select count(t.var_id) from wjc_inde_data_his t where t.var_id like ''%R'' and
t.data_time>=to_date('||sysdate||',''YYYY-MM-DD HH24:MI:SS'') and
t.data_time<to_date('||sysdate||',''YYYY-MM-DD HH24:MI:SS'')';
dbms_output.put_line(month_str);
end;
得到结果
select count(t.var_id) from wjc_inde_data_his t where t.var_id like '%R' and
t.data_time>=to_date(15-4月 -10,'YYYY-MM-DD HH24:MI:SS') and
t.data_time<to_date(15-4月 -10,'YYYY-MM-DD HH24:MI:SS')
t.data_time>=to_date(''' || start_month || ''',''YYYY-MM-DD HH24:MI:SS'') and
t.data_time<to_date(''' || stop_month || ''',''YYYY-MM-DD HH24:MI:SS'')';
dbms_output.put_line(month_str);