动机:想在Oracle中用一条SQL语句直接进行Insert/Update的操作。说明:在进行SQL语句编写时,我们经常会遇到大量的同时进行Insert/Update的语句 ,也就是说当存在记录时,就更新(Update),不存在数据时,就插入(Insert)。实战:接下来我们有一个任务,有一个表T,有两个字段a,b,我们想在表T中做Insert/Update,如果存在,则更新T中b的值,如果不存在,则插入一条记录。在Microsoft的SQL语法中,很简单的一句判断就可以了,SQL Serv...
昨天发现程序中数据分析的结果不对,重新进行分析后,原数据仍在,有值的字段被累计。心说,不对啊,是重新生成记录后才分析的啊。难道忘了DELETE了?查代码,发现有删除语句。于是在查询分析器中执行,报错。反复试几次,明白了,Delete From不认表名别名!回头想下,当初程序改完后主要是在Oracle中测的,SQLServer一直没细测。之所以要用别名,是因为where条件中需要用到子查询写一些条件,下面不写那么复杂,仅说明一下问题。结...
我遇到的情况:当使用select语句查询表时,后面跟着for update ,select * from table for update当修改表中数据,但是没有commit就关掉PL/SQL,下次再打开,执行带for update的sql语句,就会卡死 一、锁表查看锁表进程SQL语句: select * from v$session t1, v$locked_object t2 where t1.sid = t2.SESSION_ID; 如果有记录,可查到如下锁表记录 二、解锁杀掉锁表进程: 记录下SID和serial# ,分别替换掉下面的1155,39095,即可...
你可以选择在查询语句的最后加上 for update,就可以打开编辑锁,直接修改数据。而在默认查询下,点击Edit data,会报错:The query results are not updateable.SQL代码示例select * from table_name for update; (table_name为要编辑的表) 原文:http://www.cnblogs.com/yangxia-test/p/3939218.html
为了方便起见,建立了以下简单模型,和构造了部分测试数据:在某个业务受理子系统BSS中,SQL 代码1--客户资料表2createtable customers
3(
4 customer_id number(8) notnull, -- 客户标示5 city_name varchar2(10) notnull, -- 所在城市6 customer_type char(2) notnull, -- 客户类型7...
8)
9createuniqueindex PK_customers on customers (customer_id) 由于某些原因,客户所在城市这个信息并不什么准确,但是在客户服务部的CRM子系...
merge into table_c c using table_m m on(c.username = m.username) when matched then update set c.userId = m.id; ------将table_m中的id字段设置到table_c中userId字段
spool /tmp/insert2.log; ----设置执行日志文件
spool off; ------关闭日志oracle 高级update标签:本文系统来源:http://www.cnblogs.com/zhonghan/p/4522542.html
update语句的语法与原理1. 语法单表:UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值如:update t_join_situation set join_state=‘1‘whereyear=‘2011‘更新年度为“2011”的数据的join_state字段为“1”。如果更新的字段加了索引,更新时会重建索引,更新效率会慢。 多表关联,并把一个表的字段值更新到另一个表中的字段去:update 表a set a.字段1 = (select b.字段1 from 表b where a.字段2=b.字段2) where exi...
table1 f
set f.ljjine1= (select nvl(sum(nvl(b.jine1,0)),0) from table1 b where b.kjqj<=f.kjqj and b.gs=f.gs and b.bm=f.bm and b.yw=f.yw and b.currency=f.currency and substr(b.kjqj,1,4)=substr(f.kjqj,1,4)),
f.jine2 = (select nvl(sum(nvl(e.jine1,0)),0) from table2 e where e.kjqj=f.kjqj=e.gs=f.gs and e.bm=f.bm and e.yw= f.yw),
f.ljjine2 = (select nvl(sum(nvl(e.jine1,0)),0) from table2 e wher...
1. 语法
单表:UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
如:update t_join_situation set join_state=‘1‘whereyear=‘2011‘
更新年度为“2011”的数据的join_state字段为“1”。如果更新的字段加了索引,更新时会重建索引,更新效率会慢。
多表关联,并把一个表的字段值更新到另一个表中的字段去:
update 表a set a.字段1 = (select b.字段1 from 表b where a.字段2=b.字段2) where ...
select*from dept;Sql Server:
update dept a set dname=(select top 1 ename from emp where deptno=a.deptno orderby sal)经过尝试,查找资料,得出下面转换结果,不知道这样是否可行:
update dept a set dname=(with t as(select ename,deptno from emp orderby sal)select ename from t where deptno=a.deptno andrownum=1)whereexists(with t as(select ename,deptno from emp orderby sal)selectnullfrom t where deptno=a....
create table customers
(
customer_id number(8) not null, -- 客户标示
city_name varchar2(10) not null, -- 所在城市
customer_type char(2) not null, -- 客户类型
...
)
create unique index PK_customers on customers (customer_id)由于某些原因,客户所在城市这个信息并不什么准确,但是在客户服务部的CRM子系统中,通过主动服务获取了部分客户20%的所在城市等准确信息,于是你将该部分信息提取至一张临时表中:SQL 代码c...
--客户资料表
2 create table customers
3 (
4 customer_id number(8) not null, -- 客户标示
5 city_name varchar2(10) not null, -- 所在城市
6 customer_type char(2) not null, -- 客户类型
7 ...
8 )
9 create unique index PK_customers on customers (customer_id)
由于某些原因,客户所在城市这个信息并不什么准确,但是在客户服务部的CRM子系统中,通过主动服务获取了部分客户20%的所在城市等准确信息,于是你将该部分信...
可以通过以下办法解决:
先查询锁定记录
Sql代码
SELECT s.sid, s.serial# FROM v$locked_object lo, dba_objects ao, v$session s WHERE ao.object_id = lo.object_id AND lo.session_id = s.sid;
然后删除锁定记录
Sql代码
ALTER system KILL session ‘SID,serial#‘;
其中 SID填写上文中查到的SID数值,serial#填写serial#列的数值如:
ALTER system KILL session ‘214,23456‘; oracle执行update时卡死问题的解决办法标签:...
说明:笔记总结了在工作中遇到过的几种update方法和各种方法适用的范围。
1.单表更新方案:使用标准update语法即可,执行稳定且效率较高update tableset (column1,column2,...)=value1,value2,...;
2.多表关联更新举例:更新gkfq_rec表中所有slid与oa2_ftask表fi_inst相同的行,blzt字段值=oa2_ftask表的ft_lstate。
create table gkfq_rec (
slid char(12) parimary key,
blzt varchar2(50),
wjbt varchar2(100) not null,
.........
table
set (column1,column2,...)=
value1,value2,...
;
2.多表关联更新举例:更新gkfq_rec表中所有slid与oa2_ftask表fi_inst相同的行,blzt字段值=oa2_ftask表的ft_lstate。create table gkfq_rec (slid char(12) parimary key,blzt varchar2(50),wjbt varchar2(100) not null,........);create table oa2_ftask (fi_inst char(12) parimary key,fi_state int not null,ft_lstate int not null,...);
方法描述 适用范围 运行效...