https://www.idug.org/p/fo/et/thread=43184

For Fetch only 告诉DB2你只读数据,不想更新数据

FOR FETCH ONLY tells DB2 that you really are only going to READ the data (and not subsequently going to update it). This allows DB2 to me much smarter about lock avoidance. In fact, I always suggest that it's good practice to specify FOR FETCH ONLY whenever you know your cursor is read-only. Otherwise, DB2 has to guess and in the case of ambiguous cursors (that could be read only or could be updateable, DB2 has to assume the worse)

WITH UR告诉DB2,即使数据锁定了,你也可以读取。
WITH UR means you are happy to read data EVEN WHEN IT IS LOCKED BY OTHERS (Uncommitted Read) 可以读脏数据
This means your cursor will not be subject to lock waits (and possible timeouts) when reading locked data BUT you must also be prepared to accept potentially inconsistent data. For example, if someone inserts a row and then you read it but then they ROLL BACK the insert, you will have read a row "that never existed" in the table

 

两个写到一块,表示游标只读,而且会读到脏数据

We use such "FOR FETCH ONLY WITH UR" clause to our queries when we want to extract any data from real production tables for analysis without causing any disruption to the batch and online executing in production. This will tell DB2 that we need to only read some data and we are not worried if they have any inflight changes.
Of course we will be getting some uncommitted data but since we will be using these for analysis purpose only we are ok with it.
We do not have any "WITH UR" clause in any of our actual batch or online programs executing in Production. That is our standard.

 

他们两个不是互斥的,他们控制不同的事情。With ur表示,及时数据锁定了,你也可以得到返回数据。

No, they are not mutually exclusive at all - as they are controlling different things
WITH UR controls HOW the data that DB2 is processing is returned - you get data back even if it is locked

FOR FETCH ONLY says you are not then going to issue an update statement via the cursor
Now, you could argue that the FOR FETCH ONLY is superfluous, as WITH UR makes the cursor read only
BUT if, at a later date, someone were to remove the WITH UR clause, and you hadn't specified FOR FETCH ONLY you open up the possibility of an ambiguous cursor which DB2 might not be able to determine whether it is read only or not
So in my mind, it is still good practice to add FOR FETCH ONLY to EVERY cursor that you know really IS only reading data

DB2 for fetch only VS with ur相关推荐

  1. db2 with ur迁移Oracle,db2 “with ur”是什么意思!可以完成什么功能

    db2 select * from topicis.dm_qylx with ur 在DB2中,共有四種隔離級:RS,RR,CS,UR UR:UR-Uncommitted Read 未提交讀 是sql ...

  2. db2与mysql语法区别,db2和mysql语法分析异同点

    1.建表: (1)创建基本表二者是一致的 mysql:create table person(name varchar(10),age int) db2: 同上. (2)mysql支持在创建表的时候指 ...

  3. DB2 SQL性能调优秘笈

    <DB2 SQL性能调优秘笈> 基本信息 作者: (美)Tony Andrews 译者: 陈勇 杨健康 丛书名: 华章程序员书库 出版社:机械工业出版社 ISBN:978711142502 ...

  4. 关于DB2数据库和SQL

    1.在使用DB2的时候不能用limit报错: db2使用fetch first 10 rows only返回前10行数据: mysql使用limit 10返回前10行数据: oracle使用rownu ...

  5. DB2数据库嵌入式SQL开发

    如有转载,请注明出处:http://blog.csdn.net/embedded_sky BY:super_bert@csdn 1.1 DB2应用程序开发概述 1.1.1    程序结构 DB2应用程 ...

  6. DB2中cursor的使用举例

    摘要: DB2中经常会使用到CURSOR,这篇文章举几个例子说明cursor的用法. 准备工作: $ db2 "select * from t2" ID -----------   ...

  7. DB2sql——fetch first n rows only

    在db2中如果想获取前n行,只要加上fetch first n rows only 就可以了,但在oracle中没有fetch,网上很多人说可以用oracle的rownum<=n来替代db2的f ...

  8. SQL 限定返回行数

    描述: 你想限定查询结果的行数.你不关心排序,任意 n 行都可以.比如一张很大的表,你只想返回10行简单看看. 方法: 使用数据库的内置功能来控制返回的行数. DB2 使用 FETCH FIRST 子 ...

  9. 数据库开发-4-SQL优化

    Lec4-SQL优化 1. SQL优化 1.1. 关系代数 E.FCodd关系理论之父,关系代数究竟有什么用? 代数是表达式的等价变换 $ \begin{aligned} (2 + 4) \times ...

最新文章

  1. 云计算行业报告:2018, 风起云涌
  2. 刷新COCO目标检测纪录!谷歌只靠AI扩增数据,就把一个模型变成SOTA,已开源
  3. 如何对phpcms v9的首页列表进行分页?
  4. JavaScript文档
  5. 主成分分析(PCA)——以2维图像为例
  6. php如何生成订单号,php如何生成不重复订单号
  7. JQUERY的location.href.split
  8. jquery最快速入门文档
  9. UML与需求分析进阶
  10. 充值加油卡骗局:一次伪金融诈骗为何能圈数亿
  11. tikz画GPS卫星电文通信结构图
  12. Xcode5 如何添加一个Github/Repository 并且Checkout
  13. Silverlight3.0教程下载
  14. 分数混合运算简便方法_分数混合运算和简便算法
  15. 3Dmax导出插件制作
  16. vue接口总是请求超时_vue axios调用接口时请求超时
  17. 这几款真香旗舰机,买到就是赚到,有你入手了的吗?
  18. 【AI简报20210611期】Arm v9架构来啦、开源实战教你实现文字识别!
  19. 兄弟hl3150cdn打印测试页6_打印性能测试:LED高效输出_兄弟 3150CDN_办公打印评测试用-中关村在线...
  20. jQery基础参考pink老师ppt

热门文章

  1. 【26】Android - 初识Fragment
  2. 你对未来计算机的展望,未来计算机发展的展望
  3. Core Bluetooth框架之一:Central与Peripheral
  4. EIM是什么?与QQ有什么区别?
  5. 那些你可能用得上的在线办公神器
  6. win10 系统恢复后右键一直转圈卡死
  7. idea maven项目的依赖有红色波浪线解决
  8. double保留两位小数的方法
  9. ESP32学习笔记(22)——ADC接口使用
  10. 微信HOOK 删除好友