我有一个可以编译的触发器,但会引发 ORA12704 字符不匹配错误。这是引发错误的行
Begin
if :new.ADD_TEXT = '{8A9AFF65-9BD8-4B2A-8686-5279CC34F24B}' and
:new.MORE_TEXT is null then
:new.MORE_TEXT := substr(:new.RES_TXT, instr(:new.RES_TXT, '.',-1)+1, 10);
我有一个可以编译的触发器,但会引发 ORA12704 字符不匹配错误。这是引发错误的行
Begin
if :new.ADD_TEXT = '{8A9AFF65-9BD8-4B2A-8686-5279CC34F24B}' and
:new.MORE_TEXT is null then
:new.MORE_TEXT := substr(:new.RES_TXT, instr(:new.RES_TXT, '.',-1)+1, 10);
尝试更改线路
:new.MORE_TEXT := substr(:new.RES_TXT, instr(:new.RES_TXT, '.',-1)+1, 10);
至
:new.MORE_TEXT := substr(:new.RES_TXT, instr(:new.RES_TXT, n'.',-1)+1, 10);
即 instr 函数调用中的第一个和第二个参数在数据类型中匹配。即使拥有该参数,我也无法在 10.2.0.4 上复制该问题'.'
。
.例如,如果您使用插入值在您的机器上运行这个煮沸的测试用例,它会失败吗?
drop table tester;
create table tester
(
ADD_TEXT VARCHAR2 (38),
MORE_Text NVARCHAR2(500),
RES_TXT NVARCHAR2(500)
);
create trigger tester_trig
before insert on tester
for each row
declare
begin
if :new.ADD_TEXT = '{8A9AFF65-9BD8-4B2A-8686-5279CC34F24B}' and
:new.MORE_TEXT is null then
:new.MORE_TEXT := substr(:new.RES_TXT, instr(:new.RES_TXT, '.',-1)+1, 10);
end if;
end;
/
insert into tester values ('{8A9AFF65-9BD8-4B2A-8686-5279CC34F24B}', '', 'your.value' );
select * from tester;
编辑:
根据您的新触发器:
SQL> CREATE OR REPLACE TRIGGER test_trigger_001
2 Before Insert or update ON tester
3 for each row
4 declare
5 v1_ext varchar2(10);
6 Begin
7 if :new.ADD_TEXT = '{8A9AFF65-9BD8-4B2A-8686-5279CC34F24B}'
8 and :new.MORE_TEXT is null
9 then
10 :new.MORE_TEXT := substr(:new.RES_TXT, instr(:new.RES_TXT, '.',-1)+1, 10);
11 select Case :new.MORE_TEXT
12 WHEN 'avi' THEN 'video/x-msvideo'
13 WHEN 'doc' THEN 'application/msword'
14 else 'application/unknown'
15 end
16 into :new.MORE_TEXT
17 from dual;
18 end if;
19 v1_ext := null;
20 END;
21 /
Warning: Trigger created with compilation errors.
SQL> show errors
Errors for TRIGGER TEST_TRIGGER_001:
LINE/COL ERROR
-------- -----------------------------------------------------------------
8/5 PL/SQL: SQL Statement ignored
9/12 PL/SQL: ORA-12704: character set mismatch
修复n
SQL> CREATE OR REPLACE TRIGGER test_trigger_001
2 Before Insert or update ON tester
3 for each row
4 declare
5 v1_ext varchar2(10);
6 Begin
7 if :new.ADD_TEXT = '{8A9AFF65-9BD8-4B2A-8686-5279CC34F24B}'
8 and :new.MORE_TEXT is null
9 then
10 :new.MORE_TEXT := substr(:new.RES_TXT, instr(:new.RES_TXT, n'.',-1)+1, 10);
11 select Case :new.MORE_TEXT
12 WHEN n'avi' THEN n'video/x-msvideo'
13 WHEN n'doc' THEN n'application/msword'
14 else n'application/unknown'
15 end
16 into :new.MORE_TEXT
17 from dual;
18 end if;
19 v1_ext := null;
20 END;
21 /
Trigger created.
SQL> show errors
No errors.
SQL> insert into tester values ('{8A9AFF65-9BD8-4B2A-8686-5279CC34F24B}', '', 'foo.avi');
1 row created.
SQL> select * from tester;
ADD_TEXT
--------------------------------------
MORE_TEXT
--------------------------------------------------------------------------------
RES_TXT
--------------------------------------------------------------------------------
{8A9AFF65-9BD8-4B2A-8686-5279CC34F24B}
video/x-msvideo
foo.avi