如果我执行下面的查询,它给我4个正确的记录。
select SUBSCRIBER_NUM, SUBSCRIBER_STATUS, P_ID
from C_S_FORWARD_INFO
where SUBSCRIBER_NUM IN ('0', '07', '070', '0705', '07052', '070526', '0705262', '07052620') and
SCP_VER = 1
但是当我执行下面的命令时,它给了我0条记录。实际上我必须动态地传递查询的“IN”部分的值。
我尝试了以下操作(VAR_CALLING_NUM = 07052620):
while var1<=len LOOP
temp1 := SUBSTR(VAR_CALLING_NUM, 1, var1);
temp1 := concat('''',temp1);
temp1 := concat(temp1,'''');
temp6 := temp6 || temp1 || ',' ;
var1:=var1+1;
END LOOP;
temp6 := SUBSTR(temp6, 1,length(temp6)-1);
select SUBSCRIBER_NUM, SUBSCRIBER_STATUS, P_ID from C_S_FORWARD_INFO where SUBSCRIBER_NUM IN ( temp6 ) and SCP_VER = 1 order by length(subscriber_num) desc;
为什么给我0条记录。我在SUBSCRIBER_NUM IN ( temp6 )
这样的查询中传递temp6是否做错了什么
2条答案
按热度按时间5cg8jx4n1#
您有一个类似
"'0', '07', . . ."
的字符串。这是单个字符串。in
不会将其解释为多个值。您需要使用动态SQL将其作为列表放入,这需要构造SQL,然后使用
execute immediate
。wlsrxk512#
您可以使用以下语法将单个字符串中的值转换为多个字符串,以便对IN子句有效。
(SELECT regexp_substr(YOUR_INPUT_VAR,'[^,]+', 1, level) AS list FROM dual CONNECT BY regexp_substr(YOUR_INPUT_VAR, '[^,]+', 1, level) IS NOT NULL)