view不能更新的情况:
1。基本表中没有的列不能更新
2。基本表中存在连接的情况
除了这两种情况,还有别的情况不能更新么这两种情况为什么不能更新?/
1。基本表中没有的列不能更新
2。基本表中存在连接的情况
除了这两种情况,还有别的情况不能更新么这两种情况为什么不能更新?/
解决方案 »
- oracle9201 升级9208问题
- 简单问题大家来抢分
- mysql 3.51中有无information_schema信息数据库?
- 求写一条存储过程。。新手期待中。。
- oracle在java存储过程中如何创建和删除 txt文件呢,是否需要授权呢
- 怎样把Oracle中的数据转移到 active directory 中啊
- 有谁用过Oracle10g呀,安装完之后启动Oracle服务有问题呀!
- 怎样在ORACLE 9i中使用中文字段???
- 请高手指点:在一个数据量比较大的系统中,怎样让系统自动保存近两年的数据?而无需维护!
- order by 问题
- ORACLE中TRANSACTION ISOLATION的理解
- 求oracle数据库中表字段的每个小时均值SQL语句
比如 视图是通过a的字段查询到b的字段 又关联c的字段 只显示出了a和c的字段
通过a的字段在视图中查询c的字段的值 但是C中等于这个值的不一定都能和a有关系 这样就会造成混乱
SQL> create or replace view v_deptemp
2 as
3 select a.empno,a.ename,a.sal,b.deptno,b.dname
4 from emp a,dept b
5 where a.deptno=b.deptno
6 /视图已创建。SQL> select * from v_deptemp where empno=1688
2 /未选定行SQL> select * from dept where deptno=50
2 /未选定行SQL> ed
已写入 file afiedt.buf 1 create or replace trigger tri_v_deptemp instead of insert on v_deptemp
2 for each row
3 begin
4 begin
5 insert into dept(deptno,dname) values(:new.deptno,:new.dname);
6 exception
7 when others then
8 null;
9 end;
10 begin
11 insert into emp(empno,ename,sal,deptno) values(:new.empno,:new.ename,:new.sal,:new.deptno);
12 exception
13 when others then
14 null;
15 end;
16* end;
SQL> /触发器已创建SQL> insert into v_deptemp values(1688,'scott',5000,50,'db')
2 /已创建 1 行。SQL> commit
2 /提交完成。SQL> select * from v_deptemp where empno=1688
2 / EMPNO ENAME SAL DEPTNO DNAME
---------- ---------- ---------- ---------- --------------
1688 scott 5000 50 dbSQL>
create or replace view my_emp_view
as
select d.deptno,d.dname,e.ename,e.empno
from dept d,emp e
where d.deptno=e.deptno--更新视图
update my_emp_view set ename='张三' where empno=7900;
可以执行。update my_emp_view set dname='市场部' where empno=7900;
不可以执行。因为此时dname是通过表连接动态计算出来的。分析:视图能否更新,取决于所更新的行是否能与实际数据表中的行一一对应,如果能对应,则可以更新。emp表中的每一行数据与my_emp_view视图中的每一行能够一一对应,但是dept表中的每一行数据却对应my_emp_view视图的多行数据,所以在my_emp_view视图中是不能更新部门信息的,但是能够更新员工数据。
刚在公交车上想了下 对于有外键约束的则不可以更新没有则可以
SQL> create or replace trigger tri_v_deptemp instead of insert or update on v_deptemp
2 for each row
3 begin
4 if inserting then
5 begin
6 insert into dept(deptno,dname) values(:new.deptno,:new.dname);
7 exception
8 when others then
9 null;
10 end;
11 begin
12 insert into emp(empno,ename,sal,deptno) values(:new.empno,:new.ename,:new.sal,:new.deptno);
13 exception
14 when others then
15 null;
16 end;
17 end if;
18 if updating then
19 begin
20 update dept set deptno=:new.deptno,dname=:new.dname where deptno=:old.deptno;
21 exception
22 when others then
23 dbms_output.put_line(sqlcode||' '||sqlerrm);
24 end;
25 begin
26 update emp set empno=:new.empno,ename=:new.ename,sal=:new.sal,deptno=:new.deptno
27 where deptno=:old.deptno;
28 exception
29 when others then
30 dbms_output.put_line(sqlcode||' '||sqlerrm);
31 end;
32 end if;
33 end;
34 /触发器已创建SQL> select * from v_deptemp where deptno=50
2 / EMPNO ENAME SAL DEPTNO DNAME
---------- ---------- ---------- ---------- --------------
1688 scott 5000 50 dbSQL> QL> select * from dept where deptno=50
2 / DEPTNO DNAME LOC
--------- -------------- -------------
50 dbQL> select * from emp where deptno=50
2 / EMPNO ENAME JOB MGR HIREDATE SAL COMM
--------- ---------- --------- ---------- -------------- ---------- ----------
DEPTNO
---------
1688 scott 5000
50
SQL> alter table emp drop constraint FK_DEPTNO ----这里删除了外键约束
2 /表已更改。SQL> update v_deptemp set deptno=60 where deptno=50
2 /已更新 1 行。SQL> commit
2 /提交完成。SQL> select * from v_deptemp where deptno=50
2 /未选定行SQL> select * from v_deptemp where deptno=60
2 / EMPNO ENAME SAL DEPTNO DNAME
---------- ---------- ---------- ---------- --------------
1688 scott 5000 60 dbSQL> select * from emp where deptno=60
2 / EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- -------------- ---------- ----------
DEPTNO
----------
1688 scott 5000
60
SQL> select * from dept where deptno=60
2 / DEPTNO DNAME LOC
---------- -------------- -------------
60 db
否则报ORA-02292: 违反完整约束条件 (SCOTT.FK_DEPTNO) - 已找到子记录
ORA-02291: 违反完整约束条件 (SCOTT.FK_DEPTNO) - 未找到父项关键字