select r.stf_type_no, i.*
from sly_staffincome i, stf_type_relation r
where i.stf_code = r.stf_code
and to_char(r.stf_type_no) in
(select stf_type from sly_customreport where report_id = 1);
如上查询为空。
单独运行(select stf_type from sly_customreport where report_id = 1) 获取的stf_type 为 3,4然后把上面的语句改成select r.stf_type_no, i.*
from sly_staffincome i, stf_type_relation r
where i.stf_code = r.stf_code
and to_char(r.stf_type_no) in
(3,4);这样查询出来就有值的。
为什么会这样,如何解决呢?
select stf_type from sly_customreport where report_id = 1
--運行出來為3,4
說明 stf_type值為'3,4'字符串而下面的是:3和4兩個數字的集合, 不是一個概念
select r.stf_type_no, i.*
from sly_staffincome i, stf_type_relation r
where i.stf_code = r.stf_code
and to_char(r.stf_type_no) in
(3,4);
楼主这里是一条记录呢,还是两条?
用select语句的效果等于
and to_char(r.stf_type_no) in
('3,4');他把3,4作为集合中中一个。那是否可以显式的控制这个字符串就是一个集合呢?
--試下這個是不是你要的
select r.stf_type_no, i.*
from sly_staffincome i, stf_type_relation r
where i.stf_code = r.stf_code
and exists(select 1 from sly_customreport where report_id=1 and
instr(','||sly_customreport.stf_type||',',','||r.stf_type_no||',')>0);