<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.5" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: random statements</title>
	<link>http://laurentschneider.com/wordpress/2007/11/random-statements.html</link>
	<description>Oracle Certified Master</description>
	<pubDate>Sun, 07 Sep 2008 07:06:25 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>

	<item>
		<title>by: I&#8217;m just a simple DBA on a complex production system</title>
		<link>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5465</link>
		<pubDate>Mon, 26 Nov 2007 07:50:12 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5465</guid>
					<description>[...] ** This post has been partially inspired by this one.   Posted in plsql &#124; [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] ** This post has been partially inspired by this one.   Posted in plsql | [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5442</link>
		<pubDate>Sat, 24 Nov 2007 20:44:41 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5442</guid>
					<description>&lt;i&gt;why that way&lt;/i&gt;
because you have no subquery and no plsql
because Model is the most elegant solution I found

Well, 100000 over 3 years, that's enough for a whole DBA team :mrgreen:</description>
		<content:encoded><![CDATA[<p><i>why that way</i><br />
because you have no subquery and no plsql<br />
because Model is the most elegant solution I found</p>
<p>Well, 100000 over 3 years, that&#8217;s enough for a whole DBA team  <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Brian Ballsun-Stanton</title>
		<link>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5441</link>
		<pubDate>Sat, 24 Nov 2007 20:23:27 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5441</guid>
					<description>On a completely random tangent, I love your human-checking. It's quite a bit better than a bloody image.

100,000 cases over 3 years :) Since the date dimension is by weekday only, that's *quite a few* cases per day. Aren't all DBAs alcoholics? :)

With respect to your iterate function, it's a neat way to do it, but I'm not sure why you chose to do it that way. Was it a "look what I can do" hack? I'd be interested in seeing the explain plan output from this. If your reference tables are only full-table-scanned once, this might be a really shiny way for me to generate data.</description>
		<content:encoded><![CDATA[<p>On a completely random tangent, I love your human-checking. It&#8217;s quite a bit better than a bloody image.</p>
<p>100,000 cases over 3 years <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Since the date dimension is by weekday only, that&#8217;s *quite a few* cases per day. Aren&#8217;t all DBAs alcoholics? <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>With respect to your iterate function, it&#8217;s a neat way to do it, but I&#8217;m not sure why you chose to do it that way. Was it a &#8220;look what I can do&#8221; hack? I&#8217;d be interested in seeing the explain plan output from this. If your reference tables are only full-table-scanned once, this might be a really shiny way for me to generate data.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5440</link>
		<pubDate>Sat, 24 Nov 2007 19:23:26 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5440</guid>
					<description>well, two is only an example, but you could have 200 %E if you want

About model :

I look (ITERATE) until the is no more % in the string (UNTIL LIKE). 

Each loop, I replace the first % (the second SUBSTR) with a value. i check what kind of % it is (the second DECODE), if it is a %E, i then use the reference model (REFERENCE EMP ON) and a random value (DBMS_RANDOM) as a dimension (ROWNUM R).

And then I loop for next value. It means, my str[1]= is executed as many time as you have % in the string.

I hope it puts some light 8-)

10'000 bottles over 3 years, it is about 9 bottles a day, you must be very thirsty :lol:</description>
		<content:encoded><![CDATA[<p>well, two is only an example, but you could have 200 %E if you want</p>
<p>About model :</p>
<p>I look (ITERATE) until the is no more % in the string (UNTIL LIKE). </p>
<p>Each loop, I replace the first % (the second SUBSTR) with a value. i check what kind of % it is (the second DECODE), if it is a %E, i then use the reference model (REFERENCE EMP ON) and a random value (DBMS_RANDOM) as a dimension (ROWNUM R).</p>
<p>And then I loop for next value. It means, my str[1]= is executed as many time as you have % in the string.</p>
<p>I hope it puts some light <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_cool.gif' alt='8-)' class='wp-smiley' /> </p>
<p>10&#8242;000 bottles over 3 years, it is about 9 bottles a day, you must be very thirsty  <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_lol.gif' alt=':lol:' class='wp-smiley' />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Brian Ballsun-Stanton</title>
		<link>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5439</link>
		<pubDate>Sat, 24 Nov 2007 18:42:30 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5439</guid>
					<description>Hrmm, that makes it more interesting. Are we allowed to select against a precomputed materialized view?

(The replace is necessary insofar as one can select and populate random phrase. But the dual name thing requires two hits to the employees table, doesn't it?)

Also, could you explain your model code? There are an impressive amount of parens.</description>
		<content:encoded><![CDATA[<p>Hrmm, that makes it more interesting. Are we allowed to select against a precomputed materialized view?</p>
<p>(The replace is necessary insofar as one can select and populate random phrase. But the dual name thing requires two hits to the employees table, doesn&#8217;t it?)</p>
<p>Also, could you explain your model code? There are an impressive amount of parens.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5438</link>
		<pubDate>Sat, 24 Nov 2007 18:34:40 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5438</guid>
					<description>Brian, the objective is of course to select the table only once and to later substitute, according to the various %. The string '%E and %E travel to %L' could be a bind variable, for example</description>
		<content:encoded><![CDATA[<p>Brian, the objective is of course to select the table only once and to later substitute, according to the various %. The string &#8216;%E and %E travel to %L&#8217; could be a bind variable, for example
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Brian Ballsun-Stanton</title>
		<link>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5437</link>
		<pubDate>Sat, 24 Nov 2007 17:08:53 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5437</guid>
					<description>Whoops. Forgot the subquery. Yea, the wrapper is important. (I was rather tired last night, which isn't a proper excuse. )

For employee name... lets see here

select text from (
  select a.Name &#124;&#124;' and '&#124;&#124; b.name &#124;&#124; ' travel to ' &#124;&#124; location as text, 
           rownum as rnum
  from name a, name b, location
  where a.name != b.name
  order by DBMS_RANDOM.value() ) c
where rnum = 1;

should work. However, I'll actually be testing it later today, since my previous post was full of errors...


10,000 bottles of wine, 15,000 cases, and 100,000 orders over 3 years. It makes for a fairly compact data warehouse. (Versus last year's which, one of our students computed, had a business one third the size of wal-mart's.</description>
		<content:encoded><![CDATA[<p>Whoops. Forgot the subquery. Yea, the wrapper is important. (I was rather tired last night, which isn&#8217;t a proper excuse. )</p>
<p>For employee name&#8230; lets see here</p>
<p>select text from (<br />
  select a.Name ||&#8217; and &#8216;|| b.name || &#8216; travel to &#8216; || location as text,<br />
           rownum as rnum<br />
  from name a, name b, location<br />
  where a.name != b.name<br />
  order by DBMS_RANDOM.value() ) c<br />
where rnum = 1;</p>
<p>should work. However, I&#8217;ll actually be testing it later today, since my previous post was full of errors&#8230;</p>
<p>10,000 bottles of wine, 15,000 cases, and 100,000 orders over 3 years. It makes for a fairly compact data warehouse. (Versus last year&#8217;s which, one of our students computed, had a business one third the size of wal-mart&#8217;s.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5435</link>
		<pubDate>Sat, 24 Nov 2007 08:18:13 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5435</guid>
					<description>&lt;code&gt;select foo
from bar
where rownum = 1
order by DBMS_RANDOM.value();&lt;/code&gt;
this does not generate random values. you need subquery because the order by is executed after rownum=1
&lt;code&gt;
Select regexp_replace('%E and %E travel to %L',
  '%E',(select ename  from (
    select ename from emp order by dbms_random.value(0,1)) 
    where rownum=1)))
from t
&lt;/code&gt;
is also not possible, because all %E will be replaced by the same string... 

Wow, 10000 bottle of wine, that is quite a lot 8-)</description>
		<content:encoded><![CDATA[<p><pre><code>select foo
from bar
where rownum = 1
order by DBMS_RANDOM.value();</code></pre><br />
this does not generate random values. you need subquery because the order by is executed after rownum=1<br />
<pre><code>
Select regexp_replace(&#039;%E and %E travel to %L&#039;,
&nbsp;&nbsp;&#039;%E&#039;,(select ename&nbsp;&nbsp;from (
&nbsp;&nbsp;&nbsp;&nbsp;select ename from emp order by dbms_random.value(0,1)) 
&nbsp;&nbsp;&nbsp;&nbsp;where rownum=1)))
from t
</code></pre><br />
is also not possible, because all %E will be replaced by the same string&#8230; </p>
<p>Wow, 10000 bottle of wine, that is quite a lot <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_cool.gif' alt='8-)' class='wp-smiley' />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Brian Ballsun-Stanton</title>
		<link>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5433</link>
		<pubDate>Sat, 24 Nov 2007 02:20:23 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5433</guid>
					<description>It's waaaay easier to do random tuples.

select foo
from bar
where rownum = 1
order by DBMS_RANDOM.value();


Reading over the random excuse generator more closely, you folks are looking for the functional equivalent of good, random, data. (Since I make around a gig of that a quarter for RIT... I'm good at this)

The trick to good random data that doesn't require a lot of PL is the ugly cartesian product.


Select regexReplacementThatImTooTiredToLookUp(prefixText &#124;&#124; midText &#124;&#124; postText)
from pre, mid, post
where rownum = 1
order by DBMS_RANDOM.value();

This is how, for example, one creates 10,000 bottles of wine from two 50 entry lists ganked from the wikipedia.</description>
		<content:encoded><![CDATA[<p>It&#8217;s waaaay easier to do random tuples.</p>
<p>select foo<br />
from bar<br />
where rownum = 1<br />
order by DBMS_RANDOM.value();</p>
<p>Reading over the random excuse generator more closely, you folks are looking for the functional equivalent of good, random, data. (Since I make around a gig of that a quarter for RIT&#8230; I&#8217;m good at this)</p>
<p>The trick to good random data that doesn&#8217;t require a lot of PL is the ugly cartesian product.</p>
<p>Select regexReplacementThatImTooTiredToLookUp(prefixText || midText || postText)<br />
from pre, mid, post<br />
where rownum = 1<br />
order by DBMS_RANDOM.value();</p>
<p>This is how, for example, one creates 10,000 bottles of wine from two 50 entry lists ganked from the wikipedia.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5429</link>
		<pubDate>Fri, 23 Nov 2007 13:13:32 +0000</pubDate>
		<guid>http://laurentschneider.com/wordpress/2007/11/random-statements.html#comment-5429</guid>
					<description>the algorythm is straightforward. 

In the format string &lt;code&gt;'%E / %N / %L'&lt;/code&gt; I replace the %E, %N and %L by a random employee, a random number of employees (from 0 to count) and a random location, respectively.

So I look until there is no more % in the string, and one by one I replace each string containing a % with [begin][substitution][end], where substitution is a value of a reference model where the dimension is a random value (pointing to a random row number). 

I apologize for the lack of readability of the substr and instr due to the very short line of the wordpress template, which make proper indenting hard to implement

The point of using model and not REGEXP_REPLACE is to have %E replaced by different values (accidentally it will be the same) within the same string. 

Here I avoid using PL/SQL, which is the natural way to translate T-SQL, in order to demonstrate the power of MODEL. 

Those who attended my unconference at OpenWorld know what it is about 8-)</description>
		<content:encoded><![CDATA[<p>the algorythm is straightforward. </p>
<p>In the format string <code>&#039;%E / %N / %L&#039;</code> I replace the %E, %N and %L by a random employee, a random number of employees (from 0 to count) and a random location, respectively.</p>
<p>So I look until there is no more % in the string, and one by one I replace each string containing a % with [begin][substitution][end], where substitution is a value of a reference model where the dimension is a random value (pointing to a random row number). </p>
<p>I apologize for the lack of readability of the substr and instr due to the very short line of the wordpress template, which make proper indenting hard to implement</p>
<p>The point of using model and not REGEXP_REPLACE is to have %E replaced by different values (accidentally it will be the same) within the same string. </p>
<p>Here I avoid using PL/SQL, which is the natural way to translate T-SQL, in order to demonstrate the power of MODEL. </p>
<p>Those who attended my unconference at OpenWorld know what it is about <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_cool.gif' alt='8-)' class='wp-smiley' />
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
