存储过程中定义的一个字符串,在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

解决方案 »

  1.   

    start_month 外部变量?还是....
    外部变量加:
      

  2.   

    外部变量传入.处理后赋予start_month和stop_month
      

  3.   

    --改成这样试试
    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'')';
      

  4.   

    调试了下你的语句
    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')
      

  5.   

     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'')';
      dbms_output.put_line(month_str);