这个存储过程的部分代码如下……
begin
 select id,name,type from tablename where id=p_id and name=p_name and 
instr(p_other,','||type||',')>0;
end;
……传入参数字符串格式  ',aaa,bbb,ccc,...,'

解决方案 »

  1.   

    你可以动态拼凑Sql语句,然后动态执行就可以了!
      strsql:='select id,name,type from tablename where id=p_id and name=p_name and type not in(p_other)';
      execute immediate strsql;
      

  2.   

    TO  bzszp(SongZip) 
    原:
    select id,name,type from tablename where id=p_id and name=p_name and type not in(p_other);您的:
    select id,name,type from tablename where id=p_id and name=p_name and 
    instr(p_other,','||type||',')>0;请问是不是
    select id,name,type from tablename where id=p_id and name=p_name and 
    instr(p_other,','||type||',')<=0;我对instr(str1,str2)函数不太清楚, 是不是:检测str2是否为str1的子串,如果是返回的一定为大于0的数(即str2在str1中字串的开始位置)
    如此看来是不是下面这样也可以得到我的目的,请bzszp(SongZip)老师指点,学生感激不尽!select id,name,type from tablename where id=p_id and name=p_name and 
    instr(p_other,type)<=0;
      

  3.   

    select id,name,type from tablename where id=p_id and name=p_name and 
    instr(p_other,type)>0;如果type字段中的字符串 包含在 p_other 的字符串中 返回 开始位置(n>0)
    否则,返回0应当就是这样的,不是<=0.
      

  4.   

    instr:Finds numeric position of a named character
    如:
    select instr('String','r')
    结果为3
      

  5.   

    请问bzszp(SongZip)老师
    您是不是没有看清:……and type not in(p_other)……;
    是 NOT IN (P_OTHER)
    所是是不是应该select id,name,type from tablename where id=p_id and name=p_name 
    and instr(p_other,type)=0;
      

  6.   

    用not in 达不到你的目的。instr(p_other,type)如果type字段中的字符串 包含在 p_other 的字符串中 返回 存在的位置n(n>=1)
    否则,返回016:31:32 SQL> select instr(',aaa,bbb,ccc,',',ccc,') from dual;INSTR(',AAA,BBB,CCC,',',CCC,')
    ------------------------------
                                 9已用时间:  00: 00: 00.63
    17:43:37 SQL> select instr(',aaa,bbb,ccc,',',ddd,') from dual;INSTR(',AAA,BBB,CCC,',',DDD,')
    ------------------------------
                                 0已用时间:  00: 00: 00.16
    17:44:40 SQL> ',ccc,'包含在',aaa,bbb,ccc,'里面,返回存在的位置9
    ',ddd,'不在',aaa,bbb,ccc,'里面,返回0明白了吧。
      

  7.   

    select id,name,type from tablename where id=p_id and name=p_name and 
    instr(p_other,','||type||',')=0;
    应该用字符串"','||type||','",前提是你输入的p_other格式为",ee,ff,",
    用instr(p_other,type)这样的格式可能会有问题,例如type为e,f 而你的p_other为"ee,ff",就出问题了
      

  8.   

    用动态sql或动态cursor
    即 cursor c1 is
         ....
       where ... and type not in (var1,var2....) ; 然后
      open c1(valuale1,valuale2....)
      ....应该可以吧,未试过啊,测试一下吧!
      

  9.   

    TO bzszp(SongZip) 老师,NOT IN 就是要达到我的目的,所以我想我用
    select id,name,type from tablename where id=p_id and name=p_name 
    and instr(p_other,type)=0;
    应该没有错了!
    老师您的心真好!
    不过 qiaozhiwei(乔)老师提出的问题也不能不考虑!
    TO  qiaozhiwei(乔)老师那你有什么别的办法吗?
      

  10.   

    没有看明白分割符',' 是什么意思?
    lotusfromwater(出水芙蓉)想使用的是:
    select id,name,type from tablename where id=p_id and name=p_name 
    and instr(p_other,type)=0;
    为什么两位高手说要使用instr(p_other,','||type||',')=0;???
    是为了防止出现逗号(,)么?  什么时候会出现逗号呢?