我正在尝试创建一个before insert&更新Oracle中表的触发器。 在尝试阅读NEW.CLOB_COLUMN_VALUE时,它给我留空。
表:
CREATE TABLE TEMP_TEST101
(
ID NUMBER(2),
TEST_CLOB_VALUE CLOB
)
触发:
CREATE OR REPLACE TRIGGER TR_Temp_Test101
BEFORE INSERT OR UPDATE
ON Temp_Test101 FOR EACH ROW
DECLARE
BEGIN
If (:NEW.TEST_CLOB_VALUE = 'A')
Then
raise_application_error(-20010,'Testing Successfull');
End IF;
raise_application_error(-20010,'Testing Failed:['||:NEW.TEST_CLOB_VALUE||']');
END TR_Temp_Test101;
/
尝试插入后提示:
ORA-20010: Testing Failed:[]
我们有什么办法可以在插入/更新之前阅读:NEW.TEST_CLOB_VALUE
吗?
要求是在插入/更新之前验证CLOB列的数据。
答案 0 :(得分:0)
由于其clob
列,您需要将条件检查为
dbms_lob.substr(:NEW.TEST_CLOB_VALUE,1,1) = 'A'
参见演示:
CREATE OR REPLACE TRIGGER TR_Temp_Test101
BEFORE INSERT OR UPDATE
ON Temp_Test101
FOR EACH ROW
DECLARE
BEGIN
IF (dbms_lob.substr(:NEW.TEST_CLOB_VALUE,1,1) = 'A')
THEN
raise_application_error (-20010, 'Testing Successfull');
END IF;
raise_application_error (
-20010,
'Testing Failed:[' || :NEW.TEST_CLOB_VALUE || ']');
END TR_Temp_Test101;
执行:
SQL> Insert into TEMP_TEST101 values(1,'A');
Insert into TEMP_TEST101 values(1,'A')
*
ERROR at line 1:
ORA-20010: Testing Successfull
ORA-06512: at "TR_TEMP_TEST101", line 5
ORA-04088: error during execution of trigger 'TR_TEMP_TEST101'