<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>blog.nicolas.pawlak.fr &#187; Bases de données</title>
	<atom:link href="http://blog.nicolas.pawlak.fr/categories/bases-de-donnees/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nicolas.pawlak.fr</link>
	<description>Tux ne sait pas voler, c&#039;est normal : ce n&#039;est pas un pingouin...</description>
	<lastBuildDate>Sun, 31 Jul 2011 14:56:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Manipulations sur les adresses e-mail d&#8217;une table sur MySQL</title>
		<link>http://blog.nicolas.pawlak.fr/2011/03/05/manipulations-sur-les-adresses-e-mail-dune-table-sur-mysql/</link>
		<comments>http://blog.nicolas.pawlak.fr/2011/03/05/manipulations-sur-les-adresses-e-mail-dune-table-sur-mysql/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 18:30:38 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=1374</guid>
		<description><![CDATA[Supposons un intranet d&#8217;entreprise sur un domaine &#171;&#160;domaine.fr&#160;&#187;, avec messagerie électronique en @domaine.fr pour tous les utilisateurs. Arrive le jour où l&#8217;architecture de l&#8217;intranet fait l&#8217;objet d&#8217;une évolution passant par le changement de domaine : domaine.fr devient intranet.nom.fr. Il va falloir, sur nombre de tables, modifier toutes les adresses e-mail de tous les utilisateurs. Il [...]]]></description>
			<content:encoded><![CDATA[<p>Supposons un <a href="http://www.commentcamarche.net/contents/entreprise/intranet.php3">intranet</a> d&#8217;entreprise sur un domaine &laquo;&nbsp;domaine.fr&nbsp;&raquo;, avec messagerie électronique en @domaine.fr pour tous les utilisateurs. </p>
<p>Arrive le jour où l&#8217;architecture de l&#8217;intranet fait l&#8217;objet d&#8217;une évolution passant par le changement de domaine : <em>domaine.fr</em> devient <em>intranet.nom.fr</em>. Il va falloir, sur nombre de tables, modifier toutes les adresses e-mail de tous les utilisateurs. Il faudra peut-être gérer, pour certains cas, des adresses e-mail mal orthographiées (domiane.fr), avec une <a href="http://fr.wikipedia.org/wiki/Sensibilité_à_la_casse">casse</a> différente (DOMAINE.FR), ou, comme j&#8217;ai pu le constater récemment sur un <a href="http://fr.wikipedia.org/wiki/Logiciel_de_suivi_de_problèmes"><em>bug tracker</em></a> où les utilisateurs s&#8217;inscrivaient eux-mêmes, des domaines totalement différents de celui mis en place (gmail.com)&#8230; voire pas de domaine du tout (simple nom d&#8217;utilisateur sous la forme prenom.nom) !</p>
<p>La simplicité voudrait que l&#8217;on édite le <a href="http://fr.wikipedia.org/wiki/Dump">dump</a> de la base de données avec son éditeur de texte favori (<a href="http://notepad-plus-plus.org/">Notepad++</a> sur Windows, <a href="http://fr.wikipedia.org/wiki/Vi">vi</a> sous Linux&#8230; en ce qui me concerne) et que l&#8217;on fasse les modifications avec une fonction de remplacement de texte. Seulement, l&#8217;hétérogénéité des adresses e-mail enregistrées et surtout la taille du dump sont deux freins non négligeables à cette solution. Ouvrir un dump de 1 Go avec Notepad++ ? Impensable ! Exporter uniquement les tables où figurent les adresses e-mail, puis ensuite les réinjecter ? Pourquoi pas, mais en fonction des outils mis en place sur l&#8217;intranet, cette méthode peut se réveler fastidieuse. Modifier manuellement dans la table les adresses e-mail ? Oui pour quelques utilisateurs, non pour plusieurs dizaines voire centaines d&#8217;utilisateurs.</p>
<p>Il y a une solution simple, efficace et rapide avec MySQL. Démonstration :</p>
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">DESC</span> users;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------+-------------+------+-----+---------+-------+ </span>
<span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">FIELD</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">TYPE</span>        <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #66cc66;">|</span> Extra <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------+-------------+------+-----+---------+-------+ </span>
<span style="color: #66cc66;">|</span> email <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>       <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------+-------------+------+-----+---------+-------+ </span>
<span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">ROW</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.05</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> users;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------------------------------+ </span>
<span style="color: #66cc66;">|</span> email                         <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------------------------------+ </span>
<span style="color: #66cc66;">|</span> sergent<span style="color: #66cc66;">.</span>bellec                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> capitaine<span style="color: #66cc66;">.</span>flamme@DOMAINE<span style="color: #66cc66;">.</span>FR   <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> lieutenant<span style="color: #66cc66;">.</span>columbo@domaine<span style="color: #66cc66;">.</span>fr <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> colonel<span style="color: #66cc66;">.</span>moutarde@youpi<span style="color: #66cc66;">.</span>fr     <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------------------------------+ </span>
<span style="color: #cc66cc;">4</span> <span style="color: #993333; font-weight: bold;">ROWS</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.05</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">UPDATE</span> users <span style="color: #993333; font-weight: bold;">SET</span> email<span style="color: #66cc66;">=</span>concat<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>email<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'@'</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'@intranet.nom.fr'</span><span style="color: #66cc66;">&#41;</span>;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4</span> <span style="color: #993333; font-weight: bold;">ROWS</span> affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">ROWS</span> matched: <span style="color: #cc66cc;">4</span>  Changed: <span style="color: #cc66cc;">4</span>  Warnings: <span style="color: #cc66cc;">0</span>
&nbsp;
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> users;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------------------------------+ </span>
<span style="color: #66cc66;">|</span> email                              <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------------------------------+ </span>
<span style="color: #66cc66;">|</span> sergent<span style="color: #66cc66;">.</span>bellec@intranet<span style="color: #66cc66;">.</span>nom<span style="color: #66cc66;">.</span>fr     <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> capitaine<span style="color: #66cc66;">.</span>flamme@intranet<span style="color: #66cc66;">.</span>nom<span style="color: #66cc66;">.</span>fr   <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> lieutenant<span style="color: #66cc66;">.</span>columbo@intranet<span style="color: #66cc66;">.</span>nom<span style="color: #66cc66;">.</span>fr <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> colonel<span style="color: #66cc66;">.</span>moutarde@intranet<span style="color: #66cc66;">.</span>nom<span style="color: #66cc66;">.</span>fr   <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------------------------------+ </span>
<span style="color: #cc66cc;">4</span> <span style="color: #993333; font-weight: bold;">ROWS</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span></pre></div></div>
<p>Explications :</p>
<p>- La fonction <em><a href="http://dev.mysql.com/doc/refman/5.0/fr/string-functions.html">substring_index</a></em> permet de découper la valeur d&#8217;un champ avec un délimiteur ;<br />
- La fonction <em><a href="http://dev.mysql.com/doc/refman/5.0/fr/string-functions.html">concat</a></em> permet de concaténer (ah bon ?) deux éléments.</p>
<p>Grâce à ces deux fonctions, la requête récupère pour chaque utilisateur la partie avant l&#8217;arobase, y ajoute la valeur &laquo;&nbsp;@intranet.nom.fr&nbsp;&raquo; et met à jour le champ. Tout simplement.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2011/03/05/manipulations-sur-les-adresses-e-mail-dune-table-sur-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux : attention aux mots de passe Oracle sur sqlplus !</title>
		<link>http://blog.nicolas.pawlak.fr/2010/06/29/linux-attention-aux-mots-de-passe-oracle-sur-sqlplus/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/06/29/linux-attention-aux-mots-de-passe-oracle-sur-sqlplus/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 10:00:56 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[connect]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mot]]></category>
		<category><![CDATA[nolog]]></category>
		<category><![CDATA[passe]]></category>
		<category><![CDATA[ps]]></category>
		<category><![CDATA[sqlplus]]></category>
		<category><![CDATA[system]]></category>
		<category><![CDATA[xe]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=970</guid>
		<description><![CDATA[Une petite piqûre de rappel sur la façon dont se connecter à une instance Oracle sous Linux, afin de tordre le cou au sacro-saint sqlplus identifiant/motdepasse@instance &#8230; &#91;ora102@bddhost&#93;# sqlplus SYSTEM/manager@XE &#160; SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jun 8 10:49:35 2010 &#160; Copyright &#40;c&#41; 1982, 2005, Oracle. All rights reserved. &#160; Connected to: Oracle [...]]]></description>
			<content:encoded><![CDATA[<p>Une petite piqûre de rappel sur la façon dont se connecter à une <a href="http://oracle.developpez.com/guide/architecture/archiinstance/">instance Oracle</a> sous Linux, afin de tordre le cou au sacro-saint <em>sqlplus  identifiant/motdepasse@instance</em> &#8230;</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>ora102<span style="color: #000000; font-weight: bold;">@</span>bddhost<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># sqlplus SYSTEM/manager@XE</span>
&nbsp;
SQL<span style="color: #000000; font-weight: bold;">*</span>Plus: Release 10.2.0.1.0 - Production on Tue Jun <span style="color: #000000;">8</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">49</span>:<span style="color: #000000;">35</span> <span style="color: #000000;">2010</span>
&nbsp;
Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1982</span>, <span style="color: #000000;">2005</span>, Oracle.  All rights reserved.
&nbsp;
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
&nbsp;
SQL<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>
<p>Ouvrons un autre <a href="http://doc.ubuntu-fr.org/terminal">terminal</a>, et voyons ce qui se passe lors d&#8217;une commande <em><a href="http://chl.be/glmf/www.linuxmag-france.org/old/lm3/ps.html">ps</a></em> :</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>bddhost<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># ps -ef | grep sqlplus | grep -v grep</span>
root      <span style="color: #000000;">9207</span>  <span style="color: #000000;">9193</span>  <span style="color: #000000;">0</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">49</span> pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>    00:00:00 sqlplus SYSTEM<span style="color: #000000; font-weight: bold;">/</span>manager<span style="color: #000000; font-weight: bold;">@</span>XE
root      <span style="color: #000000;">9208</span>  <span style="color: #000000;">9207</span>  <span style="color: #000000;">0</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">49</span> pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1</span>    00:00:00 sqlplus</pre></div></div>
<p>Plutôt gênant, non ? </p>
<p>Une bonne pratique est l&#8217;utilisation de l&#8217;option /nolog :</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>ora102<span style="color: #000000; font-weight: bold;">@</span>bddhost<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># sqlplus /nolog</span>
&nbsp;
SQL<span style="color: #000000; font-weight: bold;">*</span>Plus: Release 10.2.0.1.0 - Production on Tue Jun <span style="color: #000000;">8</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">53</span>:<span style="color: #000000;">48</span> <span style="color: #000000;">2010</span>
&nbsp;
Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1982</span>, <span style="color: #000000;">2005</span>, Oracle.  All rights reserved.
&nbsp;
SQL<span style="color: #000000; font-weight: bold;">&gt;</span> connect SYSTEM<span style="color: #000000; font-weight: bold;">/</span>manager<span style="color: #000000; font-weight: bold;">@</span>XE
Connected.
SQL<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>
<p>Le résultat de la commande <em>ps</em> :</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>bddhost<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># ps -ef | grep sqlplus | grep -v grep</span>
root      <span style="color: #000000;">9314</span>  <span style="color: #000000;">9193</span>  <span style="color: #000000;">0</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">53</span> pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>    00:00:00 sqlplus <span style="color: #000000; font-weight: bold;">/</span>nolog
root      <span style="color: #000000;">9315</span>  <span style="color: #000000;">9314</span>  <span style="color: #000000;">0</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">53</span> pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1</span>    00:00:00 sqlplus</pre></div></div>
<p>C&#8217;est mieux !</p>
<p>Enfin, pour une utilisation hors scripts, il vaut mieux éviter de saisir de cette façon son mot de passe et privilégier la solution suivante :</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>ora102<span style="color: #000000; font-weight: bold;">@</span>bddhost<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># sqlplus /nolog</span>
&nbsp;
SQL<span style="color: #000000; font-weight: bold;">*</span>Plus: Release 10.2.0.1.0 - Production on Tue Jun <span style="color: #000000;">8</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">56</span>:<span style="color: #000000;">55</span> <span style="color: #000000;">2010</span>
&nbsp;
Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1982</span>, <span style="color: #000000;">2005</span>, Oracle.  All rights reserved.
&nbsp;
SQL<span style="color: #000000; font-weight: bold;">&gt;</span> connect SYSTEM<span style="color: #000000; font-weight: bold;">@</span>XE
Enter password: <span style="color: #000000; font-weight: bold;">*******</span>
Connected.
SQL<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/06/29/linux-attention-aux-mots-de-passe-oracle-sur-sqlplus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Utiliser des variables dans MySQL</title>
		<link>http://blog.nicolas.pawlak.fr/2010/05/08/utiliser-des-variables-dans-mysql/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/05/08/utiliser-des-variables-dans-mysql/#comments</comments>
		<pubDate>Sat, 08 May 2010 13:00:39 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[variable]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=866</guid>
		<description><![CDATA[Dans le développement de pages web, la notion de variable est très fréquemment associée au langage de script (ASP, PHP). Mais MySQL peut en utiliser également, ce qui peut s&#8217;avérer être plus simple à administrer pour le développeur, et moins gourmand en ressources. mysql&#62; select * from t1; +------+------+ &#124; c1 &#124; c2 &#124; +------+------+ [...]]]></description>
			<content:encoded><![CDATA[<p>Dans le développement de pages web, la notion de <a href="http://fr.wikipedia.org/wiki/Variable_%28informatique%29">variable</a> est très fréquemment associée au <a href="http://fr.wikipedia.org/wiki/Langage_de_script">langage de script</a> (<a href="http://www.asp-php.net/">ASP, PHP</a>). Mais <a href="http://cyberzoide.developpez.com/php4/mysql/">MySQL</a> peut en utiliser également, ce qui peut s&#8217;avérer être plus simple à administrer pour le développeur, et moins gourmand en ressources.</p>
<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">from</span> t1<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #CC0099;">|</span> c1   <span style="color: #CC0099;">|</span> c2   <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">1</span> <span style="color: #CC0099;">|</span> aaa  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">2</span> <span style="color: #CC0099;">|</span> bbb  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">3</span> <span style="color: #CC0099;">|</span> ccc  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">4</span> <span style="color: #CC0099;">|</span> ddd  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">5</span> <span style="color: #CC0099;">|</span> eee  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #008080;">5</span> rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">select</span> @total <span style="color: #CC0099;">:=</span> <span style="color: #000099;">COUNT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #CC0099;">*</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">as</span> <span style="color: #008000;">&quot;@total&quot;</span> <span style="color: #990099; font-weight: bold;">from</span> t1<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+--------+</span>
<span style="color: #CC0099;">|</span> @total <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+--------+</span>
<span style="color: #CC0099;">|</span>      <span style="color: #008080;">5</span> <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+--------+</span>
<span style="color: #008080;">1</span> row <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.01</span> sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">from</span> t1 <span style="color: #990099; font-weight: bold;">where</span> c1 <span style="color: #CC0099;">=</span> @total<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #CC0099;">|</span> c1   <span style="color: #CC0099;">|</span> c2   <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">5</span> <span style="color: #CC0099;">|</span> eee  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #008080;">1</span> row <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.01</span> sec<span style="color: #FF00FF;">&#41;</span></pre></div></div>
<p>Il est également possible d&#8217;affecter directement une valeur à une variable :</p>
<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">from</span> t1<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #CC0099;">|</span> c1   <span style="color: #CC0099;">|</span> c2   <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">1</span> <span style="color: #CC0099;">|</span> aaa  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">2</span> <span style="color: #CC0099;">|</span> bbb  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">3</span> <span style="color: #CC0099;">|</span> ccc  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">4</span> <span style="color: #CC0099;">|</span> ddd  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">5</span> <span style="color: #CC0099;">|</span> eee  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #008080;">5</span> rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">set</span> @valeur <span style="color: #CC0099;">=</span> <span style="color: #008080;">4</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> <span style="color: #008080;">0</span> rows affected <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">from</span> t1 <span style="color: #990099; font-weight: bold;">where</span> c1 <span style="color: #CC0099;">=</span> @valeur<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #CC0099;">|</span> c1   <span style="color: #CC0099;">|</span> c2   <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">4</span> <span style="color: #CC0099;">|</span> ddd  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #008080;">1</span> row <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span></pre></div></div>
<p>Notez que dans ce cas, il faut utiliser simplement le signe &laquo;&nbsp;=&nbsp;&raquo; et non &laquo;&nbsp;:=&nbsp;&raquo; comme précédemment.</p>
<p>Un exemple d&#8217;utilisation concrète : comment faire pour qu&#8217;une table aux <a href="http://fr.wikipedia.org/wiki/Cl%C3%A9_primaire">clés primaires</a> décousues (1,3,8,14,15&#8230;) soit de nouveau bien ordonnée (1,2,3,4,5&#8230;) <sup>[1]</sup> ? Sélectionner chaque entrée de la table et l&#8217;ajouter dans une autre table ? C&#8217;est lourd&#8230; Faire une <a href="http://fr.wikipedia.org/wiki/Structure_de_contr%C3%B4le#Boucles">boucle</a> et envoyer une <a href="http://www.ianywhere.com/developer/product_manuals/sqlanywhere/0901/fr/html/dbrffr9/00000498.htm">instruction UPDATE</a> pour chaque entrée de la table ? C&#8217;est lourd&#8230; </p>
<p>MySQL le fait avec seulement une variable et une requête :</p>
<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">from</span> t1<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #CC0099;">|</span> c1   <span style="color: #CC0099;">|</span> c2   <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">1</span> <span style="color: #CC0099;">|</span> aaa  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">3</span> <span style="color: #CC0099;">|</span> bbb  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">8</span> <span style="color: #CC0099;">|</span> ccc  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>   <span style="color: #008080;">14</span> <span style="color: #CC0099;">|</span> ddd  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>   <span style="color: #008080;">15</span> <span style="color: #CC0099;">|</span> eee  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #008080;">5</span> rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">set</span> @valeur <span style="color: #CC0099;">=</span> <span style="color: #008080;">0</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> <span style="color: #008080;">0</span> rows affected <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">update</span> t1 <span style="color: #990099; font-weight: bold;">set</span> c1 <span style="color: #CC0099;">=</span> @valeur <span style="color: #CC0099;">:=</span> @valeur <span style="color: #CC0099;">+</span> <span style="color: #008080;">1</span><span style="color: #000033;">;</span>
Query OK<span style="color: #000033;">,</span> <span style="color: #008080;">4</span> rows affected <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span>
Rows matched: <span style="color: #008080;">5</span>  Changed: <span style="color: #008080;">4</span>  <span style="color: #990099; font-weight: bold;">Warnings</span>: <span style="color: #008080;">0</span>
&nbsp;
mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">from</span> t1<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #CC0099;">|</span> c1   <span style="color: #CC0099;">|</span> c2   <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">1</span> <span style="color: #CC0099;">|</span> aaa  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">2</span> <span style="color: #CC0099;">|</span> bbb  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">3</span> <span style="color: #CC0099;">|</span> ccc  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">4</span> <span style="color: #CC0099;">|</span> ddd  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">|</span>    <span style="color: #008080;">5</span> <span style="color: #CC0099;">|</span> eee  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+------+------+</span>
<span style="color: #008080;">5</span> rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span></pre></div></div>
<p>[1] : avec un champ auto-incrémenté et des <a href="http://www.ianywhere.com/developer/product_manuals/sqlanywhere/0901/fr/html/dbrffr9/00000386.htm">instructions DELETE</a> à répétition, on a vite fait de se retrouver dans ce genre de situation.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/05/08/utiliser-des-variables-dans-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Supprimer le bip système de MySQL en console sous Windows</title>
		<link>http://blog.nicolas.pawlak.fr/2010/01/13/supprimer-le-bip-systeme-de-mysql-en-console-sous-windows/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/01/13/supprimer-le-bip-systeme-de-mysql-en-console-sous-windows/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 14:30:19 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[bip]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=385</guid>
		<description><![CDATA[L&#8217;utilisation de MySQL en console sous Windows présente un léger inconvénient dans son utilisation classique : chaque erreur provoque un bip système plutôt désagréable pour les oreilles des voisins&#8230; et les nôtres. Il existe pourtant un paramètre à passer dans la commande de lancement MySQL afin de désactiver cette fonction : -b. Ce paramètre figure [...]]]></description>
			<content:encoded><![CDATA[<p>L&#8217;utilisation de MySQL en console sous Windows présente un léger inconvénient dans son utilisation classique : chaque erreur provoque un bip système plutôt désagréable pour les oreilles des voisins&#8230; et les nôtres. </p>
<p>Il existe pourtant un paramètre à passer dans la commande de lancement MySQL afin de désactiver cette fonction : <strong>-b</strong>.</p>
<p>Ce paramètre figure dans l&#8217;aide de la commande mysql, mais semble visiblement peu connu&#8230; malgré son utilité.</p>
<p>Pensez donc à lancer MySQL de cette façon :</p>
<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">C:\<span style="color: #33cc33;">&gt;</span> mysql -b -h serveur -u identifiant -p</pre></div></div>
<p>Vos voisins vous remercieront, et vous n&#8217;aurez plus à craindre d&#8217;être agressé à chaque erreur dans votre requête SQL&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/01/13/supprimer-le-bip-systeme-de-mysql-en-console-sous-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Améliorer l&#8217;utilisation de SQL*Plus (Oracle) sous Linux avec rlwrap</title>
		<link>http://blog.nicolas.pawlak.fr/2010/01/08/ameliorer-lutilisation-de-sqlplus-oracle-sous-linux-avec-rlwrap/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/01/08/ameliorer-lutilisation-de-sqlplus-oracle-sous-linux-avec-rlwrap/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 13:00:16 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[flèches]]></category>
		<category><![CDATA[historique]]></category>
		<category><![CDATA[rlwrap]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[sqlplus]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=390</guid>
		<description><![CDATA[L&#8217;utilisation de l&#8217;outil SQL*Plus d&#8217;Oracle sous un environnement Linux présente une particularité : il n&#8217;est pas possible de revenir dans l&#8217;historique des commandes passées avec les flèches, comme c&#8217;est possible sous Windows. Démonstration ora102@bddhost:~$ sqlplus /nolog &#160; SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jan 7 23:18:28 2010 &#160; Copyright (c) 1982, 2005, Oracle. All [...]]]></description>
			<content:encoded><![CDATA[<p>L&#8217;utilisation de l&#8217;outil SQL*Plus d&#8217;Oracle sous un environnement Linux présente une particularité : il n&#8217;est pas possible de revenir dans l&#8217;historique des commandes passées avec les flèches, comme c&#8217;est possible sous Windows. </p>
<p><strong>Démonstration</strong></p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">ora102@bddhost:~$ sqlplus /nolog
&nbsp;
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jan 7 23:18:28 2010
&nbsp;
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
&nbsp;
SQL&gt; connect SYSTEM@XE
Enter password:
Connected.
SQL&gt; alter user SYSTEM identified by drowssap;
&nbsp;
User altered.
&nbsp;
SQL &gt;</pre></div></div>
<p>Jusqu&#8217;ici, tout va bien. Essayons à présent de remonter dans l&#8217;historique avec les flèches :</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SQL&gt; ^[[A^[[B^[[A          &quot; - rest of line ignored.
SQL&gt; ^C2: unknown command &quot;</pre></div></div>
<p>Le moins que l&#8217;on puisse dire, c&#8217;est que c&#8217;est loin d&#8217;être fonctionnel&#8230; et on a très vite fait d&#8217;appuyer sur les flèches par habitude.</p>
<p><strong>La solution SQL*Plus</strong></p>
<p>Pour remonter dans l&#8217;historique avec SQL*Plus sous Linux, il faut en fait utiliser les commandes <em>L</em> et <em>R</em> :</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SQL&gt; alter user SYSTEM identified by drowssap;
&nbsp;
User altered.
&nbsp;
SQL&gt; L
  1* alter user SYSTEM identified by drowssap
SQL&gt; R
  1* alter user SYSTEM identified by drowssap
&nbsp;
User altered.
&nbsp;
SQL&gt; c/drowssap/password
  1* alter user SYSTEM identified by password
SQL&gt; R
  1* alter user SYSTEM identified by password
&nbsp;
User altered.</pre></div></div>
<p>La commande L permet de visualiser la dernière action, la commande R permet de la rejouer. Pour modifier la dernière action, il faut utiliser la commande <em>c/texte_avant/texte_apres</em>.</p>
<p><strong>La solution rlwrap</strong></p>
<p>Derrière ce nom se cache un petit utilitaire qui vient se greffer à SQL*Plus et rajoute l&#8217;utilisation de la bibliothèque <em>readline</em> afin de permettre d&#8217;utiliser l&#8217;historique SQL*Plus avec les flèches. </p>
<p>Il est disponible dans les dépôts Debian/Ubuntu/Fedora (liste sans doute non exhaustive). A défaut, vous pouvez télécharger la source <a href="http://utopia.knoware.nl/~hlub/rlwrap/">ici</a> afin de l&#8217;installer.</p>
<p>Une fois installé, vous devez remplacer vos commandes &laquo;&nbsp;sqlplus&nbsp;&raquo; par &laquo;&nbsp;rlwrap sqlplus&nbsp;&raquo; :</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ora102<span style="color: #000000; font-weight: bold;">@</span>bddhost:~$ rlwrap sqlplus <span style="color: #000000; font-weight: bold;">/</span>nolog</pre></div></div>
<p>Afin de rendre son utilisation plus transparente, il est possible de l&#8217;utiliser via un alias. Ajoutons-le :</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ora102<span style="color: #000000; font-weight: bold;">@</span>bddhost:~$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;alias sqlplus='rlwrap sqlplus'&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc</pre></div></div>
<p>Puis appliquons les changements apportés :</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ora102<span style="color: #000000; font-weight: bold;">@</span>bddhost:~$ <span style="color: #7a0874; font-weight: bold;">source</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc</pre></div></div>
<p>C&#8217;est fini. Désormais, en appelant l&#8217;exécutable sqlplus, rlwrap sera appelé de façon transparente et permettra l&#8217;utilisation des flèches pour visualiser ou modifier l&#8217;historique des commandes PL/SQL jouées.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/01/08/ameliorer-lutilisation-de-sqlplus-oracle-sous-linux-avec-rlwrap/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

