반응형
쿼리에서 START WITH로 시퀀스 만들기
START WITH 값이 쿼리에서 나오는 시퀀스를 만들려면 어떻게 해야 합니까?
이런 식으로 노력하고 있습니다. CREATE SEQUENCE "Seq" INCREMENT BY 1 START WITH (SELECT MAX("ID") FROM "Table");
하지만 ORA-01722 오류가 발생합니다.
START WITH CLAUSE는 정수를 받아들입니다."Create sequence" 문을 동적으로 작성한 다음 execute immediate를 사용하여 이를 달성할 수 있습니다.
declare
l_new_seq INTEGER;
begin
select max(id) + 1
into l_new_seq
from test_table;
execute immediate 'Create sequence test_seq_2
start with ' || l_new_seq ||
' increment by 1';
end;
/
이 링크들을 확인해보세요.
http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_6014.htm
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/executeimmediate_statement.htm
잘 작동하는 예제가 있습니다.
declare
ex number;
begin
select MAX(MAX_FK_ID) + 1 into ex from TABLE;
If ex > 0 then
begin
execute immediate 'DROP SEQUENCE SQ_NAME';
exception when others then
null;
end;
execute immediate 'CREATE SEQUENCE SQ_NAME INCREMENT BY 1 START WITH ' || ex || ' NOCYCLE CACHE 20 NOORDER';
end if;
end;
언급URL : https://stackoverflow.com/questions/3461267/create-a-sequence-with-start-with-from-query
반응형
'sourcecode' 카테고리의 다른 글
우커머스 체크아웃 ax 콜백 (0) | 2023.11.04 |
---|---|
차이에서 "주장", "기대", "해야 한다"의 차이는 무엇입니까? (0) | 2023.11.04 |
Powershell 스크립트에서 반환 값을 잡는 방법 (0) | 2023.11.04 |
쿼리를 하나의 레코드로 제한하면 성능이 향상됩니까? (0) | 2023.11.04 |
jQuery.live()와 .on()의 차이점은 무엇입니까? (0) | 2023.11.04 |