<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Laurent Schneider</title>
	<atom:link href="http://laurentschneider.com/rss2" rel="self" type="application/rss+xml" />
	<link>http://laurentschneider.com</link>
	<description>Oracle Certified Master</description>
	<pubDate>Fri, 03 Jul 2009 12:21:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
	<language>en</language>
			<item>
		<title>select from column-separated list</title>
		<link>http://laurentschneider.com/wordpress/2009/07/select-from-column-separated-list.html</link>
		<comments>http://laurentschneider.com/wordpress/2009/07/select-from-column-separated-list.html#comments</comments>
		<pubDate>Fri, 03 Jul 2009 12:16:10 +0000</pubDate>
		<dc:creator>Laurent Schneider</dc:creator>
		
		<category><![CDATA[11g]]></category>

		<category><![CDATA[sql]]></category>

		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://laurentschneider.com/?p=564</guid>
		<description><![CDATA[This is asked over and over in the forums, but why not proposing an 11g solution here  
create table t(description varchar2(12) primary key, 
&#160;&#160;numbers varchar2(4000));
insert into t(description, numbers) values (&#039;PRIME&#039;,&#039;2,3,5,7&#039;);
insert into t(description, numbers) values (&#039;ODD&#039;,&#039;1,3,5,7,9&#039;);
commit;


DESCRIPTION
NUMBERS


PRIME
2,3,5,7


ODD
1,3,5,7,9


Now I want to unpivot numbers in rows

select description,(column_value).getnumberval()&#160;&#160;
from t,xmltable(numbers)



DESCRIPTION
(COLUMN_VALUE).GETNUMBERVAL()


PRIME
2


PRIME
3


PRIME
5


PRIME
7


ODD
1


ODD
3


ODD
5


ODD
7


ODD
9


It is that simple  
Works also with strings :

select (column_value).getstringval() [...]]]></description>
			<content:encoded><![CDATA[<p>This is asked over and over in the forums, but why not proposing an 11g solution here <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><pre><code>create table t(description varchar2(12) primary key, 
&nbsp;&nbsp;numbers varchar2(4000));
insert into t(description, numbers) values (&#039;PRIME&#039;,&#039;2,3,5,7&#039;);
insert into t(description, numbers) values (&#039;ODD&#039;,&#039;1,3,5,7,9&#039;);
commit;</code></pre></p>
<table border=0>
<tr>
<th align="left" bgcolor="#C0C0C0" bordercolor="#FFFFFF">DESCRIPTION</th>
<th align="left" bgcolor="#C0C0C0" bordercolor="#FFFFFF">NUMBERS</th>
</tr>
<tr>
<td>PRIME</td>
<td>2,3,5,7</td>
</tr>
<tr>
<td>ODD</td>
<td>1,3,5,7,9</td>
</tr>
</table>
<p>Now I want to unpivot numbers in rows</p>
<p><pre><code>
select description,(column_value).getnumberval()&nbsp;&nbsp;
from t,xmltable(numbers)
</code></pre></p>
<table border=0>
<tr>
<th align="left" bgcolor="#C0C0C0" bordercolor="#FFFFFF">DESCRIPTION</th>
<th align="left" bgcolor="#C0C0C0" bordercolor="#FFFFFF">(COLUMN_VALUE).GETNUMBERVAL()</th>
</tr>
<tr>
<td>PRIME</td>
<td>2</td>
</tr>
<tr>
<td>PRIME</td>
<td>3</td>
</tr>
<tr>
<td>PRIME</td>
<td>5</td>
</tr>
<tr>
<td>PRIME</td>
<td>7</td>
</tr>
<tr>
<td>ODD</td>
<td>1</td>
</tr>
<tr>
<td>ODD</td>
<td>3</td>
</tr>
<tr>
<td>ODD</td>
<td>5</td>
</tr>
<tr>
<td>ODD</td>
<td>7</td>
</tr>
<tr>
<td>ODD</td>
<td>9</td>
</tr>
</table>
<p>It is that simple <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Works also with strings :<br />
<pre><code>
select (column_value).getstringval() 
from xmltable(&#039;&quot;a&quot;,&quot;b&quot;,&quot;c&quot;&#039;);
</code></pre></p>
<table border=0>
<tr>
<th align="left" bgcolor="#C0C0C0" bordercolor="#FFFFFF">(COLUMN_VALUE).GETSTRINGVAL()</th>
</tr>
<tr>
<td>a</td>
</tr>
<tr>
<td>b</td>
</tr>
<tr>
<td>c</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://laurentschneider.com/wordpress/2009/07/select-from-column-separated-list.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>to ftp or to sftp</title>
		<link>http://laurentschneider.com/wordpress/2009/07/to-ftp-or-to-sftp.html</link>
		<comments>http://laurentschneider.com/wordpress/2009/07/to-ftp-or-to-sftp.html#comments</comments>
		<pubDate>Wed, 01 Jul 2009 15:25:25 +0000</pubDate>
		<dc:creator>Laurent Schneider</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<category><![CDATA[security]]></category>

		<category><![CDATA[unix]]></category>

		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://laurentschneider.com/?p=558</guid>
		<description><![CDATA[Ftp is seen as an old-time unsecure protocol. Many shops nowadays have switched or are switching to sftp. I will try to point out some differences :
Compatibility: none. the protocol is completly different. Multiple graphical clients however do support both mode. But the basic &#8220;ftp&#8221; client will not work with sftp.
Ascii mode: only in ftp. [...]]]></description>
			<content:encoded><![CDATA[<p>Ftp is seen as an old-time unsecure protocol. Many shops nowadays have switched or are switching to sftp. I will try to point out some differences :</p>
<p>Compatibility: none. the protocol is completly different. Multiple graphical clients however do support both mode. But the basic &#8220;ftp&#8221; client will not work with sftp.</p>
<p>Ascii mode: only in ftp. In sftp, it is always binary so there will be no conversion. Also no blocksize, recordlength or primary/secondary space for your OS/390 connections.</p>
<p>Interactive mode: similar. you enter your username and password, do <i>cd</i>, <i>put</i> and <i>get</i>. But to quit, <i>by</i> will not work in sftp <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> Use <i>quit</i> or <i>exit</i> instead</p>
<p>Batch mode: different. Most probably you will end up setting a private/public key infrastructure for your ssh connection and use scp (secure copy). If you are using a ssh client like putty, it is possible to do something like <b>pscp -l user -pw password server:file . </b></p>
<p>Security: sftp is secure, ftp is not.</p>
<p>Speed: ftp is fast, sftp is slow <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> !</p>
<p>Oh NOOOOOOO!!!!!  What&#8217;s the point is bringing something new if it is slower !!!</p>
<p>Ok, let&#8217;s try to download a 100m file:<br />
<pre><code>$ time (echo &quot;open dbsrv01
user oracle secret
bin
get 100m&quot;|ftp -n )

real&nbsp;&nbsp;&nbsp;&nbsp;0m24.673s
user&nbsp;&nbsp;&nbsp;&nbsp;0m0.030s
sys&nbsp;&nbsp;&nbsp;&nbsp; 0m0.016s
$ time scp -q oracle@dbsrv01:100m .

real&nbsp;&nbsp;&nbsp;&nbsp;1m46.978s
user&nbsp;&nbsp;&nbsp;&nbsp;0m0.108s
sys&nbsp;&nbsp;&nbsp;&nbsp; 0m0.202s</code></pre></p>
<p>it is about 4x slower! Is there anything we could do about it? </p>
<p>Well, maybe : </p>
<p><pre><code>$ time scp -q -o Compression=yes oracle@dbsrv01:100m .

real&nbsp;&nbsp;&nbsp;&nbsp;0m18.634s
user&nbsp;&nbsp;&nbsp;&nbsp;0m0.748s
sys&nbsp;&nbsp;&nbsp;&nbsp; 0m0.452s</code></pre></p>
<p>ssh/scp/sftp have a compression mode. If you are transferring your large files across a slow network, this may be an interesting option to consider !</p>
<p>OpenSSH homepage : <a href="http://www.openssh.org<br />
">http://www.openssh.org</a></p>
]]></content:encoded>
			<wfw:commentRss>http://laurentschneider.com/wordpress/2009/07/to-ftp-or-to-sftp.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>to_number(to_char(:n))</title>
		<link>http://laurentschneider.com/wordpress/2009/06/to_numberto_charn.html</link>
		<comments>http://laurentschneider.com/wordpress/2009/06/to_numberto_charn.html#comments</comments>
		<pubDate>Tue, 09 Jun 2009 10:55:17 +0000</pubDate>
		<dc:creator>Laurent Schneider</dc:creator>
		
		<category><![CDATA[sql]]></category>

		<category><![CDATA[infinity]]></category>

		<guid isPermaLink="false">http://laurentschneider.com/?p=555</guid>
		<description><![CDATA[Is it safe to do a TO_NUMBER(TO_CHAR(:n)) ?
var n number
exec :n :=&#160;&#160;9.9999999999999999999999999999999999e125
select to_number(to_char(:n)) from dual;
ORA-01722: invalid number
Why?
SQL Reference
If a positive NUMBER value is extremely large and cannot be represented in the specified format, then the infinity sign (~) replaces the value
select to_char(:n) from dual;
TO_CHAR(:N)
--------------
~
I wrote more about infinity here
]]></description>
			<content:encoded><![CDATA[<p>Is it safe to do a TO_NUMBER(TO_CHAR(:n)) ?</p>
<p><pre><code>var n number
exec :n :=&nbsp;&nbsp;9.9999999999999999999999999999999999e125
select to_number(to_char(:n)) from dual;
ORA-01722: invalid number</code></pre></p>
<p>Why?<br />
<a href="http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/sql_elements004.htm">SQL Reference</a><br />
<i>If a positive NUMBER value is extremely large and cannot be represented in the specified format, then the infinity sign (~) replaces the value</i></p>
<p><pre><code>select to_char(:n) from dual;
TO_CHAR(:N)
--------------
~</code></pre></p>
<p>I wrote more about infinity <a href="http://laurentschneider.com/wordpress/2007/08/positive-infinity.html">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://laurentschneider.com/wordpress/2009/06/to_numberto_charn.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>committing transaction</title>
		<link>http://laurentschneider.com/wordpress/2009/06/committing-transaction.html</link>
		<comments>http://laurentschneider.com/wordpress/2009/06/committing-transaction.html#comments</comments>
		<pubDate>Thu, 04 Jun 2009 10:19:09 +0000</pubDate>
		<dc:creator>Laurent Schneider</dc:creator>
		
		<category><![CDATA[sql]]></category>

		<category><![CDATA[commit]]></category>

		<guid isPermaLink="false">http://laurentschneider.com/?p=551</guid>
		<description><![CDATA[When and how do you commit a transaction?
SQL&#62; insert into lsc_t(x) values(1);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ... (1) not committed
SQL&#62; commit;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ... (1) committed

SQL&#62; insert into lsc_t(x) values(2);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ... (2) not committed
SQL&#62; alter table lsc_t disable primary key;&#160;&#160;... (2) committed

SQL&#62; set autocommit ON
SQL&#62; insert into lsc_t(x) values(3);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ... (3) committed
SQL&#62; set autocommit OFF

SQL&#62; insert into lsc_t(x) values(4);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ... (4) [...]]]></description>
			<content:encoded><![CDATA[<p>When and how do you commit a transaction?<br />
<pre><code>SQL&gt; insert into lsc_t(x) values(1);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... (1) not committed
SQL&gt; commit;&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; ... (1) committed

SQL&gt; insert into lsc_t(x) values(2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... (2) not committed
SQL&gt; alter table lsc_t disable primary key;&nbsp;&nbsp;... (2) committed

SQL&gt; set autocommit ON
SQL&gt; insert into lsc_t(x) values(3);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... (3) committed
SQL&gt; set autocommit OFF

SQL&gt; insert into lsc_t(x) values(4);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... (4) not committed
SQL&gt; disc&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;&nbsp;&nbsp;&nbsp;... (4) committed
</code></pre></p>
<p>Row 1 is committed after the <i>commit</i> keyword. </p>
<p>Row 2 is implicitely committed <s>after</s> <b>before</b> the <i>alter table</i> ddl statement. </p>
<p>Row 3 is autocommitted. Autocommit exists in sqlplus, but is more often seen in stateless applications (for instance a web application). </p>
<p>Row 4 is committed after a successfull disconnection.</p>
<p>But what appends if you kill your current session?</p>
<p><pre><code>
SQL&gt; insert into lsc_t(x) values (5);

1 row created.

SQL&gt; !ps
&nbsp;&nbsp; PID TTY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIME CMD
 13903 pts/33&nbsp;&nbsp; 0:00 ksh
 22384 pts/33&nbsp;&nbsp; 0:00 sqlplus

SQL&gt; !kill 22384
Terminated
</code></pre><br />
The row 5 is not commited</p>
<p>Ref: <a href="http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/transact.htm#i8072">Overview of Transaction Management</a><br />
<i><br />
A transaction ends when any of the following occurs:<br />
- A user issues a COMMIT or ROLLBACK statement without a SAVEPOINT clause.<br />
- A user runs a DDL statement such as CREATE, DROP, RENAME, or ALTER (*).<br />
If the current transaction contains any DML statements, Oracle Database<br />
first commits the transaction, and then runs and commits the DDL statement<br />
as a new, single statement transaction.<br />
- A user disconnects from Oracle Database. The current transaction is committed.<br />
- A user process terminates abnormally. The current transaction is rolled back.<br />
</i><br />
(*) but not <i>ALTER SESSION</i> &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://laurentschneider.com/wordpress/2009/06/committing-transaction.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>CONNECT BY NOCYCLE</title>
		<link>http://laurentschneider.com/wordpress/2009/05/connect-by-nocycle.html</link>
		<comments>http://laurentschneider.com/wordpress/2009/05/connect-by-nocycle.html#comments</comments>
		<pubDate>Mon, 25 May 2009 15:45:43 +0000</pubDate>
		<dc:creator>Laurent Schneider</dc:creator>
		
		<category><![CDATA[sql]]></category>

		<category><![CDATA[NOCYCLE]]></category>

		<guid isPermaLink="false">http://laurentschneider.com/?p=548</guid>
		<description><![CDATA[the idea of this post was largely inspired by nuke_y on developpez.net (in French)
I will try to rephrase it in a hierarchical way.
Let&#8217;s take all managers of Adams in EMP :
SELECT&#160;&#160;&#160;&#160; empno, ename, mgr
&#160;&#160;&#160;&#160;&#160;&#160;FROM emp
CONNECT BY NOCYCLE PRIOR mgr = empno
START WITH ename = &#039;ADAMS&#039;;
&#160;&#160;&#160;&#160; EMPNO ENAME&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MGR
---------- ---------- ----------
&#160;&#160;&#160;&#160;&#160;&#160;7876 ADAMS&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7788
&#160;&#160;&#160;&#160;&#160;&#160;7788 SCOTT&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7566
&#160;&#160;&#160;&#160;&#160;&#160;7566 JONES&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7839
&#160;&#160;&#160;&#160;&#160;&#160;7839 KING&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
So [...]]]></description>
			<content:encoded><![CDATA[<p>the idea of this post was largely inspired by nuke_y on <a href="http://www.developpez.net/forums/d742374/bases-donnees/oracle/sql/10g-bug-connect-by-nocycle-requete-hierarchique/">developpez.net</a> (in French)</p>
<p>I will try to rephrase it in a hierarchical way.</p>
<p>Let&#8217;s take all managers of Adams in EMP :<br />
<pre><code>SELECT&nbsp;&nbsp;&nbsp;&nbsp; empno, ename, mgr
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM emp
CONNECT BY NOCYCLE PRIOR mgr = empno
START WITH ename = &#039;ADAMS&#039;;
&nbsp;&nbsp;&nbsp;&nbsp; EMPNO ENAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MGR
---------- ---------- ----------
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7876 ADAMS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7788
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7788 SCOTT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7566
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7566 JONES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7839
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7839 KING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></pre></p>
<p>So far so good. Let&#8217;s imagine SCOTT has two managers, JONES and PAUL.</p>
<p><pre><code>create table lsc_t AS
&nbsp;&nbsp;&nbsp;&nbsp; (SELECT ename, empno, mgr
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM emp
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UNION ALL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SELECT &#039;SCOTT&#039;, 7788, 9999
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM DUAL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UNION ALL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SELECT &#039;PAUL&#039;, 9999, NULL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM DUAL);
SELECT&nbsp;&nbsp;&nbsp;&nbsp; empno, ename, mgr
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM lsc_t
CONNECT BY NOCYCLE PRIOR mgr = empno
START WITH ename = &#039;ADAMS&#039;;
&nbsp;&nbsp;&nbsp;&nbsp; EMPNO ENAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MGR
---------- ---------- ----------
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7876 ADAMS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7788
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7788 SCOTT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7566
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7566 JONES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7839
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7839 KING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7788 SCOTT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;9999
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;9999 PAUL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></pre></p>
<p>EMP is not supposed to allow this (primary key on empno), so I created a table LSC_T.</p>
<p>So far still fine, Paul is in my list of managers.</p>
<p>Let&#8217;s imagine Scott is the manager of Paul. In 9i and below, this would result in an <i>ORA-0146 CONNECT BY loop in user data</i>, but in 10g, and according to <a href="http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/queries003.htm">the doc</a> <i>The NOCYCLE parameter instructs Oracle Database to return rows from a query even if a CONNECT BY loop exists in the data</i>. </p>
<p>Should I try ???</p>
<p><pre><code>UPDATE lsc_t
&nbsp;&nbsp; SET mgr = 7788
 WHERE ename = &#039;PAUL&#039;;
COMMIT ;
SELECT&nbsp;&nbsp;&nbsp;&nbsp; empno, ename, mgr
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM lsc_t
CONNECT BY NOCYCLE PRIOR mgr = empno
START WITH ename = &#039;ADAMS&#039;;
&nbsp;&nbsp;&nbsp;&nbsp; EMPNO ENAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MGR
---------- ---------- ----------
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7876 ADAMS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7788
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7788 SCOTT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7566
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7566 JONES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7839
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7839 KING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7788 SCOTT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;9999
</code></pre></p>
<p>Due to a loop in user data, PAUL is no longer returned. I have no explanation so far.</p>
]]></content:encoded>
			<wfw:commentRss>http://laurentschneider.com/wordpress/2009/05/connect-by-nocycle.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>How to reuse connection in shell</title>
		<link>http://laurentschneider.com/wordpress/2009/05/how-to-reuse-connection-in-shell.html</link>
		<comments>http://laurentschneider.com/wordpress/2009/05/how-to-reuse-connection-in-shell.html#comments</comments>
		<pubDate>Fri, 15 May 2009 13:59:55 +0000</pubDate>
		<dc:creator>Laurent Schneider</dc:creator>
		
		<category><![CDATA[dba]]></category>

		<category><![CDATA[unix]]></category>

		<category><![CDATA[coprosess pipe]]></category>

		<guid isPermaLink="false">http://laurentschneider.com/?p=546</guid>
		<description><![CDATA[It is Friday, I wanted to give my readers some stuff for the week-end  
Imagine that piece of code :
countlines() {
&#160;&#160;c=$(sqlplus -s /nolog &#60;&#60;EOF &#124; grep -v Connected
connect scott/tiger
set feed off head off
select count(*) from $1;
EOF
)
&#160;&#160;echo there are $c lines in $1
}

countlines EMP
countlines DEPT

I can run this 
time ./script1
there are 14 lines in EMP
there [...]]]></description>
			<content:encoded><![CDATA[<p>It is Friday, I wanted to give my readers some stuff for the week-end <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Imagine that piece of code :</p>
<p><pre><code>countlines() {
&nbsp;&nbsp;c=$(sqlplus -s /nolog &lt;&lt;EOF | grep -v Connected
connect scott/tiger
set feed off head off
select count(*) from $1;
EOF
)
&nbsp;&nbsp;echo there are $c lines in $1
}

countlines EMP
countlines DEPT
</code></pre></p>
<p>I can run this </p>
<p><pre><code>time ./script1
there are 14 lines in EMP
there are 4 lines in DEPT

real&nbsp;&nbsp;&nbsp;&nbsp;0m0.46s
user&nbsp;&nbsp;&nbsp;&nbsp;0m0.06s
sys&nbsp;&nbsp;&nbsp;&nbsp; 0m0.09s
</code></pre></p>
<p>Sounds like a regular shell script. How could we optimize the countlines function? Well, we could create the connection only once and use coprocess pipe (with |&amp; that is pipe ampersand)</p>
<p><pre><code>sqlplus -s /nolog |&amp;

print -p &quot;connect scott/tiger&quot;

read -p line
if [ $line != Connected. ]
then
&nbsp;&nbsp;exit 1
fi

print -p &quot;set feed off head off&quot;

countlines() {
&nbsp;&nbsp;print -p &quot;select count(*) from $1;&quot;
&nbsp;&nbsp;read -p c
&nbsp;&nbsp;echo &quot;there is $c lines in $1&quot;
}

countlines EMP
countlines DEPT

print -p disconnect
</code></pre></p>
<p>A two-ways pipe is opened with sqlplus. There is only one connect, and one disconnect. </p>
<p>Let&#8217;s check the performance :</p>
<p><pre><code>$ time ./script2
there is 14 lines in EMP
there is 4 lines in DEPT

real&nbsp;&nbsp;&nbsp;&nbsp;0m0.23s
user&nbsp;&nbsp;&nbsp;&nbsp;0m0.00s
sys&nbsp;&nbsp;&nbsp;&nbsp; 0m0.01s
</code></pre></p>
<p>About twice as fast! Note the &#8220;Connected&#8221; output may not exist in recent version of sqlplus in silent mode. If you have a script that generates hundreds of connections, or which create a connection every 5 seconds or so, think about it <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Enjoy your week-end</p>
]]></content:encoded>
			<wfw:commentRss>http://laurentschneider.com/wordpress/2009/05/how-to-reuse-connection-in-shell.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>return code before grep</title>
		<link>http://laurentschneider.com/wordpress/2009/05/return-code-before-grep.html</link>
		<comments>http://laurentschneider.com/wordpress/2009/05/return-code-before-grep.html#comments</comments>
		<pubDate>Fri, 15 May 2009 13:12:19 +0000</pubDate>
		<dc:creator>Laurent Schneider</dc:creator>
		
		<category><![CDATA[dba]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[unix]]></category>

		<category><![CDATA[return code]]></category>

		<guid isPermaLink="false">http://laurentschneider.com/?p=542</guid>
		<description><![CDATA[In my previous post hide-password-from-ps-output-sql-loader I mentioned a way to pass the password to the loader thru a parameter file. As correctly suggested by Brian Tkatch, the password could be passed as standard input
sqlldr control=x.ctl silent=header,feedback &#60;&#60;EOF
scott/tiger
EOF
Username:
The Username: prompt is displayed  &#160;  
How do we get rid of this ?
sqlldr control=x.ctl silent=header,feedback &#60;&#60;EOF [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post <a href="http://laurentschneider.com/wordpress/2009/05/hide-password-from-ps-output-sql-loader.html">hide-password-from-ps-output-sql-loader</a> I mentioned a way to pass the password to the loader thru a parameter file. As correctly suggested by Brian Tkatch, the password could be passed as standard input</p>
<p><pre><code>sqlldr control=x.ctl silent=header,feedback &lt;&lt;EOF
scott/tiger
EOF
Username:</code></pre></p>
<p>The <i>Username:</i> prompt is displayed <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> &nbsp; <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>How do we get rid of this ?</p>
<p><pre><code>sqlldr control=x.ctl silent=header,feedback &lt;&lt;EOF | grep -v &quot;^Username:&quot;
scott/tiger
EOF</code></pre></p>
<p>There is no output. But what&#8217;s the error code<br />
<pre><code>echo $?
1</code></pre></p>
<p>The return code is 1 <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>This is not the error code from sqlldr, but the error code from grep !</p>
<p>Ok, here is the trick, a bit cryptic if you are not familiar with file descriptors </p>
<p><pre><code>( ( (sqlldr control=x &lt;&lt;EOF;echo $? &gt;&amp;3) |grep -v &quot;^Username:&quot; &gt;&amp;4 ) 3&gt;&amp;1 |(read x;exit $x) )4&gt;&amp;1
scott/tiger
EOF
echo $?
0
</code></pre></p>
<p>The return code is 0 <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://laurentschneider.com/wordpress/2009/05/return-code-before-grep.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Hide password from ps output : sql loader</title>
		<link>http://laurentschneider.com/wordpress/2009/05/hide-password-from-ps-output-sql-loader.html</link>
		<comments>http://laurentschneider.com/wordpress/2009/05/hide-password-from-ps-output-sql-loader.html#comments</comments>
		<pubDate>Wed, 13 May 2009 12:44:13 +0000</pubDate>
		<dc:creator>Laurent Schneider</dc:creator>
		
		<category><![CDATA[dba]]></category>

		<category><![CDATA[SQL Loader]]></category>

		<category><![CDATA[temporary file]]></category>

		<guid isPermaLink="false">http://laurentschneider.com/?p=540</guid>
		<description><![CDATA[By reporting the process status with ps, any Unix user will see the command line arguments
ps -ef 
&#160;&#160;&#160;&#160; UID&#160;&#160; PID&#160;&#160;PPID&#160;&#160;C&#160;&#160;&#160;&#160;STIME TTY&#160;&#160;&#160;&#160;&#160;&#160;TIME CMD
lsc&#160;&#160;&#160;&#160;&#160;&#160;13837 13825&#160;&#160;0&#160;&#160; May 11 pts/17&#160;&#160; 0:01 -ksh
oracle&#160;&#160;&#160;&#160;4698&#160;&#160;6294&#160;&#160;0 12:00:40 ?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0:00 sqlplus -s system/manager
appluser&#160;&#160;4229&#160;&#160;4062&#160;&#160;0 12:00:03 ?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0:00 sqlldr scott/tiger
applrun0 28445 28281&#160;&#160;0 11:54:03 ?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0:00 imp king/gold full=y
...
What you see here above is definitely a security issue. For sqlplus, [...]]]></description>
			<content:encoded><![CDATA[<p>By reporting the process status with ps, any Unix user will see the command line arguments</p>
<p><pre><code>ps -ef 
&nbsp;&nbsp;&nbsp;&nbsp; UID&nbsp;&nbsp; PID&nbsp;&nbsp;PPID&nbsp;&nbsp;C&nbsp;&nbsp;&nbsp;&nbsp;STIME TTY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIME CMD
lsc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;13837 13825&nbsp;&nbsp;0&nbsp;&nbsp; May 11 pts/17&nbsp;&nbsp; 0:01 -ksh
oracle&nbsp;&nbsp;&nbsp;&nbsp;4698&nbsp;&nbsp;6294&nbsp;&nbsp;0 12:00:40 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0:00 sqlplus -s system/manager
appluser&nbsp;&nbsp;4229&nbsp;&nbsp;4062&nbsp;&nbsp;0 12:00:03 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0:00 sqlldr scott/tiger
applrun0 28445 28281&nbsp;&nbsp;0 11:54:03 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0:00 imp king/gold full=y
...</code></pre></p>
<p>What you see here above is definitely a security issue. For sqlplus, the trick is to use <code>sqlplus /nolog</code> and then pass <code>connect system/manager</code> as input or script. </p>
<p>For sqlldr (and exp/imp etc&#8230;), the <i>trick</i> is to use a parameter file.</p>
<p>To make it as safe as possible, the file must be unique, readable only for owner and removed after usage. </p>
<p>Ex:<br />
<pre><code>umask 0077
TMPFILE=$(mktemp)
echo &quot;userid=scott/tiger&quot; &gt;$TMPFILE
sqlldr parfile=$TMPFILE control=x.ctl silent=header,feedback
rm $TMPFILE</code></pre></p>
<p>mktemp is an Unix utility that creates temp files with unique names.</p>
]]></content:encoded>
			<wfw:commentRss>http://laurentschneider.com/wordpress/2009/05/hide-password-from-ps-output-sql-loader.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>future of MySQL</title>
		<link>http://laurentschneider.com/wordpress/2009/05/future-of-mysql.html</link>
		<comments>http://laurentschneider.com/wordpress/2009/05/future-of-mysql.html#comments</comments>
		<pubDate>Tue, 05 May 2009 15:18:20 +0000</pubDate>
		<dc:creator>Laurent Schneider</dc:creator>
		
		<category><![CDATA[license]]></category>

		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://laurentschneider.com/?p=538</guid>
		<description><![CDATA[a google search on oracle and mysql will returns concerns about the future of MySQL. When SUN bought mysql, the enthousiasm was also not unanimous in the opensource community. But now it really need repositioning.
I was just reading : http://www.mysql.com/products/enterprise/unlimited.html
Deploy an unlimited number of MySQL Enterprise Servers for the price of
a single CPU of Oracle [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.google.com/search?q=mysql+oracle">a google search on oracle and mysql</a> will returns concerns about the future of MySQL. When SUN bought mysql, the enthousiasm was also not unanimous in the opensource community. But now it really need repositioning.</p>
<p>I was just reading : http://www.mysql.com/products/enterprise/unlimited.html<br />
<i><b>Deploy an unlimited number of MySQL Enterprise Servers for the price of<br />
a single CPU of Oracle Enterprise Edition </b><br />
Today, there are over 5,000 organizations that spend more than $1Million on<br />
License fees to Oracle, Microsoft, Sybase and IBM. In many cases, that&#8217;s money<br />
that doesn&#8217;t need to be spent. Not only does open source save money, it<br />
provides an architecture that is more scalable for modern web-based applications.<br />
No wonder open source software has become a strategic initiative for CIOs &#038; CFOs<br />
in many organizations.</i></p>
<p>Clearly this need repositioning. (For Oracle, money need to be spent <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_twisted.gif' alt=':twisted:' class='wp-smiley' /> ) </p>
<p>On the redundant offering MySQL and Oracle Database Express Edition, I could imagine Oracle will get rid of the free edition. Oracle seems to put effort on not releasing any database patch or security patch and the amount of features as well as the cpu/memory limitation are just way to annoying. </p>
<p>This is why I believe MySQL will survive XE.  </p>
<p>Pure guess of course&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://laurentschneider.com/wordpress/2009/05/future-of-mysql.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>ora-984 and sqlerrm</title>
		<link>http://laurentschneider.com/wordpress/2009/04/ora-984-and-sqlerrm.html</link>
		<comments>http://laurentschneider.com/wordpress/2009/04/ora-984-and-sqlerrm.html#comments</comments>
		<pubDate>Thu, 30 Apr 2009 12:00:59 +0000</pubDate>
		<dc:creator>Laurent Schneider</dc:creator>
		
		<category><![CDATA[dba]]></category>

		<category><![CDATA[plsql]]></category>

		<category><![CDATA[sqlerrm]]></category>

		<guid isPermaLink="false">http://laurentschneider.com/?p=533</guid>
		<description><![CDATA[What&#8217;s wrong with this code ?

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.8.0 - Production

SQL&#62; drop table lsc_t ;

Table dropped.

SQL&#62; create table lsc_t (x varchar2(255), y date);

Table created.

SQL&#62; begin
&#160;&#160;2&#160;&#160;&#160;&#160;null;
&#160;&#160;3&#160;&#160;exception when others then
&#160;&#160;4&#160;&#160;&#160;&#160;insert into lsc_t (x,y)
&#160;&#160;5&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;values (sqlerrm, sysdate);
&#160;&#160;6&#160;&#160;end;
&#160;&#160;7&#160;&#160;/

PL/SQL procedure successfully completed.

I was in the process of migrating a database with [...]]]></description>
			<content:encoded><![CDATA[<p>What&#8217;s wrong with this code ?<br />
<pre><code>
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.8.0 - Production

SQL&gt; drop table lsc_t ;

Table dropped.

SQL&gt; create table lsc_t (x varchar2(255), y date);

Table created.

SQL&gt; begin
&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;null;
&nbsp;&nbsp;3&nbsp;&nbsp;exception when others then
&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;insert into lsc_t (x,y)
&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;values (sqlerrm, sysdate);
&nbsp;&nbsp;6&nbsp;&nbsp;end;
&nbsp;&nbsp;7&nbsp;&nbsp;/

PL/SQL procedure successfully completed.
</code></pre></p>
<p>I was in the process of migrating a database with 10g and this piece of code became invalid <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p><pre><code>Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL&gt; drop table lsc_t ;

Table dropped.

SQL&gt; create table lsc_t (x varchar2(255), y date);

Table created.

SQL&gt; begin
&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;null;
&nbsp;&nbsp;3&nbsp;&nbsp;exception when others then
&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;insert into lsc_t (x,y)
&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;values (sqlerrm, sysdate);
&nbsp;&nbsp;6&nbsp;&nbsp;end;
&nbsp;&nbsp;7&nbsp;&nbsp;/
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;values (sqlerrm, sysdate);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
ERROR at line 5:
ORA-06550: line 5, column 17:
PL/SQL: ORA-00984: column not allowed here
ORA-06550: line 4, column 3:
PL/SQL: SQL Statement ignored

SQL&gt; </code></pre></p>
<p>Ok, the code is wrong. It has been running for half a decade in production but the exception was never reached.</p>
<p>Note it is a bug, and putting sqlerrm after sysdate would have generate the exception even in 9i</p>
<p><pre><code>Connected to:
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.8.0 - Production

SQL&gt; begin
&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;null;
&nbsp;&nbsp;3&nbsp;&nbsp;exception when others then
&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;insert into lsc_t (y,x)
&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;values (sysdate,sqlerrm);
&nbsp;&nbsp;6&nbsp;&nbsp;end;
&nbsp;&nbsp;7&nbsp;&nbsp;/
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;values (sysdate,sqlerrm);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
ERROR at line 5:
ORA-06550: line 5, column 25:
PL/SQL: ORA-00984: column not allowed here
ORA-06550: line 4, column 3:
PL/SQL: SQL Statement ignored</code></pre></p>
<p>Just having fun with 10g migration <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://laurentschneider.com/wordpress/2009/04/ora-984-and-sqlerrm.html/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
