--我以前使用 trigger(行级别和块级别)来实现复杂的数据一致性,修改一个表的同时同步另外/自己表的数据
--20200619 这个技术GENERATED ALWAYS AS (f_count_yaorh(id)) VIRTUAL可以实现触发器的功能
--调用函数来作为虚拟列表达式是
-----------多表同步,我以前使用的是
drop table t_main_yaorh purge;
drop table t_sub_yaorh purge;
create table t_sub_yaorh(id number,name varchar2(20));
insert into t_sub_yaorh values(1,'thomas');
insert into t_sub_yaorh values(1,'jerry');
insert into t_sub_yaorh values(1,'kkk');
insert into t_sub_yaorh values(2,'kkk');
insert into t_sub_yaorh values(2,'John');
insert into t_sub_yaorh values(2,'John');
create or replace function f_count_yaorh(p_id number)
return number deterministic
as
li_rtn number;
begin
select count(*) into li_rtn from t_sub_yaorh where id = p_id;
return li_rtn;
exception when others then
dbms_output.put_line(sqlerrm);
end;
/
create table t_main_yaorh(id number,cnt number GENERATED ALWAYS AS (f_count_yaorh(id)) VIRTUAL);
insert into t_main_yaorh(id) values(1);
insert into t_main_yaorh(id) values(2);
commit;
select * from t_main_yaorh;
insert into t_sub_yaorh values(1,'bbb');
-----------单表多列
drop table t_main_yaorh purge;
create or replace function f_total_yaorh(p_id number)
return number deterministic
as
ld_total number;
begin
execute immediate 'select price * num from t_main_yaorh where id = :p_id' into ld_total using p_id;
return ld_total;
exception when others then
dbms_output.put_line(sqlerrm);
end;
/
create table t_main_yaorh(id number,price number,num number,total number GENERATED ALWAYS AS (f_total_yaorh(id)) VIRTUAL);
insert into t_main_yaorh(id,price,num) values(1,2.34,3);
insert into t_main_yaorh(id,price,num) values(2,1.34,2);
11g里面的虚拟列
来源:这里教程网
时间:2026-03-03 14:45:44
作者:
编辑推荐:
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- 11g里面的虚拟列
11g里面的虚拟列
26-03-03 - ORACLE DML执行计划频繁变更导致业务响应极慢问题的处理
ORACLE DML执行计划频繁变更导致业务响应极慢问题的处理
26-03-03 - 为啥苹果手机取消耳机孔和home键,却单单保留了它?原因令人佩服
为啥苹果手机取消耳机孔和home键,却单单保留了它?原因令人佩服
26-03-03 - oracle后台进程LGWR,DBWR,SMON,CKPT的工作机制
oracle后台进程LGWR,DBWR,SMON,CKPT的工作机制
26-03-03 - 手机拨号界面为什么会有"*和#"键?这2个键有什么用?望周知
手机拨号界面为什么会有"*和#"键?这2个键有什么用?望周知
26-03-03 - RMAN的使用(一)
RMAN的使用(一)
26-03-03 - 华为手机卡顿怎么解决?调节这四个设置,瞬间流畅
华为手机卡顿怎么解决?调节这四个设置,瞬间流畅
26-03-03 - 苹果手机耐用吗?看看iPhone 6S Plus用户的说法,结果很让人意外
- RMAN的使用(八)
RMAN的使用(八)
26-03-03 - 华为手机的七种截屏方法,你都知道吗?第一种可是要看机型的
华为手机的七种截屏方法,你都知道吗?第一种可是要看机型的
26-03-03
