숫자 목록을 plsql 변수로 쿼리하고 다른 SQL 쿼리의 in 절에서 사용하려고합니다. 내가하고 싶은 것을 아래에 테스트 케이스를 만들었다.'IN'절에서 바인드 변수 사용
나는 해결책을 찾기 위해 google을했는데 어떻게 든 가능해야한다고 생각하지만 그냥 실행하지 않아도된다. 컴파일 솔루션으로 도와주세요.
CREATE OR REPLACE PROCEDURE PROCEDURE1
as
type t_id is table of number;
v_ids t_id;
v_user_ids number;
BEGIN
-- fill variable v_id with id's, user_id is of type number
select user_id
bulk collect into v_ids
from user_users;
-- then at a later stage ... issue a query using v_id in the in clause
select user_id into v_user_ids from user_users
-- this line does not compile (local collection type not allowed in SQL statements)
where user_id in (v_ids);
END PROCEDURE1;
아마도이 간단한 데모이지만 두 개의 쿼리를 하나로 결합하지 않겠습니까? "Select ... from ... 어디에서 user_id (select user_id from ...)"? 또는 참여를 수행 하시겠습니까? –
예, 이것은 어리 석다. 컴파일 할 때 예제가 필요합니다 - 줄에 오류가 발생합니다. 여기서 user_id (v_ids) – opi
은 SQL 배열을 사용하고 있습니다. plsql 중첩 테이블은 옵션이 아닙니다. 그렇다면 TABLE() 함수를 사용하여 문제를 해결할 수 있습니다. 마지막 문장은 select into로 선택되지 않으므로 한 행으로 끝납니다. 실제 SQL이 select max이면 괜찮습니다.() 또는 rownum = 1 또는 무엇인가). – DazzaL