ORA - 02287: 여기 서 번호 (sequence number not allowed here) 의 회피 및 강제 실현 을 허용 하지 않 습 니 다.

문제 필드 1:
SELECT id,name FROM (select SEQ_B_LOG_ID.NEXTVAL id , 'elong_deo' name from dual);

문제 장면 2:
insert into b_authority
  (id,role_id,authority,remark,url,yn,parent_id,authority_type,log_flag)
select SEQ_B_AUTHORITY_ID.NEXTVAL,1, 'admin:role:listRole', '      ', '/admin/role/listRole.htm', 1,210,4, 1 from dual
union
select SEQ_B_AUTHORITY_ID.NEXTVAL,1, 'admin:role:toEditAuthority', '        ', '/admin/role/toEditAuthority.htm', 1,210,4, 1 from dual
union
select SEQ_B_AUTHORITY_ID.NEXTVAL,1, 'admin:role:findAuthsByRoleId', '      ', '/admin/role/findAuthsByRoleId.htm', 1,210,4, 1 from dual
union
select SEQ_B_AUTHORITY_ID.NEXTVAL,1, 'admin:role:updateRoleAuths', '      ', '/admin/role/updateRoleAuths.htm', 1,210,4, 1 from dual;

이 알림 이 나타 난 이 유 는 Oacle 이 이렇게 사용 하지 못 하 게 하기 때 문 입 니 다. 구체 적 으로 설명 하면 다음 과 같 습 니 다.
Restrictions on Sequence Values You cannot use CURRVAL and NEXTVAL in the
following constructs:
■ A subquery in a DELETE, SELECT, or UPDATE statement
■ A query of a view or of a materialized view
■ A SELECT statement with the DISTINCT operator
■ A SELECT statement with a GROUP BY clause or ORDER BY clause   
■ A SELECT statement that is combined with another SELECT statement with the
UNION, INTERSECT, or MINUS set operator
■ The WHERE clause of a SELECT statement
■ The DEFAULT value of a column in a CREATE TABLE or ALTER TABLE statement
■ The condition of a CHECK constrain
문제 해결 의 회피:
피 하 는 것 은 Oacle 시퀀스 에 들 어가 지 않 는 금지 구역 을 말 합 니 다. 즉, 상기 몇 가지 상황 에 부합 되 지 않도록 SQL 문 구 를 합 리 적 으로 변경 하여 우리 의 목적 을 달성 하 는 것 입 니 다.
필드 1 해결:
SELECT SEQ_B_LOG_ID.NEXTVAL id ,name FROM (select  'elong_deo' name from dual);

장면 2 해결:
insert into b_authority
  (id,role_id,authority,remark,url,yn,parent_id,authority_type,log_flag)
select SEQ_B_AUTHORITY_ID.NEXTVAL,t.c1,t.c2,t.c3,t.c4,t.c5,t.c6,t.c7 from (select 1 c1, 'admin:role:listRole' c2, '      ' c3, '/admin/role/listRole.htm' c4, 1 c5,210 c6,4 c7, 1 c8 from dual
union all
select 1, 'admin:role:toEditAuthority', '        ', '/admin/role/toEditAuthority.htm', 1,210,4, 1 from dual
union all
select 1, 'admin:role:findAuthsByRoleId', '      ', '/admin/role/findAuthsByRoleId.htm', 1,210,4, 1 from dual
union all
select 1, 'admin:role:updateRoleAuths', '      ', '/admin/role/updateRoleAuths.htm', 1,210,4, 1 from dual) t;

문제 해결 의 다른 강제 집행:
많은 Oacle 문 구 는 사용 할 때 제한 이 있 지만 Function 은 대부분 상황 에서 제한 이 없습니다. 우 리 는 프로그램 을 통 해 nextval 과 currval 을 얻 을 수 있 습 니 다.
--         
create or replace function get_seq_next (seq_name in varchar2) return number
is
  seq_val number ;
begin
  execute immediate 'select '|| seq_name|| '.nextval from dual' into seq_val ;
  return seq_val ;
end get_seq_next;
--        (    nextval)
create or replace function get_seq_curr (seq_name in varchar2) return number
is
  seq_val number ;
begin
  execute immediate 'select '|| seq_name|| '.currval from dual' into seq_val ;
  return seq_val ;
end get_seq_curr;

필드 1 해결:
SELECT id,name FROM (select get_seq_next('SEQ_B_LOG_ID') id , 'elong_deo' name from dual);

장면 2 해결:
insert into b_authority
  (id,role_id,authority,remark,url,yn,parent_id,authority_type,log_flag)
select get_seq_next('SEQ_B_AUTHORITY_ID'),1, 'admin:role:listRole', '      ', '/admin/role/listRole.htm', 1,210,4, 1 from dual
union
select get_seq_next('SEQ_B_AUTHORITY_ID'),1, 'admin:role:toEditAuthority', '        ', '/admin/role/toEditAuthority.htm', 1,210,4, 1 from dual
union
select get_seq_next('SEQ_B_AUTHORITY_ID'),1, 'admin:role:findAuthsByRoleId', '      ', '/admin/role/findAuthsByRoleId.htm', 1,210,4, 1 from dual
union
select get_seq_next('SEQ_B_AUTHORITY_ID'),1, 'admin:role:updateRoleAuths', '      ', '/admin/role/updateRoleAuths.htm', 1,210,4, 1 from dual;

좋은 웹페이지 즐겨찾기