有一列ID保存在字符串中: "111,222,333,444,555,666"
现在想查找这列ID中,哪些是错误的,也就是不存在表中的。下面这段SQL可能会帮助理解需求。
select * from table t where (889814, 889820, 889828) not in t.id
现在想查找这列ID中,哪些是错误的,也就是不存在表中的。下面这段SQL可能会帮助理解需求。
select * from table t where (889814, 889820, 889828) not in t.id
解决方案 »
- 关于JDBC连接ORACLE的问题~~~~~~~~~~~~~
- 请教一个查询语句怎么用?
- 怎么查看本机某个数据库的连接字符串(很菜鸟)
- oracle 中%type怎么使用啊
- sql题目,请帮着写四句语句
- "Note:From Oracle 10g you don't need to put the "/AS SYSDBA" in quotes anymore."是什么意思?
- 关于日期格式?????????????????????????????????
- 怎么解决数据倒入时提示IMP-00016:不支持要求的字符集转换(从类型871到852)错误?
- LONG RAW 字段与SQL的IMAGE字段有什么区别?从LONG RAW字段中怎么取出??
- [讨论]这样的SQL怎么写?
- oracle性能问题
- (急)oracle 根据当前日期得到季节(类似SQL的datepart函数)
(
select '111,222,333,444,555,666' id from dual
),
tb1 as( --将字符串拆分成表
select rtrim(ltrim(substr(id, 4 * (rownum - 1), 4), ','), ',') newid
from tb
connect by rownum <= length(id) - length(replace(id, ',', '')) + 1
),
tb2 as(
select '111' id from dual union all
select '333' from dual)
select * from tb1
where not exists(select null from tb2 where tb1.newid=tb2.id)
--查找字符串'111,222,333,444,555,666'中不存在tb2中的那些字符串NEWID
--------
666
555
222
444
--首先要将你字串“111,222,333,444,555,666”拆分成一个一个的,然后跟你另外的表去做判断
with tab as(
select '111,222,333,444,555,666' id from dual
)
select substr(','||id||',',instr(','||id||',',',',1,level)+1,
instr(','||id||',',',',1,level+1)-instr(','||id||',',',',1,level)-1) newid
from tab
connect by
level <= length(','||id||',') - length(replace(','||id||',', ',', ''))-1NEWID
--------
111
222
333
444
555
666