CREATE OR REPLACE TRIGGER pendaftaran_tri
BEFORE INSERT ON MAHASISWA
FOR EACH ROW
WHEN (new.id_pendaftar is null)
DECLARE v_daftar mahasiswa.id_pendaftar%NUMBER(8,0);
BEGIN
SELECT MAHASISWA_SEQ.nextval INTO v_daftar
FROM DUAL; :new.id_pendaftar := v_daftar;
END pendaftaran_tri;
表格定义:
CREATE TABLE "MAHASISWA" (
"id_pendaftar" NUMBER(6,0),
"nama_mhs" VARCHAR2(50) NOT NULL ENABLE,
"nim" NUMBER(11,0) NOT NULL ENABLE,
"id_pembayaran" VARCHAR2(8),
"jenis_kel" VARCHAR2(1) NOT NULL ENABLE,
"goldar" VARCHAR2(2) NOT NULL ENABLE,
"tem_lahir" VARCHAR2(18) NOT NULL ENABLE,
"ttl" DATE,
"alamat_mhs" VARCHAR2(100) NOT NULL ENABLE,
"no_telp" VARCHAR2(12) NOT NULL ENABLE,
"email_mhs" VARCHAR2(35) NOT NULL ENABLE,
"kd_jurusan" VARCHAR2(4),
"no_rek" VARCHAR2(16),
"pin" VARCHAR2(6),
CONSTRAINT "PK_MAHASISWA" PRIMARY KEY ("nim") ENABLE,
CONSTRAINT "MAHASISWA_FK" FOREIGN KEY ("ID_KAMPUS")
REFERENCES "KAMPUS" ("id_kampus") ENABLE
)
CREATE OR REPLACE TRIGGER "UPDATE_MAHASISWA_HISTORY"
AFTER UPDATE ON MAHASISWA
FOR EACH ROW
BEGIN
add_mahasiswa_history(:old.id_pendaftar, :old.ID_KAMPUS, sysdate,
:old.nim, :old.nama_mhs, :old.id_pembayaran, :old.jenis_kel, :old.goldar, :old.tem_lahir, :old.ttl, :old.alamat_mhs, :old.no_telp, :old.email_mhs, :old.kd_jurusan, :old.no_rek, :old.pin );
END;
CREATE SEQUENCE "MAHASISWA_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE
ALTER TRIGGER "UPDATE_MAHASISWA_HISTORY" ENABLE;
/
ALTER TRIGGER "UPDATE_MAHASISWA_HISTORY" ENABLE
/
答案 0 :(得分:2)
您的CREATE TABLE语句包含双引号中的列名:
CREATE TABLE "MAHASISWA" (
"id_pendaftar" NUMBER(6,0),
这使它们区分大小写,因此您必须在触发器中使用双引号:
CREATE OR REPLACE TRIGGER pendaftaran_tri
BEFORE INSERT ON MAHASISWA
FOR EACH ROW
WHEN (new.id_pendaftar is null)
DECLARE v_daftar mahasiswa.id_pendaftar%NUMBER(8,0);
BEGIN
SELECT MAHASISWA_SEQ.nextval INTO v_daftar
FROM DUAL;
:new."id_pendaftar" := v_daftar;
END pendaftaran_tri;
但是,我强烈反对使用区分大小写的列名称。如果可能,请使用不区分大小写的名称重新创建表,或者更改现有表。