我希望建立一个触发器,计算出其中(某列的字符串长度/60)的结果插入另一行。我的写法如下:CREATE OR REPLACE TRIGGER ECCDBA.MESSAGESEND_COUNT
before insert ON T1 --表名
for each row
declare
M_count integer; --结果变量
M_content varchar(500); --字符串长度变量
begin
M_content:=:new.MESSAGECONTEXT; --先得到插入的字符串
select length(M_content) into M_count from dual; --计算出长度
update T_BASE_MESSAGESENDLIST set MESSAGECOUNT=(ceil(M_count/60)) where ID=:new.id; --然后把(长度/60的
结果更新到表中)
end btnlist_FOR_AUTOINC;结果我发现这样更新没有结果!!!!
before insert ON T1 --表名
for each row
declare
M_count integer; --结果变量
M_content varchar(500); --字符串长度变量
begin
M_content:=:new.MESSAGECONTEXT; --先得到插入的字符串
select length(M_content) into M_count from dual; --计算出长度
update T_BASE_MESSAGESENDLIST set MESSAGECOUNT=(ceil(M_count/60)) where ID=:new.id; --然后把(长度/60的
结果更新到表中)
end btnlist_FOR_AUTOINC;结果我发现这样更新没有结果!!!!
解决方案 »
- 关于oracle的几个服务,具体代表什么意思?
- oracle SGA,PGA 内存分配,急.....
- oracle 已经提示数据成功导入,但是找不到表
- 关于oracle 时间比较的表达式
- 求:WINXP下9.2服务端和同一局域网内CentOS5.1下Oracle 10.2.0.1互相通信,以用户为单位备份数据方案!请教高手LINUX下10g数据库备份数据方案
- 函数的返回值不正确的问题,------------100分!
- 有空的进来帮帮我!!!!!!!!!!
- number extents 扩展不了了,紧急
- 刚装了oracle,请问如何使用他自带的帮助文档呀?
- 触发器语法正切 为什么执行不能通过?
- oracle书籍
- 急!求教高手关于linux下 oracle10g rac双实例无法同时启用的问题!!!
确认表T_BASE_MESSAGESENDLIST里有对应数据?
表T_BASE_MESSAGESENDLIST中,一定要有ID等於新插入的id值才能更新
T1=T_BASE_MESSAGESENDLIST;
where ID=:new.id; 条件是否满足 T_BASE_MESSAGESENDLIST 中的ID中是否有T1中新插入的id
before insert ON T_BASE_MESSAGESENDLIST --表名
for each row
declare
begin
:new.MESSAGECOUNT:=ceil(length(:new.MESSAGECONTEXT)/60);
end btnlist_FOR_AUTOINC;
before insert ON T_BASE_MESSAGESENDLIST
for each row
begin
:new.MESSAGECOUNT:=(ceil(length(:new.MESSAGECONTEXT)/60)) ;
end btnlist_FOR_AUTOINC;
--这样CREATE OR REPLACE TRIGGER ECCDBA.MESSAGESEND_COUNT
before insert ON T1
for each row
declare
M_count integer;
M_content varchar(500);
begin
M_content:=:new.MESSAGECONTEXT;
select length(M_content) into M_count from dual;
:new.MESSAGECOUNT:=(ceil(M_count/60)) ;
end btnlist_FOR_AUTOINC;
CREATE OR REPLACE TRIGGER ECCDBA.MESSAGESEND_COUNT
before insert ON T_BASE_MESSAGESENDLIST
for each row
declare
M_count integer;
M_content varchar(500);
begin
M_content:=:new.MESSAGECONTEXT;
select length(M_content) into M_count from dual;
:new.MESSAGECOUNT:=(ceil(M_count/60)) ;
end btnlist_FOR_AUTOINC;
如果没有的话,肯定没有更新结果,其它的我不认为有错
我的MESSAGECONTEXT字段不应该是0 啊
SQL> create table T_BASE_MESSAGESENDLIST
2 (id number(5),
3 MESSAGECONTEXT varchar2(4000),
4 MESSAGECOUNT number(4))
5 ;
Table createdSQL> CREATE OR REPLACE TRIGGER MESSAGESEND_COUNT
2 before insert ON T_BASE_MESSAGESENDLIST --表名
3 for each row
4 declare
5 begin
6 :new.MESSAGECOUNT:=ceil(length(:new.MESSAGECONTEXT)/60);
7 end btnlist_FOR_AUTOINC;
8 /
Trigger created
SQL> insert into T_BASE_MESSAGESENDLIST(id,MESSAGECONTEXT)values(1,'1234');
1 row inserted
SQL> commit;
Commit complete
SQL> select * from T_BASE_MESSAGESENDLIST;
ID MESSAGECONTEXT MESSAGECOUNT
------ -------------------------------------------------------------------------------- ------------
1 1234 1
SQL>
MESSAGECONTEXT里面明明有值啊?
before insert ON T_BASE_MESSAGESENDLIST --表名
for each row
declare
begin
:new.MESSAGECOUNT:=ceil(DBMS_LOB.getlength(:new.MESSAGECONTEXT)/60);
end btnlist_FOR_AUTOINC;
Name Type Nullable Default Comments
-------------- --------- -------- ------- --------
ID NUMBER(5) Y
MESSAGECONTEXT CLOB Y
MESSAGECOUNT NUMBER(4) Y
SQL> insert into T_BASE_MESSAGESENDLIST values(1,'12345',111);
1 row inserted
SQL> select * from T_BASE_MESSAGESENDLIST;
ID MESSAGECONTEXT MESSAGECOUNT
------ -------------------------------------------------------------------------------- ------------
1 12345 1
SQL>
我找到原因了,我直接在toda里面通过手动输入就会认为MESSAGECONTEXT为0。通过语句就会正常识别!哎,真是奇怪啊