楼主: dingjun123

[精华] 【有奖讨论】PL/SQL编程要点和注意点

[复制链接]
论坛徽章:
1088
金色在线徽章
日期:2007-04-25 04:02:08金色在线徽章
日期:2007-06-29 04:02:43金色在线徽章
日期:2007-03-11 04:02:02在线时间
日期:2007-04-11 04:01:02在线时间
日期:2007-04-12 04:01:02在线时间
日期:2007-03-07 04:01:022008版在线时间
日期:2010-05-01 00:01:152008版在线时间
日期:2011-05-01 00:01:342008版在线时间
日期:2008-06-03 11:59:43ITPUB年度最佳技术原创精华奖
日期:2013-03-22 13:18:30
71#
 楼主| 发表于 2012-2-1 09:21 | 只看该作者
tom对于limit值的观点

You Asked
Hi Tom, could you please tell me if exists any difference with LIMIT 1000 and for example LIMIT 100000? If I

increase the number of the limit... my process could run faster?

Thanks!

and we said...
it might

a) run faster (doubtful)
b) the same (doubtful)
c) slower


somewhere between 100 and 500 is typically "the best", getting 100k records INTO MEMORY and managing them take

"work"

What is the limit or the upper end of LIMIT.
At what threshold of LIMIT , will we get optimum performance.

i.e. what would you recommend the LIMIT to be ,  1000 or 2000, or 3000 or 5000 or 10,000



Followup   October 10, 2001 - 11am Central time zone:

I'd suggest hundreds, not thousands.  There are ram concerns, you want to keep the interaction
between you and database going back and forth -- not "ok database do tons of work, then I'll do
tons of work and then I'll give you tons of work again".  You want things to be flowing between you
and the database -- not "bursting" between you and the db.

Consider this -- if you array insert 10k rows - you might have to wait for LGWR to make room in the
redo buffer cache (sync writes to the file system).  If you send him 100 or 500 rows -- you won't
wait and LGWR will flush the buffer cache in the background whilst you are off doing the next
100/500 rows.

"Consider this -- if you array insert 10k rows - you might have to wait for LGWR to make room in
the redo buffer cache (sync writes to the file system).  If you send him 100 or 500 rows -- you
won't wait and LGWR will flush the buffer cache in the background whilst you are off doing the next
100/500 rows."

Firstly, YES, I will limit it to a figures between 100 and 500, but what can be the max number, out
of academic interest.

Secondly, what if the redo buffer has a lot of memory, then even in the case I set the limit at
5000, then it should not slow down the process, Iam I right.

Thirdly, Setting the LIMIT to a lesser number, does it also mean faster execution. , then when you
set the LIMIT to a hight number.

KIndly expand on the below--
"if you array insert 10k rows - you might have to wait for LGWR to make room in the redo buffer
cache (sync writes to the file system).  "

使用道具 举报

回复
论坛徽章:
16
数据库板块每日发贴之星
日期:2007-12-03 01:03:272010世博会纪念徽章
日期:2010-09-14 17:24:312010新春纪念徽章
日期:2010-03-01 11:20:05生肖徽章2007版:马
日期:2009-11-13 10:55:15参与WIN7挑战赛纪念
日期:2009-11-06 10:44:24CTO参与奖
日期:2009-03-23 11:00:18生肖徽章2007版:马
日期:2009-02-08 17:20:54生肖徽章2007版:兔
日期:2008-12-01 13:33:59生肖徽章2007版:马
日期:2008-10-31 19:01:49奥运会纪念徽章:赛艇
日期:2008-10-24 13:25:17
72#
发表于 2012-2-9 23:04 | 只看该作者
lastwinner 发表于 2012-1-10 01:58
编程规范我还想到一点——空格,记得在某个版本的pl/sql中,如果你写了如下一行代码
k:=0;
for i in 1... ...

没看出来是怎么回事啊,
执行报错啊.

使用道具 举报

回复
论坛徽章:
520
奥运会纪念徽章:垒球
日期:2008-09-15 01:28:12生肖徽章2007版:鸡
日期:2008-11-17 23:40:58生肖徽章2007版:马
日期:2008-11-18 05:09:48数据库板块每日发贴之星
日期:2008-11-29 01:01:02数据库板块每日发贴之星
日期:2008-12-05 01:01:03生肖徽章2007版:虎
日期:2008-12-10 07:47:462009新春纪念徽章
日期:2009-01-04 14:52:28数据库板块每日发贴之星
日期:2009-02-08 01:01:03生肖徽章2007版:蛇
日期:2009-03-09 22:18:532009日食纪念
日期:2009-07-22 09:30:00
73#
发表于 2012-2-9 23:12 | 只看该作者
xilangxiangwa 发表于 2012-2-9 23:04
没看出来是怎么回事啊,
执行报错啊.

你没看到他FOR的那一行露了三点?

使用道具 举报

回复
论坛徽章:
16
数据库板块每日发贴之星
日期:2007-12-03 01:03:272010世博会纪念徽章
日期:2010-09-14 17:24:312010新春纪念徽章
日期:2010-03-01 11:20:05生肖徽章2007版:马
日期:2009-11-13 10:55:15参与WIN7挑战赛纪念
日期:2009-11-06 10:44:24CTO参与奖
日期:2009-03-23 11:00:18生肖徽章2007版:马
日期:2009-02-08 17:20:54生肖徽章2007版:兔
日期:2008-12-01 13:33:59生肖徽章2007版:马
日期:2008-10-31 19:01:49奥运会纪念徽章:赛艇
日期:2008-10-24 13:25:17
74#
发表于 2012-2-9 23:16 | 只看该作者
是啊,所以报错啊,
那因空格导致结果出人意料是怎么个说法?

使用道具 举报

回复
论坛徽章:
16
数据库板块每日发贴之星
日期:2007-12-03 01:03:272010世博会纪念徽章
日期:2010-09-14 17:24:312010新春纪念徽章
日期:2010-03-01 11:20:05生肖徽章2007版:马
日期:2009-11-13 10:55:15参与WIN7挑战赛纪念
日期:2009-11-06 10:44:24CTO参与奖
日期:2009-03-23 11:00:18生肖徽章2007版:马
日期:2009-02-08 17:20:54生肖徽章2007版:兔
日期:2008-12-01 13:33:59生肖徽章2007版:马
日期:2008-10-31 19:01:49奥运会纪念徽章:赛艇
日期:2008-10-24 13:25:17
75#
发表于 2012-2-9 23:44 | 只看该作者
关了电脑,准备上了厕所睡觉,
哪知突然想到 lastwinner 说的应该是指三点中最后一个点与倒数第二点之间有个空格,然后系统误认为是
0.255
这样才会出现结果认人大跌眼镜

上完厕所开机一试果然如此:
declare
k number(30,4);
begin
k:=0;
for i in 1.. .255 loop
    k:=k+i;
end loop;

dbms_output.put_line(k);
end;

0

使用道具 举报

回复
论坛徽章:
484
ITPUB北京香山2007年会纪念徽章
日期:2007-01-24 14:35:02ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24ITPUB北京2009年会纪念徽章
日期:2009-02-09 11:42:452010新春纪念徽章
日期:2010-03-01 11:04:552010数据库技术大会纪念徽章
日期:2010-05-13 10:04:272010系统架构师大会纪念
日期:2010-09-04 13:35:54ITPUB9周年纪念徽章
日期:2010-10-08 09:28:512011新春纪念徽章
日期:2011-02-18 11:43:32ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:54
76#
发表于 2012-2-10 00:01 | 只看该作者
xilangxiangwa 发表于 2012-2-9 23:04
没看出来是怎么回事啊,
执行报错啊.

你的服务器端和客户端的版本各是啥?
有的版本不报错,有的版本报错,这个事情很好玩
报错的,会认为 1...255 中的 ... 是非法操作符
不报错的,会将 1...255 解析为 1 .. .25,即1 .. 0.25,所以,结果你也肯定知道了吧?呵呵

使用道具 举报

回复
论坛徽章:
520
奥运会纪念徽章:垒球
日期:2008-09-15 01:28:12生肖徽章2007版:鸡
日期:2008-11-17 23:40:58生肖徽章2007版:马
日期:2008-11-18 05:09:48数据库板块每日发贴之星
日期:2008-11-29 01:01:02数据库板块每日发贴之星
日期:2008-12-05 01:01:03生肖徽章2007版:虎
日期:2008-12-10 07:47:462009新春纪念徽章
日期:2009-01-04 14:52:28数据库板块每日发贴之星
日期:2009-02-08 01:01:03生肖徽章2007版:蛇
日期:2009-03-09 22:18:532009日食纪念
日期:2009-07-22 09:30:00
77#
发表于 2012-2-10 00:10 | 只看该作者
哈哈,野花的阴谋被你识破了。

使用道具 举报

回复
论坛徽章:
484
ITPUB北京香山2007年会纪念徽章
日期:2007-01-24 14:35:02ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24ITPUB北京2009年会纪念徽章
日期:2009-02-09 11:42:452010新春纪念徽章
日期:2010-03-01 11:04:552010数据库技术大会纪念徽章
日期:2010-05-13 10:04:272010系统架构师大会纪念
日期:2010-09-04 13:35:54ITPUB9周年纪念徽章
日期:2010-10-08 09:28:512011新春纪念徽章
日期:2011-02-18 11:43:32ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:54
78#
发表于 2012-2-10 01:07 | 只看该作者
newkid 发表于 2012-2-10 00:10
哈哈,野花的阴谋被你识破了。

没完全识破呀
某版本下是不用带空格也能识别为0.255的,记不清什么版本了

在发现我所说的两种不同表现时,我曾用过的数据库版本是8.1.5  8.1.6  8.1.7  9.2.0.1  9.2.0.4  9.2.0.8。

使用道具 举报

回复
论坛徽章:
16
数据库板块每日发贴之星
日期:2007-12-03 01:03:272010世博会纪念徽章
日期:2010-09-14 17:24:312010新春纪念徽章
日期:2010-03-01 11:20:05生肖徽章2007版:马
日期:2009-11-13 10:55:15参与WIN7挑战赛纪念
日期:2009-11-06 10:44:24CTO参与奖
日期:2009-03-23 11:00:18生肖徽章2007版:马
日期:2009-02-08 17:20:54生肖徽章2007版:兔
日期:2008-12-01 13:33:59生肖徽章2007版:马
日期:2008-10-31 19:01:49奥运会纪念徽章:赛艇
日期:2008-10-24 13:25:17
79#
发表于 2012-2-10 20:06 | 只看该作者
哈哈
不错

使用道具 举报

回复
论坛徽章:
7
授权会员
日期:2005-10-30 17:05:33会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB十周年纪念徽章
日期:2011-11-01 16:19:41鲜花蛋
日期:2012-07-16 15:24:59ITPUB 11周年纪念徽章
日期:2012-10-09 18:05:072013年新春福章
日期:2013-02-25 14:51:24
80#
发表于 2012-2-15 18:52 | 只看该作者
本帖最后由 yiwenvtech 于 2012-2-15 18:57 编辑

简单说几句
1.sql不是过程语言,仅是数据库操作命令集合。pl/sql增加了过程控制等编程语言特点(原型是PASCAL语言-最早面向对象的语言)
2.使用标准sql通常不会因为数据库升级而出错,有时使用pl/sql内置包在升级后由于包的改变可能导致需要修改原程序
3.什么时候使用cursor需要因情况而定,数据量大小、索引的使用、内存、存储等很多因素影响性能,不能简单说cursor不好。
  针对处理大数据量,还是建议使用cursor,并在处理了一部分数据(如1000条或5000条记后)及时提交有时会大大提高性能。
  其实任何时候处理数据时都是使用cursor的,只是sql语句一般使用的是隐性cursor,我们所说的cursor是显性定义的cursor而已。关键要看explain plan是否有效率。

另外,
oralce pl/sql可以调用java来做更多扩展,有时候使用文件处理方式会优过在数据库处理,比如先导出大量数据,使用文件处理方式处理数据后再导入数据库等。
oracle 10g,11g也提供了许多新特性,如分区表,materilize view,pivot查询等等...

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表