一个奇怪的问题,急急急

tcxx2008 2012-09-04 02:01:24

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);

这样查询出来就有值的。


为什么会这样,如何解决呢?
...全文
116 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
tcxx2008 2012-09-04
  • 打赏
  • 举报
回复
感谢2位的解答。
yinan9 2012-09-04
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]
SQL code

--試下這個是不是你要的
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 ……
[/Quote]+1 楼主对in的理解有一点小误差,in后面跟的是一个list,而不是一个带逗号的字符串
人生无悔 2012-09-04
  • 打赏
  • 举报
回复

--試下這個是不是你要的
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);
tcxx2008 2012-09-04
  • 打赏
  • 举报
回复
1楼说的意思我大概理解了
用select语句的效果等于
 and to_char(r.stf_type_no) in
('3,4');

他把3,4作为集合中中一个。那是否可以显式的控制这个字符串就是一个集合呢?
tcxx2008 2012-09-04
  • 打赏
  • 举报
回复
仅有一条
yinan9 2012-09-04
  • 打赏
  • 举报
回复
单独运行(select stf_type from sly_customreport where report_id = 1) 获取的stf_type 为 3,4
楼主这里是一条记录呢,还是两条?
tcxx2008 2012-09-04
  • 打赏
  • 举报
回复
如何解决呢? 这个是关键呀!!!
人生无悔 2012-09-04
  • 打赏
  • 举报
回复

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);

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧