Oracle物化视图的一般使用

<div style="margin: 0 auto; padding: 20px; font-family: -apple-system, BlinkMacSystemFont, “Segoe UI”, Roboto, “Helvetica Neue”, Arial, sans-serif;”><p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”><span style="color: black; background-color: #FFA07A; font-weight: bold;”>Oracle物化视图的一般使用

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>有个项目因为有比较多的查询汇总,考虑到速度,所以使用了物化视图。简单的把用到的给整理了下。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>先看简单创建语句:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”><span style="color: white; background-color: #FF6347; font-weight: bold;”>  view   force on  start with  next

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>((( +1,'dd-mm-yyyy'),'10:25:00'),'dd-mm-yyyy hh24:mi:ss') as

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”> * from ; –这个物化视图在每天10:25进行刷新

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>物化视图也是种视图。的物化视图是包括一个查询结果的数据库对像<strong style=”font-weight: 700; color: #5e22b0;”>oracle 物化视图 刷新</strong>,它是远程数据的的本地副本,或者用来生成基于数据表求和的汇总表。物化视图存储基于远程表的数据,也可以称为快照。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>物化视图可以查询表<span style="color: black; background-color: #FFA07A; font-weight: bold;”>Oracle物化视图的一般使用,视图和其它的物化视图。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>特点:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>(1) 物化视图在某种意义上说就是一个物理表(而且不仅仅是一个物理表),这通过其可以被查询出来,而得到确认;

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>(2) 物化视图也是一种段(),所以其有自己的物理存储属性;

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>(3) 物化视图会占用数据库磁盘空间,这点从的查询结果,可以得到佐证;

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>创建语句: view as * from

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>因为物化视图由于是物理真实存在的,故可以创建索引。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>创建时生成数据:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>分为两种:build  和 build ,

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>build 是在创建物化视图的时候就生成数据。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>build 则在创建时不生成数据,以后根据需要在生成数据。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>如果不指定,则默认为build 。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>刷新模式:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>物化视图有二种刷新模式:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>在创建时 mode是 on  还是 on 。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>on 顾名思义,仅在该物化视图“需要”被刷新了,才进行刷新(),即更新物化视图,以保证和基表数据的一致性;

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>on   提交触发,一旦基表有了,即事务提交,则立刻刷新,立刻更新物化视图,使得数据和基表一致。一般用这种方法在操作基表时速度会比较慢。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>创建物化视图时未作指定,则按 on  模式来创建。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>上面说的是刷新的模式,针对于如何刷新,则有三种刷新方法:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>完全刷新(): 会删除表中所有的记录(如果是单表刷新,可能会采用的方式),然后根据物化视图中查询语句的定义重新生成物化视图。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>快速刷新(FAST): 采用增量刷新的机制,只将自上次刷新以后对基表进行的所有操作刷新到物化视图中去。FAST必须创建基于主表的视图日志。对于增量刷新选项,如果在子查询中存在分析函数<strong style=”font-weight: 700; color: #5e22b0;”>oracle 物化视图 刷新</strong><strong style=”font-weight: 700; color: #5e22b0;”>oracle 物化视图 刷新</strong>,则物化视图不起作用。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>FORCE方式:这是默认的数据刷新方式。会自动判断是否满足快速刷新的条件,如果满足则进行快速刷新,否则进行完全刷新。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>关于快速刷新:物化视图的快速刷新机制是通过物化视图日志完成的。通过一个物化视图日志还可以支持多个物化视图的快速刷新。物化视图日志根据不同物化视图的快速刷新的需要,可以建立为ROWID或 KEY类型的。还可以选择是否包括、 NEW 以及指定列的列表。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>查询重写():

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>包括  query  和  query  两种。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”><span style="color: white; background-color: #FF69B4; font-weight: bold;”>分别指出创建的物化视图是否支持查询重写。查询重写是指当对物化视图的基表进行查询时<span style="color: black; background-color: #FFA07A; font-weight: bold;”>Oracle物化视图的一般使用,会自动判断能否通过查询物化视图来得到结果,如果可以,则避免了聚集或连接操作,而直接从已经计算好的物化视图中读取数据。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”><span style="color: white; background-color: #FF8C00; font-weight: bold;”>默认为 query 。

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”><span style="color: yellow; background-color: #007BFF; font-weight: bold;”>语法:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”><span style="color: white; background-color: #FF6347; font-weight: bold;”>  view 

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”><span style="color: black; background-color: #FFA07A; font-weight: bold;”>fast||force

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>on

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>|

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>start with () next ()

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>AS ;

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>具体操作

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>创建物化视图需要的权限:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>grant <span style="color: white; background-color: #FF6347; font-weight: bold;”>  view to ;

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>在源表建立物化视图日志:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”><span style="color: white; background-color: #FF6347; font-weight: bold;”>  view log on 

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>  — 日志空间

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>with  key;     — 指定为主键类型

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>在目标数据库上创建 VIEW:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”><span style="color: white; background-color: #FF6347; font-weight: bold;”>  view   force on  start with  next

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>(((+1,'dd-mm-yyyy'),'10:25:00'),'dd-mm-yyyy hh24:mi:ss') as

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”> * from ; –这个物化视图在每天10:25进行刷新

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>修改刷新时间:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>alter<span style="color: white; background-color: #FF6347; font-weight: bold;”>  view   force on  start with 

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>next (((+1,'dd-mm-yyyy'),' 23:00:00'),'dd-mm-yyyy hh24:mi:ss');

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>alter<span style="color: white; background-color: #FF6347; font-weight: bold;”>  view   force on  start with 

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>next trunc(,'dd')+1+1/24; — 每天1点刷新

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>建立索引:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”> index 

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>on (ID,UNAME)

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>删除物化视图及日志:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>drop<span style="color: white; background-color: #FF6347; font-weight: bold;”>  view log on ;    –删除物化视图日志:

<p style="margin: 1em 0; line-height: 1.9; font-size: 16px; color: #262626; text-align: justify;”>drop<span style="color: white; background-color: #FF6347; font-weight: bold;”>  view ; –删除物化视图

公告:
1. 本站所有资源来源于用户上传和网络,如有侵权请联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系站长处理!
6. 本站不售卖代码,资源标价只是站长收集整理的辛苦费!如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。
7. 站长QQ号码 2205675299

资源库 - 资源分享下载网 » Oracle物化视图的一般使用

常见问题FAQ

关于资源售价和售后服务的说明?
本站所有资源的标价均为本站收集资源的辛苦费,不代表资源本身的价值。软件是高智慧高价值的商品,不可能是白菜价。本站资源标价只是赞助费用,收取的赞助费仅用来维持本站的日常运营!毕竟收集整理资料需要投入云计算资源和站长大量的精力。
代码有没有售后服务和技术支持?
由于代码的运行具有不可预见性,本站不保证代码完整可运行,不提供技术支持和售后服务。 本站原创代码都是站长自己开发的,可以有偿提供技术支持服务。 网站里标明【亲测】的代码都是站长亲测过的,其他的代码由于精力有限,没有一一测试,不能保证代码就一定能够使用,更没有技术支持服务,下载前请自行斟酌。
有没有搭建服务?
由于搭建服务比较费时费力,所以本站除了原创代码外均不提供搭建服务。本站分享代码纯属兴趣爱好,不以盈利为目的,请勿咨询有没有搭建服务,谢谢理解。
链接地址失效了怎么办?
请带上资源链接地址联系客服,工作时间内我们看到后将第一时间回复。
关于解压密码
本站资源一般都没有加密,如果发现需要解压密码的,那么就输入 hao.35dc.com 试试。

发表评论

资源库,由老程序员细心甄别、精心筛选,只为提供优质的源码资源

关于我们 联系我们