当前位置:Gxlcms > 数据库问题 > 连续创建多个Oracle触发器失败,单个创建才成功的解决方法

连续创建多个Oracle触发器失败,单个创建才成功的解决方法

时间:2021-07-01 10:21:17 帮助过:23人阅读

.应用信息 drop table app_info cascade constraints; create table APP_INFO ( id NUMBER(9) not null, appid VARCHAR2(255) default NULL, appkey VARCHAR2(255) default NULL, md5_key VARCHAR2(255) default NULL, aes_key VARCHAR2(255) default NULL, permission VARCHAR2(3000) default NULL, email VARCHAR2(255) default NULL, password VARCHAR2(255) default NULL, ras_public_key VARCHAR2(255) default NULL, constraint APP_INFO primary key (id) ); drop sequence app_info_id; create sequence app_info_id increment by 1 start with 1 nomaxvalue nominvalue nocache; CREATE OR REPLACE TRIGGER addAppInfo BEFORE INSERT ON App_INFO FOR EACH ROW BEGIN SELECT app_info_id.nextval INTO :new.id FROM dual; END; ---2.unit信息 drop table unit_info cascade constraints; create table UNIT_INFO ( UNIT_ID NUMBER(9) not null, USERID VARCHAR2(255) default NULL, UNIT_NAME VARCHAR2(128) default NULL, UNIT_LINKMAN VARCHAR2(64) default NULL, ORGANIZATION_CODE VARCHAR2(64) default NULL, constraint UNIT_INFO primary key (UNIT_ID) ); drop sequence unit_info_id; create sequence unit_info_id increment by 1 start with 1 nomaxvalue nominvalue nocache; CREATE OR REPLACE TRIGGER addUnitInfo BEFORE INSERT ON UNIT_INFO FOR EACH ROW BEGIN SELECT unit_info_id.nextval INTO :new.unit_id FROM dual; END;

错误截图如下:

技术分享图片

这种创建是失败的,因为触发器需要先编译,每创建一个触发器,需要以“/”结束,然后才能执行下一个。

正确的做法应该是这样的;

---1.应用信息
drop table app_info cascade constraints;
create table APP_INFO
(
  id      NUMBER(9)   not null,
  appid    VARCHAR2(255)        default NULL,
  appkey    VARCHAR2(255)       default NULL,
  md5_key          VARCHAR2(255)    default NULL,
  aes_key    VARCHAR2(255)      default NULL,
  permission    VARCHAR2(3000)     default NULL,
  email    VARCHAR2(255)       default NULL,
  password    VARCHAR2(255)      default NULL,
  ras_public_key     VARCHAR2(255)  default NULL,
  constraint APP_INFO primary key (id)
);

drop sequence app_info_id;
create sequence app_info_id
increment by 1
start with 1
nomaxvalue
nominvalue
nocache;

CREATE OR REPLACE TRIGGER addAppInfo BEFORE INSERT ON App_INFO FOR EACH ROW  
 BEGIN  
    SELECT app_info_id.nextval INTO :new.id  FROM dual;  
 END; 
/
---2.unit信息
drop table unit_info cascade constraints;
create table UNIT_INFO
(
  UNIT_ID        NUMBER(9)  not null,
  USERID          VARCHAR2(255)        default NULL,
  UNIT_NAME      VARCHAR2(128)        default NULL,
  UNIT_LINKMAN      VARCHAR2(64)    default NULL,
  ORGANIZATION_CODE        VARCHAR2(64)     default NULL,
  constraint UNIT_INFO primary key (UNIT_ID)
);

drop sequence unit_info_id;
create sequence unit_info_id
increment by 1
start with 1
nomaxvalue
nominvalue
nocache;

CREATE OR REPLACE TRIGGER addUnitInfo BEFORE INSERT ON UNIT_INFO FOR EACH ROW  
 BEGIN  
    SELECT unit_info_id.nextval INTO :new.unit_id  FROM dual;  
 END; 
/

 注意:存储过程也是一样的。

连续创建多个Oracle触发器失败,单个创建才成功的解决方法

标签:pid   word   成功   strong   nocache   har   触发器   default   const   

人气教程排行