读书人

oracle方面的有关问题请

发布时间: 2012-03-30 17:32:09 作者: rapoo

oracle方面的问题,请高手指点
select * from functions where
CHARINDEX('(('+convert(varchar,funid)+'))',
(select funid from (select * from users u,roles r where u.roles_id=r.rid and u.users_id='1042')
ur,roles_functions rf where ur.rid=rf.rid))>0 and father_id='1';

请各位大侠帮我分析下上面的sql语句是什么意思。
请中select * from functions 的查询结果是:
funid funname funurl father_id isfold
1021管理中心 d0 1

其中select funid from (select * from users u,roles r where u.roles_id=r.rid and u.users_id='1042')
ur,roles_functions rf where ur.rid=rf.rid的查询结果是
funid
((2)),((3)),((4)),((5)),((6))


[解决办法]
这个是sql server的语句吧,
oracle中无charindex函数,虽有convert函数,但意义不一样
charindex是搜索字符串,oracle中的对应函数是instr,不过前两个参数正好相反

从表functions中查询father_id=1并且满足(从子查询中得到的funid)中存在'(('字符串的记录。
[解决办法]

SQL code
--sql server 中的charindex,在oracle中可以用instr函数替代:instr(str,chr)   ---chr在str中第1次出现的位置 instr(str,chr,3,2)   ---从str第3个字符位置开始搜索chr在str中第2次出现的位置 instr(str,chr,-3,2)   ---从str的从右向左数第3个字符位置开始反向搜索chr在str中第2次出现的位置 

读书人网 >oracle

热点推荐