﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-chen4765654-随笔分类-Oracle</title><link>http://www.blogjava.net/chen4765654/category/54435.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 16 Dec 2014 17:23:25 GMT</lastBuildDate><pubDate>Tue, 16 Dec 2014 17:23:25 GMT</pubDate><ttl>60</ttl><item><title>ORACLE大数据量生成语句</title><link>http://www.blogjava.net/chen4765654/archive/2014/09/15/417939.html</link><dc:creator>紫色心情</dc:creator><author>紫色心情</author><pubDate>Mon, 15 Sep 2014 05:50:00 GMT</pubDate><guid>http://www.blogjava.net/chen4765654/archive/2014/09/15/417939.html</guid><wfw:comment>http://www.blogjava.net/chen4765654/comments/417939.html</wfw:comment><comments>http://www.blogjava.net/chen4765654/archive/2014/09/15/417939.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chen4765654/comments/commentRss/417939.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chen4765654/services/trackbacks/417939.html</trackback:ping><description><![CDATA[<div>为了更好的测试我们的系统在一定数据量下的运行情况，时常需要准备大量的测试数据。如果有灵活的方法可以使用，那就可以事半功倍了。</div><div>以下介绍如何在ORACLE数据库中进行大数据量的构造方法，数据量大小均为500万。</div><div></div><div>'''基本主键列'''</div><div>SELECT LEVEL AS ID</div><div>&nbsp; FROM DUAL</div><div>CONNECT BY LEVEL &lt;= 5000000</div><div></div><div>'''基本的单据列'''</div><div>SELECT 'SO20121123' || LPAD(LEVEL, 5, 0) AS ORDER_NO</div><div>&nbsp; FROM DUAL</div><div>CONNECT BY LEVEL &lt;= 5000000;</div><div></div><div>'''基本的日期列'''</div><div>SELECT TO_DATE(TRUNC(DBMS_RANDOM.VALUE(TO_NUMBER(TO_CHAR(SYSDATE, 'J')),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TO_NUMBER(TO_CHAR(SYSDATE, 'J')))),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'J') + DBMS_RANDOM.VALUE(1, 360000) / 3600 AS ENTRYDATE</div><div>&nbsp; FROM DUAL</div><div>CONNECT BY LEVEL &lt; 5000000;</div><div></div><div>'''特定时间范围内'''</div><div>SELECT TO_DATE(TRUNC(DBMS_RANDOM.VALUE(TO_NUMBER(TO_CHAR(SYSDATE - 10, 'J')),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TO_NUMBER(TO_CHAR(SYSDATE, 'J')))),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'J') + DBMS_RANDOM.VALUE(1, 360000) / 3600 / 24 AS ENTRYDATE</div><div>&nbsp; FROM DUAL</div><div>CONNECT BY LEVEL &lt; 5000000;</div><div></div><div>'''随机数据'''</div><div>SELECT DBMS_RANDOM.VALUE FROM DUAL CONNECT BY LEVEL &lt; 5000000;</div><div></div><div>'''随机数据范围'''</div><div>SELECT TRUNC(DBMS_RANDOM.VALUE(0, 100))</div><div>&nbsp; FROM DUAL</div><div>CONNECT BY LEVEL &lt; 5000000;</div><div></div><div>'''随机字符串'''</div><div>SELECT DBMS_RANDOM.STRING('A', 8) FROM DUAL CONNECT BY LEVEL &lt; 5000000;</div><div></div><div>'''复杂组合（订单）'''</div><div>SELECT 'P-' ||</div><div>&nbsp; &nbsp; &nbsp; &nbsp;TO_CHAR((TO_DATE(TRUNC(DBMS_RANDOM.VALUE(TO_NUMBER(TO_CHAR(SYSDATE - 30,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'J')),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TO_NUMBER(TO_CHAR(SYSDATE,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'J')))),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'J') + DBMS_RANDOM.VALUE(1, 360000) / 3600 / 24),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'YYMMDD') || '-' ||</div><div>&nbsp; &nbsp; &nbsp; &nbsp;LPAD(TRUNC(DBMS_RANDOM.VALUE(1, 100)), 5, '0') AS 订单号,</div><div>&nbsp; &nbsp; &nbsp; &nbsp;'一般采购' AS 订单类型,</div><div>&nbsp; &nbsp; &nbsp; &nbsp;'SO20121123' || LPAD(LEVEL, 4, 0) AS 外部订单号,</div><div>&nbsp; &nbsp; &nbsp; &nbsp;'admin' AS 变更人,</div><div>&nbsp; &nbsp; &nbsp; &nbsp;TO_DATE(TRUNC(DBMS_RANDOM.VALUE(TO_NUMBER(TO_CHAR(SYSDATE, 'J')),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TO_NUMBER(TO_CHAR(SYSDATE, 'J')))),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'J') + DBMS_RANDOM.VALUE(1, 360000) / 3600 AS 更新时间</div><div>&nbsp; FROM DUAL</div><div>CONNECT BY LEVEL &lt; 5000000;</div><div></div><div>'''加入随机用户或者字符'''</div><div>SELECT 'P-' ||</div><div>&nbsp; &nbsp; &nbsp; &nbsp;TO_CHAR((TO_DATE(TRUNC(DBMS_RANDOM.VALUE(TO_NUMBER(TO_CHAR(SYSDATE - 30,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'J')),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TO_NUMBER(TO_CHAR(SYSDATE,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'J')))),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'J') + DBMS_RANDOM.VALUE(1, 360000) / 3600 / 24),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'YYMMDD') || '-' ||</div><div>&nbsp; &nbsp; &nbsp; &nbsp;LPAD(TRUNC(DBMS_RANDOM.VALUE(1, 100)), 5, '0') AS 订单号,</div><div>&nbsp; &nbsp; &nbsp; &nbsp;'一般采购' AS 订单类型,</div><div>&nbsp; &nbsp; &nbsp; &nbsp;CASE TRUNC(DBMS_RANDOM.VALUE(0, 2))</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN 0 THEN</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ('SO20121123' || LPAD(LEVEL, 4, 0))</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ELSE</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ('')</div><div>&nbsp; &nbsp; &nbsp; &nbsp;END AS 外部订单号,</div><div>&nbsp; &nbsp; &nbsp; &nbsp;CASE TRUNC(DBMS_RANDOM.VALUE(0, 3))</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN 0 THEN</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'admin'</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN 1 THEN</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'steven'</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ELSE</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'joseph'</div><div>&nbsp; &nbsp; &nbsp; &nbsp;END AS 变更人,</div><div>&nbsp; &nbsp; &nbsp; &nbsp;TO_DATE(TRUNC(DBMS_RANDOM.VALUE(TO_NUMBER(TO_CHAR(SYSDATE, 'J')),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TO_NUMBER(TO_CHAR(SYSDATE, 'J')))),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'J') + DBMS_RANDOM.VALUE(1, 360000) / 3600 AS 更新时间</div><div>&nbsp; FROM DUAL</div><div>CONNECT BY LEVEL &lt; 5000000;</div><div></div><img src ="http://www.blogjava.net/chen4765654/aggbug/417939.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chen4765654/" target="_blank">紫色心情</a> 2014-09-15 13:50 <a href="http://www.blogjava.net/chen4765654/archive/2014/09/15/417939.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle常规表优化</title><link>http://www.blogjava.net/chen4765654/archive/2014/07/29/416292.html</link><dc:creator>紫色心情</dc:creator><author>紫色心情</author><pubDate>Tue, 29 Jul 2014 07:20:00 GMT</pubDate><guid>http://www.blogjava.net/chen4765654/archive/2014/07/29/416292.html</guid><wfw:comment>http://www.blogjava.net/chen4765654/comments/416292.html</wfw:comment><comments>http://www.blogjava.net/chen4765654/archive/2014/07/29/416292.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chen4765654/comments/commentRss/416292.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chen4765654/services/trackbacks/416292.html</trackback:ping><description><![CDATA[<div>--释放空间</div><div>alter table tpl_order shrink space;</div><div></div><div>--重建索引</div><div>Alter index IDX_TPL_ORDER_1 rebuild;</div><div></div><div>--重新分析表</div><div>analyze table &nbsp;tpl_order compute statistics;&nbsp;</div><img src ="http://www.blogjava.net/chen4765654/aggbug/416292.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chen4765654/" target="_blank">紫色心情</a> 2014-07-29 15:20 <a href="http://www.blogjava.net/chen4765654/archive/2014/07/29/416292.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>复杂关联查询物化视图</title><link>http://www.blogjava.net/chen4765654/archive/2014/07/17/415931.html</link><dc:creator>紫色心情</dc:creator><author>紫色心情</author><pubDate>Thu, 17 Jul 2014 03:21:00 GMT</pubDate><guid>http://www.blogjava.net/chen4765654/archive/2014/07/17/415931.html</guid><wfw:comment>http://www.blogjava.net/chen4765654/comments/415931.html</wfw:comment><comments>http://www.blogjava.net/chen4765654/archive/2014/07/17/415931.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chen4765654/comments/commentRss/415931.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chen4765654/services/trackbacks/415931.html</trackback:ping><description><![CDATA[实现目标：查询子表TEST_B的STATUS为1的记录所关联的父表的CODE<br /><br /><br />
<p><span style="color: red">1、现在子表建立聚合物化视图</span><br />CREATE MATERIALIZED VIEW LOG on test_b WITH rowid ,SEQUENCE (status,p_id) INCLUDING NEW VALUES;</p>
<p><br />create materialized view mv_test_b&nbsp;&nbsp; <br />&nbsp;BUILD immediate<br />&nbsp;refresh fast on demand&nbsp;&nbsp; <br />&nbsp;start with sysdate next sysdate+1/1440 with rowid&nbsp;&nbsp; <br />&nbsp;as&nbsp; <br />&nbsp;select a.p_id,COUNT(*) from test_b a where a.status=1 group by a.p_id; <br />&nbsp;<br />&nbsp;<br /><span style="color: red">2、在子表聚合物化视图上建立日志</span><br />CREATE MATERIALIZED VIEW LOG on mv_test_b WITH rowid ,SEQUENCE (p_id) INCLUDING NEW VALUES;</p>
<p><br /><span style="color: red">3、在主表建立关联物化视图和日志</span><br />CREATE MATERIALIZED VIEW LOG on test_a WITH rowid ,SEQUENCE (code) INCLUDING NEW VALUES;</p>
<p>create materialized view mv_test_code&nbsp;&nbsp; <br />&nbsp;BUILD immediate<br />&nbsp;refresh fast on demand&nbsp;&nbsp; <br />&nbsp;start with sysdate next sysdate+1/1440 with rowid&nbsp;&nbsp; <br />&nbsp;as&nbsp; <br />&nbsp;select&nbsp; b.code,a.rowid aid,b.rowid bid from mv_test_b a, test_a b where a.p_id=b.id;</p><img src ="http://www.blogjava.net/chen4765654/aggbug/415931.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chen4765654/" target="_blank">紫色心情</a> 2014-07-17 11:21 <a href="http://www.blogjava.net/chen4765654/archive/2014/07/17/415931.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>