declare
v_str varchar2(32767);
v_num number;
begin
v_str := '''124''';
v_str := v_str || ',';
v_str := v_str || '''B737-700''';
select count(*) into v_num from item where itemnum in (v_str);
dbms_output.put_line(v_str|| ' ' ||v_num);
end;输出结果:'124','B737-700' 0
说明v_str为'124','B737-700',而itemnum in (v_str)应该为itemnum in ('124','B737-700')
但是输出结果为空;
select count(*) into v_num from item where itemnum in ('124','B737-700');这个结果为2

解决方案 »

  1.   

    v_str := 'select count(*) into v_num from item where itemnum in ('|| v_str ||')';execute immediate v_str;
      

  2.   

    前面的字符串连接你都知道用||select count(*) into v_num from item where itemnum in (v_str);
    这条语句你为什么就可以直接连接起来
      

  3.   

    我就想搞清楚:我不用动态语言为什么不可以!?
    -------------------------------------------------------------------------
    因为 v_str 是一个字符串' '124','B737-700' ',而不是一组字符串 '124','B737-700'。
      

  4.   

    不用动态SQL相当于
    in('''124'',''B737-700''')
    你说可能可以吗?
      

  5.   

    好的!谢谢各位!libin_ftsafe(子陌红尘:当libin告别ftsafe),doer_ljy(可战) ,tgm78() ,letsflytogether(伍子) 明天结贴
      

  6.   

    select * from t
    where instr(v_str,''''|| itemnum ||'''') >0;
    --or:vstr :='124,B737-700' 
    vstr :=','|| vstr || ',' select * from t
    where instr(v_str,','|| itemnum ||',') >0;