我有这样的表格,有触发器和序列:
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();
我尝试在网上查找,但无法找到我的错误解决方案,大多数错误都与oracle本身有关
更新:根据@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
答案 0 :(得分:1)
像这样运行以解决触发器的问题。根据异常触发器无效。
SQL> alter trigger tbl_user_trigger compile;
Warning: Trigger altered with compilation errors.
SQL> show errors
Errors for TRIGGER TBL_USER_TRIGGER:
<It will display errors here>
此外,您可以运行此查询以确认您是否有序列。从语法上讲,你的触发器代码是正确的。
select * from all_sequences where sequence_name = 'TBL_USER_SEQ';
回答ORA-06502: PL/SQL: numeric or value error: character string buffer too small
您有"USR_ID" VARCHAR2(1 BYTE) NOT NULL ENABLE,
,这意味着USR_ID只能存储一个字符。一旦usr_id越过9,它就会抛出错误。您需要更改USR_ID的数据类型。