创建了这样一个存储过程create or replace procedure CS_SELKG
(
       V_CONDTION VARCHAR2,
       V_CURSOR OUT SYS_REFCURSOR
)
IS 
BEGIN
     open v_cursor for  select a.s_txm,b.content from shuibiaoxx a
      inner join (
     select * from words where belongid='106'
              ) b on a.s_ztid=b.wordsid 
            where a.s_txm in(V_CONDTION);
END CS_SELKG存储过程调试时发现  
当 存储过程中  V_CONDTION 变量值为一个值  如  select………… in(123)
调试时候游标中有一条记录 。
 
但是当  V_CONDTION 变量值为2 个值或以上值 如  select………… in(123,456)
游标中的结果为空表 该问题应该是 给 V_CONDTION变量赋值 123,456 是 系统认为   123,456 是一个字符串 而不是以逗号分隔开的两个字符串 
 请问各位  
我想在存储过程中实现类似如 select …… in(V_CONDTION ) 多个值 
 该怎么实现 ?特别说明 存储过程中V_CONDTION 变量值 是程序中窗体输入值 ,无法在存储过程中使用exists …

解决方案 »

  1.   

    改成execute immediate执行
    因V_CONDTION你这个是一个字符串,并不是一个数字的集合,不能这样用的
      

  2.   


    --改成下面这种试下
    open v_cursor for 'select a.s_txm,b.content from shuibiaoxx a
      inner join (
      select * from words where belongid='106'
      ) b on a.s_ztid=b.wordsid  
      where a.s_txm in('||V_CONDTION||')';
      

  3.   


    open v_cursor for 'select a.s_txm,b.content from shuibiaoxx a
      inner join (
      select * from words where belongid=''106''--此处我写错了也可以去掉''直接106,毕竟是数字
      ) b on a.s_ztid=b.wordsid  
      where a.s_txm in('||V_CONDTION||')';
      

  4.   


    --这是我写的个简单的例子,你看下
    SQL> declare
      2      type cur_type is ref cursor;
      3      cur cur_type;
      4      rec emp%rowtype;
      5      str varchar2(50);
      6      letter varchar2(50):= '7369,7566';
      7  begin
      8      str:= 'select ename from emp where empno in ('||letter||')';
      9      open cur for str;
     10      loop
     11          fetch cur into rec.ename;
     12          exit when cur%notfound;
     13          dbms_output.put_line(rec.ename);
     14      end loop;
     15  end;
     16  /
    SMITH                                                                           
    JONES   
    --源码
    declare
        type cur_type is ref cursor;
        cur cur_type;
        rec emp%rowtype;
        str varchar2(50);
        letter varchar2(50):= '7369,7566';
    begin
        str:= 'select ename from emp where empno in ('||letter||')';
        open cur for str;
        loop
            fetch cur into rec.ename;
            exit when cur%notfound;
            dbms_output.put_line(rec.ename);
        end loop;
    end;
    /
      

  5.   


    --先打印出sql语句,然后直接执行你打印的语句看有无记录
    set serveroutput on;
    declare
        V_CONDTION varchar2(1000):= '1,2,3,4';--换成你的值
    v_str varchar2(4000):='';
    begin
        v_str:= 'select a.s_txm,b.content from shuibiaoxx a
    inner join (
    select * from words where belongid=''106''
    ) b on a.s_ztid=b.wordsid  
    where a.s_txm in('||V_CONDTION||')';
        dbms_output.put_line(v_str);
    end;
    /--用这个语句看下有无记录
    select a.s_txm,b.content from shuibiaoxx a
    inner join (
    select * from words   
    where belongid='106'
    ) b on a.s_ztid=b.wordsid
    where a.s_txm in(1,2,3,4);  --1,2,3,4,换成你的值