读书人

Oracle中instr的方法有没有替代的多

发布时间: 2012-10-06 17:34:01 作者: rapoo

Oracle中instr的方法,有没有替代的谢谢

SQL code
if v_Productgroup is not null then     if instr(v_Productgroup,',')>0 then        strWhere := strWhere || ' and instr ('''||v_Productgroup|| ''',s.Productgroup)>0';     else        strWhere := strWhere || ' and s.Productgroup = '''||v_Productgroup||'''';     end if;  end if;


在上面的代码中v_Productgroup是定义的传入参数,
它的值: "Oracle" 或者 "Oracle,OracleBase" 或者 "Oracle,OracleBase,SQL" 或者 "Oracle,OracleBase,SQL,SQLBase"

在使用instr的时候当传入的是"Oracle"把"OracleBase"的记录也查询出来了,请问这样的情况怎么解决,尽量改动较少就能解决,谢谢。

[解决办法]
把v_Productgroup前后加上逗号,s.productgroup前后也加上逗号,然后再调instr

例如 v_Productgroup := 'OracleBase,SQL'
前后加上逗号变成 ',OracleBase,SQL,'

如果s.productgroup等于'Oracle',在',OracleBase,SQL,'查找于',Oracle,',instr返回0;
如果s.productgroup等于'OracleBase',在',OracleBase,SQL,'查找于',OracleBase,',instr返回大于0;

[解决办法]
strWhere := strWhere || ' and instr ('_'||v_Productgroup|| '_','_'||s.Productgroup|| '_')>0';

读书人网 >oracle

热点推荐