输入参数b varchar2 '1,2,3,4,5,6,7 '
但是过程 中查询的时候是select * from table where id in(b)
这样查询出来的效果是select * from table where id in('1,2,3,4,5,6,7')
注意,请不要说用instr这个函数,这个函数我刚刚测了一下,没有得到好的效果,
当表中 id 有一个为1,有一个 为11时,
输入参数 b:='11,2'
select * from table where id in(b);
oracle会返回三个值 ,把id为1,11,2都会返回,不信的可以去试试
但是过程 中查询的时候是select * from table where id in(b)
这样查询出来的效果是select * from table where id in('1,2,3,4,5,6,7')
注意,请不要说用instr这个函数,这个函数我刚刚测了一下,没有得到好的效果,
当表中 id 有一个为1,有一个 为11时,
输入参数 b:='11,2'
select * from table where id in(b);
oracle会返回三个值 ,把id为1,11,2都会返回,不信的可以去试试
v_sql:="select * from table where id in('1,2,3,4,5,6,7')";
exec immediate v_sql;
sp中:
b:= ','||b||',';
select * from table where
instr(b,','||to_char(id)||',') > 0;
b:='11,2'sp中:
b:= ','||b||',';
select * from table where
instr(b,','||to_char(id)||',') > 0; 你这样还是会把 id为1,11,2的三个都测试出来,我刚刚已经测了
create or replace procedure test(a IN varchar2) is
b varchar2(200);
beginb:= ','||a||',';
select count(*) into b from test1 where INSTR(b,id )>0;
dbms_output.put_line(b);
end;
这是表的记录:
ID
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 11然后测试存储过程,
a的value值是 11,2
要不要我把脚本全部放上来?
我不知道你有没有看清我上面的回复,我的回复内容是这样的:
sp中:
b:= ','||b||',';
select * from table where
instr(b,','||to_char(id)||',') > 0;
SQL> SELECT * FROM TEST_B; BID CID
---------- ----------
11 5
1 1
2 1
3 2
4 2
5 36 rows selectedExecuted in 0.016 seconds-- 错误的:
SQL> SELECT *
2 FROM TEST_B
3 WHERE INSTR('11,4,5',BID) > 0; BID CID
---------- ----------
11 5
1 1
4 2
5 3Executed in 0.016 seconds-- 正确的:
SQL> SELECT *
2 FROM TEST_B
3 WHERE INSTR(','||'11,4,5'||',',','||BID||',') > 0; BID CID
---------- ----------
11 5
4 2
5 3Executed in 0.015 seconds
你可以 把 '11,2' 加工成 ',11,2,'
字段也加工成',1,'
这样就可以用instr了
----------
1
2
3
4
5
6
7
118 rows selectedSQL> select * from test1 where instr(',11,2,',id) > 0; ID
----------
1
2
11SQL> 回13楼,14楼,还是没用,我刚刚试了下,还是会找到三个值!
2 FROM TEST_B
3 WHERE INSTR(','||'11,4,5'||',',','||BID||',') > 0;