oracle update from 问题!
update t_tmprpt_firstreplycosttime t
set (t.firstreplytime,
t.dealstaff,
t.firstreplyfailcontent)
= (select a.suggesttime,
a.suggester,
substr(a.remark,instr(a.remark,'】',1)+2)
from t_wf_suggesthis a
where t.serialno = a.serialno
and t.serviceclassid = a.serviceclassid);
想把t_tmprpt_firstreplycosttime 表中的3个字段数据更新为t_wf_suggesthis表中的suggesttime, suggester,substr(a.remark,instr(a.remark,'】',1)+2)的值。条件是t表的sreialno和serviceclassid都与a表中的相等。
问题:当我执行这条更新时候会把t表中的所有数据都更新了。
解决:oracle中没update from 这样的更新,可以考虑2种解决办法。
一,
update (select a.suggesttime atime,
b.firstreplytime btime,
a.suggester astaff,
b.dealstaff bstaff,
substr(a.remark,instr(a.remark,'】',1)+2) acontent,
b.firstreplyfailcontent bcontent
from t_wf_suggesthis a, t_tmprpt_firstreplycosttime b)
set btime = atime,
btaff = astaff,
bcontent = acontent;
这是类视图的更新方法,这也是oracle所独有的。
先把对应的数据全部抽取出来,然后更新表一样更新数据,这里需要注意的是,必须保证表的数据唯一性。
这就要求a,b两表的关联字段上都是具备唯一性的。
二,
update t_tmprpt_firstreplycosttime t
set (t.firstreplytime,
t.dealstaff,
t.firstreplyfailcontent)
= (select a.suggesttime,
a.suggester,
substr(a.remark,instr(a.remark,'】',1)+2)
from t_wf_suggesthis a
where t.serialno = a.serialno
and t.serviceclassid = a.serviceclassid)
where t.serialno in (select b.serialno
from t_wf_suggesthis b
where b.serialno = t.serialno
and b.serviceclassid = t.serviceclassid);
这种就是使用子查询来确定更新的数据。
相关文档:
---------数学函数
1.绝对值
S:select abs(-1) value
O:select abs(-1) value from dual
2.取整(大)
S:select ceiling(-1.001) value
O:select ceil(-1.001) value from dual
3.取整(小)
S:select floor(-1.001) value
O:select floor(-1.001) value from dual
4.取整(截取)
S:select cast ......
上節學習開第一個Form,這個節在添加一個彈出下拉框
第一步:添加記錄組
1.1 選中Record Groups
1.2 單擊Create
1.3 輸入查詢SQL
1.4 單擊OK
1.5 修改 ......
CSDN里的一个朋友问到了这个索引覆盖的概念。 这个概念很小的知识点,在我的论坛里有解释“”,不过作为Oracle版主,不能在回帖里加上网外的地址链接,所以这里在CSDN里帖上一份
比如有复合索引为3个字段:f1 + f2 + f3,请问:
1: select f1, f2, f3, f4 from table where f1 = 'XX' and f2 = 'XX'. ......
1、创建表t1 :create table t1 (id number,name nvarchar(8));
2、创建序列 :CREATE SEQUENCE t1_id INCREMENT BY 1 START WITH 1 MAXVALUE
1.0E28 MINVALUE 1 NOCYCLE CACHE 20 NOORDER
3. 创建触发器 :
CREATE TRIGGER tig_insert_t1
BEFORE INSERT ON "YINZQ"."T1"
begin
if (:new.id is null) then
......