- 浏览: 190322 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
xing_kenny:
...
maven中jetty配置 -
springaop_springmvc:
可以参考最新的文档:如何在eclipse jee中检出项目并转 ...
maven 中 部署构件至Nexus(mvn deploy) -
13594135:
如何整合ScheduledTimerTask与Quartz到系 ...
spring计划任务(转) -
337240552:
...
maven中jetty配置 -
alanland:
你执行命令的目录不对吧
maven中jetty配置
--备份 create table content_20110112 as select * from content; alter table content_20110112 add constraint content_20110112_key primary key(contid); --回退 update content t set t.products = (select o.products from content_20110112 o where o.contid = t.contid) where t.object_id in('11111111000000010000000000000896'); --回退方法二 update ( select /*+ BYPASS_UJVC */ t.contid t1,o.contid t2,t.products as p1 , o.products as p2 from content_20110112 o join content t on t.contid = o.contid --where t.object_id in('11111111000000010000000000000896') ) xx set p1 = p2
BYPASS_UJVC的作用是跳过Oracle的键检查。
引用
Oracle中Update的一个写法,注意异常ORA-01779
---------------------------
这篇是转的,大家在写SQL的时候特别注意不要犯此类ORA-01779错误.
-- 一、==========
Oracle中试图对一个子查询进行更新时可能会出现ORA-01779错误。该错误的内容为:
ORA-01779: cannot modify a column which maps to a non-key-preserved table例如,使用以下的更新查询就会出现该错误。
CREATE TABLE test1 ( id integer primary key, num integer );
INSERT INTO test1 VALUES (1,0);
INSERT INTO test1 VALUES (2,0);
INSERT INTO test1 VALUES (3,0);
INSERT INTO test1 VALUES (4,0);
CREATE TABLE test2 ( id integer, num integer, upd integer );
INSERT INTO test2 VALUES (1,10, 0);
INSERT INTO test2 VALUES (2,20, 1);
UPDATE ( SELECT t1.id id1, t1.num num1, t2.id id2, t2.num num2
FROM test1 t1, test2 t2 WHERE t1.id=t2.id AND t2.upd=1 )
SET num1=num2; ORA-01779: cannot modify a column which maps to a non-key-preserved table
这个错误的意思是,子查询的结果中,更新数据源(test2)的内容不唯一,导致被更新对象(test1)中的一行可能对应数据源(test2)中的多行。本例中,test2表的id不唯一,因此test2表中可能存在id相同但是num不相同的数据,这种数据是无法用来更新 test1 的。
解决方法就是保证数据源的唯一性,例如本例中可以为test2.id创建一个唯一索引:
CREATE UNIQUE INDEX test2_idx_001 ON test2 (id);
之后上面的更新就可以执行了。
另外也可以强制 Oracle 执行,方法是加上 BYPASS_UJVC 注释。
UPDATE
( SELECT t1.id id1, t1.num num1, t2.id id2, t2.num num2
FROM test1 t1, test2 t2
WHERE t1.id=t2.id AND t2.upd=1 )
SET num1=num2;
BYPASS_UJVC的作用是跳过Oracle的键检查。这样虽然能够执行了,但是如果test2中存在不唯一的数据,test1就会被更新多次而导致意想不到的结果。
--二、========================
SQL> create table a ( id int, a1 varchar2(25) );
SQL> create table b ( id int, b1 varchar2(25) );
SQL> insert into a values ( 1, 'Hello' );
SQL> insert into a values ( 2, '**xx' );
SQL> insert into b values ( 2, 'World' );
SQL> commit;
SQL> update ( select a1, b1 from a, b where a.id = b.id )
2 set a1 = b1;
set a1 = b1
*
ERROR at line 2:
ORA-01779: cannot modify a column which maps to a non key-preserved table
--无法Update,必须要有一个主键
SQL> alter table b add constraint b_key primary key(id);
SQL> update ( select a1, b1 from a, b where a.id = b.id )
2 set a1 = b1;
1 row updated.
--可以Update
SQL> update ( select a1, b1 from a, b where a.id = b.id )
2 set b1 = a1;
set b1 = a1
*
ERROR at line 2:
ORA-01779: cannot modify a column which maps to a non key-preserved table
--交换位置后依旧无法更新
SQL> alter table b drop constraint b_key;
SQL> alter table a add constraint a_key primary key(id);
SQL> update ( select a1, b1 from a, b where a.id = b.id )
2 set b1 = a1;
1 row updated.
--为表a设置主键后可以更新
SQL> alter table a drop constraint a_key;
SQL> alter table a add constraint a_key primary key(id,a1);
SQL> update ( select a1, b1 from a, b where a.id = b.id )
2 set b1 = a1;
set b1 = a1
*
ERROR at line 2:
ORA-01779: cannot modify a column which maps to a non key-preserved table
--使用联合主键仪不可以的,必须是关联字段
由上可知,使用这种方式来更新表,需要用于更新的表(最终数据表)的关联字段必须设置为主键,且不可多字段主键。另外还有一个网友也指出了另外一个问题:
If the user has update permission on table A, but only has select permission on table B, they cannot update via the first example. Oracle will return ORA-01031 (insufficient privileges).
测试一下:
SQL> create user x identified by x;
SQL> grant create session on x;
SQL> grant select,update on a to x;
SQL> grant select on b to x;
SQL> create public synonym a for wangxiaoqi.a;
SQL> create public synonym b for wangxiaoqi.b;
SQL> conn x/x
Connected.
SQL> update ( select a1, b1 from a, b where a.id = b.id )
2 set a1 = b1;
update ( select a1, b1 from a, b where a.id = b.id )
*
ERROR at line 1:
ORA-01031: insufficient privileges
--系统报错权限不够
SQL> update a set a1 = (select b1 from b where b.id=a.id);
2 rows updated.
--使用Update...Select...语句是可以更新成功的
--三、===========================
ORA-01779问题的解决作者:coordinator 来源:博客园
昨天帮一个师弟看一个ORACLE触发器T的问题,这个触发器建在视图V上,当用户往视图里插记录的时候就自动插到视图的组成表里。但是每次插入总提示,ORA-01779 cannot modify a column which maps to a non key-preserved table。而怪异的是,有一个视图V2和V的构成方式一摸一样,但是它的触发器T2就没问题。在网上找了很多帖子,绝大部分原因都是插入的基本表记录不唯一,我检查了触发器内容和基本表的keys,都没问题。
到第二天的时候突然看到一个帖子的原因解释:
view的更改是有限制的
General Rule
Any INSERT, UPDATE, or DELETE operation on a join view can modify only one underlying base table at a time.
UPDATE Rule
All updatable columns of a join view must map to columns of a key-preserved table. If the view is defined with the WITH CHECK OPTION clause, then all join columns and all columns of repeated tables are non-updatable.
DELETE Rule
Rows from a join view can be deleted as long as there is exactly one key-preserved table in the join. If the view is defined with the WITH CHECK OPTION clause and the key preserved table is repeated, then the rows cannot be deleted from the view.
INSERT Rule
An INSERT statement must not explicitly or implicitly refer to the columns of a non-key preserved table. If the join view is defined with the WITH CHECK OPTION clause, INSERT statements are not permitted.
(http://www.itpub.net/225291.html)
再检查了触发器,发现事件那块只关联了UPDATE,其他都没关联,粗心啊。全部关联上就好了。
看来触发器的几个选项一定要好好检查啊。
---------------------------
这篇是转的,大家在写SQL的时候特别注意不要犯此类ORA-01779错误.
-- 一、==========
Oracle中试图对一个子查询进行更新时可能会出现ORA-01779错误。该错误的内容为:
ORA-01779: cannot modify a column which maps to a non-key-preserved table例如,使用以下的更新查询就会出现该错误。
CREATE TABLE test1 ( id integer primary key, num integer );
INSERT INTO test1 VALUES (1,0);
INSERT INTO test1 VALUES (2,0);
INSERT INTO test1 VALUES (3,0);
INSERT INTO test1 VALUES (4,0);
CREATE TABLE test2 ( id integer, num integer, upd integer );
INSERT INTO test2 VALUES (1,10, 0);
INSERT INTO test2 VALUES (2,20, 1);
UPDATE ( SELECT t1.id id1, t1.num num1, t2.id id2, t2.num num2
FROM test1 t1, test2 t2 WHERE t1.id=t2.id AND t2.upd=1 )
SET num1=num2; ORA-01779: cannot modify a column which maps to a non-key-preserved table
这个错误的意思是,子查询的结果中,更新数据源(test2)的内容不唯一,导致被更新对象(test1)中的一行可能对应数据源(test2)中的多行。本例中,test2表的id不唯一,因此test2表中可能存在id相同但是num不相同的数据,这种数据是无法用来更新 test1 的。
解决方法就是保证数据源的唯一性,例如本例中可以为test2.id创建一个唯一索引:
CREATE UNIQUE INDEX test2_idx_001 ON test2 (id);
之后上面的更新就可以执行了。
另外也可以强制 Oracle 执行,方法是加上 BYPASS_UJVC 注释。
UPDATE
( SELECT t1.id id1, t1.num num1, t2.id id2, t2.num num2
FROM test1 t1, test2 t2
WHERE t1.id=t2.id AND t2.upd=1 )
SET num1=num2;
BYPASS_UJVC的作用是跳过Oracle的键检查。这样虽然能够执行了,但是如果test2中存在不唯一的数据,test1就会被更新多次而导致意想不到的结果。
--二、========================
SQL> create table a ( id int, a1 varchar2(25) );
SQL> create table b ( id int, b1 varchar2(25) );
SQL> insert into a values ( 1, 'Hello' );
SQL> insert into a values ( 2, '**xx' );
SQL> insert into b values ( 2, 'World' );
SQL> commit;
SQL> update ( select a1, b1 from a, b where a.id = b.id )
2 set a1 = b1;
set a1 = b1
*
ERROR at line 2:
ORA-01779: cannot modify a column which maps to a non key-preserved table
--无法Update,必须要有一个主键
SQL> alter table b add constraint b_key primary key(id);
SQL> update ( select a1, b1 from a, b where a.id = b.id )
2 set a1 = b1;
1 row updated.
--可以Update
SQL> update ( select a1, b1 from a, b where a.id = b.id )
2 set b1 = a1;
set b1 = a1
*
ERROR at line 2:
ORA-01779: cannot modify a column which maps to a non key-preserved table
--交换位置后依旧无法更新
SQL> alter table b drop constraint b_key;
SQL> alter table a add constraint a_key primary key(id);
SQL> update ( select a1, b1 from a, b where a.id = b.id )
2 set b1 = a1;
1 row updated.
--为表a设置主键后可以更新
SQL> alter table a drop constraint a_key;
SQL> alter table a add constraint a_key primary key(id,a1);
SQL> update ( select a1, b1 from a, b where a.id = b.id )
2 set b1 = a1;
set b1 = a1
*
ERROR at line 2:
ORA-01779: cannot modify a column which maps to a non key-preserved table
--使用联合主键仪不可以的,必须是关联字段
由上可知,使用这种方式来更新表,需要用于更新的表(最终数据表)的关联字段必须设置为主键,且不可多字段主键。另外还有一个网友也指出了另外一个问题:
If the user has update permission on table A, but only has select permission on table B, they cannot update via the first example. Oracle will return ORA-01031 (insufficient privileges).
测试一下:
SQL> create user x identified by x;
SQL> grant create session on x;
SQL> grant select,update on a to x;
SQL> grant select on b to x;
SQL> create public synonym a for wangxiaoqi.a;
SQL> create public synonym b for wangxiaoqi.b;
SQL> conn x/x
Connected.
SQL> update ( select a1, b1 from a, b where a.id = b.id )
2 set a1 = b1;
update ( select a1, b1 from a, b where a.id = b.id )
*
ERROR at line 1:
ORA-01031: insufficient privileges
--系统报错权限不够
SQL> update a set a1 = (select b1 from b where b.id=a.id);
2 rows updated.
--使用Update...Select...语句是可以更新成功的
--三、===========================
ORA-01779问题的解决作者:coordinator 来源:博客园
昨天帮一个师弟看一个ORACLE触发器T的问题,这个触发器建在视图V上,当用户往视图里插记录的时候就自动插到视图的组成表里。但是每次插入总提示,ORA-01779 cannot modify a column which maps to a non key-preserved table。而怪异的是,有一个视图V2和V的构成方式一摸一样,但是它的触发器T2就没问题。在网上找了很多帖子,绝大部分原因都是插入的基本表记录不唯一,我检查了触发器内容和基本表的keys,都没问题。
到第二天的时候突然看到一个帖子的原因解释:
view的更改是有限制的
General Rule
Any INSERT, UPDATE, or DELETE operation on a join view can modify only one underlying base table at a time.
UPDATE Rule
All updatable columns of a join view must map to columns of a key-preserved table. If the view is defined with the WITH CHECK OPTION clause, then all join columns and all columns of repeated tables are non-updatable.
DELETE Rule
Rows from a join view can be deleted as long as there is exactly one key-preserved table in the join. If the view is defined with the WITH CHECK OPTION clause and the key preserved table is repeated, then the rows cannot be deleted from the view.
INSERT Rule
An INSERT statement must not explicitly or implicitly refer to the columns of a non-key preserved table. If the join view is defined with the WITH CHECK OPTION clause, INSERT statements are not permitted.
(http://www.itpub.net/225291.html)
再检查了触发器,发现事件那块只关联了UPDATE,其他都没关联,粗心啊。全部关联上就好了。
看来触发器的几个选项一定要好好检查啊。
发表评论
-
oracle Shrink命令
2012-03-31 11:01 2223从10g开始,oracle开始 ... -
Oracle怎么对IN子查询使用绑定变量(转)
2011-05-28 17:11 3808在实际使用中,经常会有带in的子查询,如where id in ... -
PowerDesigner中name和code取消自动关联(转)
2011-04-15 11:30 5336PowerDesigner中,但修改了某个字段的name,其c ... -
awr报表解读
2011-03-06 01:20 18131. Redo size:每秒产生的 ... -
awr报表生成方法
2011-03-06 00:37 1946可以通过调用oracle数据库服务器里awrrpt.sql或a ... -
数据库表被锁死
2011-03-06 00:00 72843月3日下午,系统发生了严重故障,后台程序大量抛出如下异常 ... -
oracle性能分析语句
2011-02-26 14:56 18551.cpu负载高的语句 select b.sql_te ... -
EXPDP命令行选项
2011-02-13 03:46 1338EXPDP命令行选项 1. ATTACH expd ... -
oracle常用命令
2011-02-13 00:02 2002--启动数据库 lsnrctl stop; lsnrctl s ... -
数据库名、实例名、数据库域名、全局数据库名、服务名(转)
2011-02-12 23:47 1055数据库名、实例名、数 ... -
Oracle中的Union、Union All、Intersect、Minus(转)
2011-02-12 00:48 1310众所周知的几个结果集 ... -
学习Oracle动态性能表V$sql(转)
2011-01-29 23:36 8638本视图持续跟踪所有shared pool中的共享cursor, ... -
免安装oracle客户端与plsql连接远程(转)
2011-01-20 11:40 17481、在安装ORACLE服务器的机器上搜索下列文件, oci ... -
linux mysql相关操作(转)
2010-08-03 14:36 1236linux mysql 安装介绍: linux 服务器 Re ... -
mysql在linux下安装
2010-08-03 13:15 1103Can't open the mysql.plugin tab ... -
sqlServer2000实用sql语句
2010-05-15 12:04 11031.备份数据库 backup database mast ...
相关推荐
方法一(推荐): UPDATE 表2 ...尤其注意最后的外层where条件尤为重要,是锁定其批量更新数据的范围。 方法二: MERGE INTO 表2 USING 表1 ON (表2.A = 表1.A) -- 条件是 A 相同 WHEN MATCHED THEN UP
ORACLE批量更新四种方法.txt ORACLE批量更新四种方法.txtORACLE批量更新四种方法.txt ORACLE批量更新四种方法.txt
Oracle数据库分区表操作方法Oracle数据库分区表操作方法
Oracle数据表更新即时通告的实现方法.pdf
Oracle批量快速更新方法
oracle中对blob字段的处理方法,包括增加,删除,修改,更新等操作。
SQL Server中这是比较容易解决的,而Oracle中不知道方法了。 SQL Server中类似问题的解决方法 后来只好用笨的方法: 首先,将数据复制到Excel;(假设称测试库的表为A–含有数据) 然后,在开发库中...
想要调整字段顺序非常不容易,网上的方法竟然都是备份表之后删除再重建,这样整的话不是麻烦而是忒麻烦。查找了一些资料,发现有办法可以解决,而不用那么大费周章,如果更改的话需要SYS的权限,废话少说了
内容涉及oracle 12的容器数据库,可插入数据库,目前只做了DML的数据同步(不含ddl的同步)
原因和解决方法 这种只有update无法执行其他语句可以执行的其实是因为记录锁导致的,在oracle中,执行了update或者insert语句后,都会要求commit,如果不commit却强制关闭连接,oracle就会将这条提交的记录锁住。...
修改项目时,涉及到了Oracle中许多表的修改(包括:增加、删除字段,修改注释等)。由于开始没有进行记录,造成在上测试机时,忘记了具体修改过哪些表了。后来在网上查找了一些资料,例如: 代码如下: 1、select uat...
我们在平时的工作中可能遇到过,多表级联更新,我也在网上看到过不少的方法,但是使用这些方法一般都没成功过,所以今天我给大家介绍一种稍微麻烦的方法,有需要的朋友可以参考下
sap开发中 模块连接oracle数据库的具体方法步骤详细说明
分别有:数据源配置、数据表结构转换、字段更新、数据迁移、根据oracle SQL的UPDATE DELETE 事物执行记录转为Mysql可执行SQL,同步执行到MySql数据库,此项目为个人兴趣爱好练手项目,项目问题欢迎留言,共同进步...
ImportExcel2Oracle.aspx通过dateset.update把数据更新到oracle数据库中的RAWDATA表中,当oracle数据库表中数据很大时,这种导入速度很慢,但是表数据空时导入比较快。ImportExcelData2Oracle.aspx通过oracle 的sql...
第5章 Oracle数据表对象(教学视频:42分钟) 63 5.1 Oracle表空间 63 5.1.1 Oracle表空间简介 63 5.1.2 创建Oracle表空间 64 5.1.3 查看表空间 66 5.1.4 修改数据库默认表空间 67 5.1.5 修改表空间名称 68 ...
一种将oracle数据库内的数据导入到mongodb数据库的方法及系统.docx
第4章 规划Oracle应用程序——方法、风险和标准 第Ⅱ部分 SQL和SQL*Plus 第5章 SQL中的基本语法 第6章 基本的SQL*Plus报表及命令 第7章 文本信息的收集与修改 第8章 正则表达式搜索 第9章 数值处理 第10章 日期:...
NULL 博文链接:https://yanxinfeng.iteye.com/blog/559874