Oracle SQL - 표에 없는 값 찾기
이 표를 사용하십시오. WORDS
WORD
Hello
Aardvark
Potato
Dog
Cat
다음 목록:
('Hello', 'Goodbye', 'Greetings', 'Dog')
단어 테이블에 없지만 내 목록에 있는 단어 목록을 반환하려면 어떻게 해야 합니까?
가능한 모든 단어를 포함하는 표가 있는 경우 다음 작업을 수행할 수 있습니다.
SELECT * from ALL_WORDS_TABLE
where word in ('Hello', 'Goodbye', 'Greetings', 'Dog')
and word not in
(SELECT word from WORDS
where word in ('Hello', 'Goodbye', 'Greetings', 'Dog')
);
하지만 저는 그런 테이블을 가지고 있지 않습니다.다른 방법이 있습니까?
또한, 해당 수준의 액세스 권한이 없기 때문에 새 테이블을 구성하는 것은 선택사항이 아닙니다.
리스트 값을 행으로 하드 코딩하는 대신DBMS_DEBUG_VC2COLL
구분된 목록을 행으로 동적으로 변환하려면 다음을 사용합니다.MINUS
연산자를 사용하여 첫 번째 쿼리에 없는 두 번째 쿼리의 행을 제거합니다.
select column_value
from table(sys.dbms_debug_vc2coll('Hello', 'Goodbye', 'Greetings', 'Dog'))
minus
select word
from words;
다음 솔루션을 사용해 보십시오.
SELECT
a.word
FROM
(
SELECT 'Hello' word FROM DUAL UNION
SELECT 'Goodbye' word FROM DUAL UNION
SELECT 'Greetings' word FROM DUAL UNION
SELECT 'Dog' word FROM DUAL
) a
LEFT JOIN ALL_WORDS_TABLE t ON t.word = a.word
WHERE
t.word IS NULL
목록을 다음과 같은 보기로 전환할 수 있습니다.
select 'Hello' as word from dual
union all
select 'Goodbye' from dual
union all
select 'Greetings' from dual
union all
select 'Dog' from dual
그런 다음 다음 중에서 선택할 수 있습니다.
select * from
(
select 'Hello' as word from dual
union all
select 'Goodbye' from dual
union all
select 'Greetings' from dual
union all
select 'Dog' from dual
)
where word not in (select word from words);
아마도 당신이 기대했던 것만큼 깔끔한 해결책은 아닐 것입니다.
테이블을 만들 수 있는 권한이 충분하지 않다고 해서 유형도 만들 수 없습니다. 하지만 데이터베이스에서 "뒤돌아다니는" 적절한 유형을 찾을 수 있다면 다음 작업을 수행할 수 있습니다.
select * from table (table_of_varchar2_type('Hello','Goodbye','Greetings','Dog'))
where column_value not in (select word from words);
여기서table_of_varchar2_type
는 다음과 같이 정의된 유형의 이름으로 상상됩니다.
create type table_of_varchar2_type as table of varchar2(100);
당신이 찾을 수 있는 그런 유형 중 하나는 다음과 같습니다.SYS.KU$_VCNT
이것은 VARCHAR2(4000)의 표입니다.
언급URL : https://stackoverflow.com/questions/9996797/oracle-sql-find-the-values-not-in-a-table
'source' 카테고리의 다른 글
ORA-00980 동의어 변환은 PLSQL에서 더 이상 유효하지 않습니다. (0) | 2023.07.21 |
---|---|
하루의 시간을 어떻게 비교합니까? (0) | 2023.07.21 |
SpringBoot 1.3.0은 최대 절전 모드 5를 지원합니까? (0) | 2023.07.21 |
0으로 채워진 판다 데이터 프레임 만들기 (0) | 2023.07.21 |
가장 비싼 쿼리를 기록하고 찾는 방법 (0) | 2023.07.16 |