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);
这种就是使用子查询来确定更新的数据。
相关文档:
package com.chinacache.boss.queryservice.service.impl;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.chinacache.boss.queryservice.excepti ......
nvl( ) 函数
示例 请参阅
从两个表达式返回一个非 null 值。
语法
NVL(eExpression1, eExpression2)
参数
eExpression1, eExpression2
如果 eExpression1 的计算结果为 null 值,则 NVL( ) 返回 eExpression2。如果 eExpression1 的计算结果不是 null 值,则返回 eExpression1。eExpression1 和 eExpression2 可以 ......
一.B-Tree索引(b-tree index)
1. 选项择索引字段的原则:
在WHERE子句中最频繁使用的字段
联接语句中的联接字段
选择高选择性的字段(如果很少的字段拥有相同值,即有很多独特值,则选择性很好)
ORACLE在UNIQUE和主键字段上自动建立索引
在选择性很差的字段上建索引只有在这个字段的 ......
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
......
Oracle维日常护点滴
虽然Oracle维护不是我的职责,但平时还是难免要跟它打交道,因此对于Oracle的日常维护略知一二还是很有好处的。
1. 登录:
(1)采用系统管理员用户登录:
#su - oracle
$ sqlplus / as sysdba
(2)采用一般用户登录,假设用户名为oracle,密码为passwor ......