我的表像這樣用觸發器和序列:觸發無效,未能重新驗證錯誤而插入記錄
CREATE TABLE "RTH"."TBL_USER"
( "USR_ID" VARCHAR2(1 BYTE) NOT NULL ENABLE,
"USR_IS_ANONYMOUS" RAW(1),
"USR_FIRST_NAME" CLOB,
"USR_MID_NAME" CLOB,
"USR_LST_NAME" CLOB,
"USR_PRIMARY_EMAIL" CLOB,
"USR_ALT_EMAIL" CLOB,
"USR_PRIMARY_CNCT_NMBR" CLOB,
"USR_SECONDARY_CNCT_NMBR" CLOB,
"USR_TYPE" CLOB,
"USR_CATEGORY" CLOB,
"USR_DOB" TIMESTAMP (0),
"USR_CREATE_DT" TIMESTAMP (0),
"CUPN_ID" VARCHAR2(1 BYTE),
"USR_MARITIAL_STUTUS" VARCHAR2(20 BYTE),
"USR_GENDER" VARCHAR2(1 BYTE),
"USR_IMAGE" RAW(1),
"USR_PASSWORD" VARCHAR2(20 BYTE),
CONSTRAINT "XPKTBL_USER" PRIMARY KEY ("USR_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOCOMPRESS LOGGING
TABLESPACE "USERS" ENABLE
) SEGMENT CREATION DEFERRED
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
TABLESPACE "USERS"
LOB ("USR_FIRST_NAME") STORE AS BASICFILE (
TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
NOCACHE LOGGING)
LOB ("USR_MID_NAME") STORE AS BASICFILE (
TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
NOCACHE LOGGING)
LOB ("USR_LST_NAME") STORE AS BASICFILE (
TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
NOCACHE LOGGING)
LOB ("USR_PRIMARY_EMAIL") STORE AS BASICFILE (
TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
NOCACHE LOGGING)
LOB ("USR_ALT_EMAIL") STORE AS BASICFILE (
TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
NOCACHE LOGGING)
LOB ("USR_PRIMARY_CNCT_NMBR") STORE AS BASICFILE (
TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
NOCACHE LOGGING)
LOB ("USR_SECONDARY_CNCT_NMBR") STORE AS BASICFILE (
TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
NOCACHE LOGGING)
LOB ("USR_TYPE") STORE AS BASICFILE (
TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
NOCACHE LOGGING)
LOB ("USR_CATEGORY") STORE AS BASICFILE (
TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
NOCACHE LOGGING) ;
CREATE OR REPLACE TRIGGER "RTH"."TBL_USER_TRIGGER"
BEFORE INSERT ON TBL_USER
FOR EACH ROW
BEGIN
SELECT TBL_USER_SEQ.nextval
INTO :new.USR_ID
FROM dual;
END;
ALTER TRIGGER "RTH"."TBL_USER_TRIGGER" ENABLE
/
ALTER TRIGGER "RTH"."TBL_USER_TRIGGER" ENABLE;
當我嘗試插入一條記錄,我得到一個錯誤說:
java.sql.SQLSyntaxErrorException: ORA-04098: trigger 'RTH.TBL_USER_TRIGGER' is invalid and failed re-validation
插入記錄Java代碼:
String query = "insert into TBL_USER(USR_FIRST_NAME,USR_LST_NAME,USR_PRIMARY_EMAIL,USR_PASSWORD) values(?,?,?,?)";
PreparedStatement pst = con.prepareStatement(query);
pst.setString(1, user.getFirstName());
pst.setString(2, user.getLastName());
pst.setString(3, user.getEmail());
pst.setString(4, user.getPassword());
pst.executeUpdate();
我試過網上找,但找不到我的錯誤,莫解決方案錯誤的ST都與甲骨文自己
更新:作爲建議的@Durga Viswanath,運行查詢:
select * from all_sequences where sequence_name = 'TBL_USER_SEQ';
得出以下結果:
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY CYCLE_FLAG ORDER_FLAG CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------------------- ---------------------- ---------------------- ---------- ---------- ---------------------- ----------------------
RTH TBL_USER_SEQ 1 9999999999999999999999999999 1 N N 100 101
1 rows selected
現在,我得到插入記錄時出現新錯誤:
One error saving changes to table "RTH"."TBL_USER":
Row 10: ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at "RTH.TBL_USER_TRIGGER", line 2
ORA-04088: error during execution of trigger 'RTH.TBL_USER_TRIGGER'
ORA-06512: at line 1
你還可以發佈'TBL_USER_SEQ'的表定義嗎?在觸發器定義後嘗試使用'SHOW ERRORS'。 –
@TimBiegeleisen更新了問題 – Satyadev
您需要經歷錯誤並理解錯誤的含義,錯誤清楚地表明「字符串緩衝區太小」。我已經編輯了這個問題的答案。 –