<?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>MacLochlainns Weblog &#187; OPAL</title>
	<atom:link href="http://blog.mclaughlinsoftware.com/category/opal/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mclaughlinsoftware.com</link>
	<description>Michael McLaughlin's Technical Blog</description>
	<lastBuildDate>Wed, 28 Jul 2010 00:02:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PHP Tutorial Available</title>
		<link>http://blog.mclaughlinsoftware.com/2010/03/29/php-tutorial-available/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/03/29/php-tutorial-available/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 17:11:43 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[LAMP]]></category>
		<category><![CDATA[MAMP]]></category>
		<category><![CDATA[OPAL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=3683</guid>
		<description><![CDATA[I finally got around to writing that PHP Tutorial. It&#8217;s a bit large and takes about 10 seconds to load or longer depending on your connection and machine. It covers the basics from writing your first page to loops. It was too large for a blog post, so it&#8217;s a blog page. Click on the [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got around to writing that PHP Tutorial. It&#8217;s a bit large and takes about 10 seconds to load or longer depending on your connection and machine. It covers the basics from writing your first page to loops. It was too large for a blog post, so it&#8217;s a blog page. Click on the <a href="http://blog.mclaughlinsoftware.com/php-programming/basic-php-tutorial/">link if you&#8217;d like to check it out</a>.</p>
<p>I plan others on functions, objects, and files. Then, I&#8217;ll get to tutorials against databases.</p>
<p>Naturally, suggestions are always welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/03/29/php-tutorial-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wrap a cursor function</title>
		<link>http://blog.mclaughlinsoftware.com/2010/03/07/wrap-a-cursor-function/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/03/07/wrap-a-cursor-function/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 03:14:55 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[OPAL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle XE]]></category>
		<category><![CDATA[pl/sql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=3584</guid>
		<description><![CDATA[A Gauss posted a question on my]]></description>
			<content:encoded><![CDATA[<p>A <em>Gauss</em> posted a question on my <a href="http://blog.mclaughlinsoftware.com/plsql-programming/pipelined-functions-plsql-tables/"pipelined table post</a> from last year&#8217;s Utah Oracle User&#8217;s Group Training Days presentation. If I understood his question correctly, this should help him work with his legacy code. Honestly, as I wrote the example something <a href="http://www.oreillynet.com/pub/au/1056"><em>Bryn Llewellyn</em></a> said kept banging around in my head, &#8220;Just because we can, doesn&#8217;t mean we should.&#8221; He was speaking of writing poorly engineered code.</p>
<p>Sometimes, we don&#8217;t get the opportunity to re-factor existing code. That leaves us with writing wrappers that aren&#8217;t pretty or effective. A realization and preface to showing everyone how to accomplish these tasks, and perhaps a watch out warning if you choose this path. I suspect that there may be a better way but I don&#8217;t know their code tree.</p>
<p>Here&#8217;s the question, as I understand it. They&#8217;ve got a library function in PL/SQL that returns a system reference cursor and is principally consumed by an external Java program. This type of architecture is more or less an Adapter OOAD pattern that I wrote about <a href="http://blog.mclaughlinsoftware.com/2008/10/31/adapter-or-not-adapter-thats-the-question/">here</a>, over a year and a half ago. The question comes to how to you wrap this approach and make it work in PL/SQL natively too.</p>
<p>The answer depends on some earlier posts because I don&#8217;t have a great deal of time to write new examples. It uses a <code>COMMON_LOOKUP</code> table, which is more or less a bunch of small tables grouped into a big table for use in <em>user interaction</em> forms. That way the values don&#8217;t get lost in a large code base and are always consistently maintained. These types of tables exist in all major ERP and CRM applications.</p>
<p>The base code for the example is <a href="http://blog.mclaughlinsoftware.com/2009/03/23/object-record-collections/">found here</a>, where I discussed how you can effectively use object tables &#8211; collections of user-defined object types (Oracle 9iR2 forward if I remember correctly). You can grab the full code at the bottom of the page by clicking the <strong><em>Code Script</em></strong> widget to unfold the code. That code also depends on the <a href="http://www.mhprofessional.com/product.php?isbn=0071494456&#038;cat=112">Oracle Database 11g PL/SQL Programming downloadable code</a>, which you can download by clicking the link to the zip file location.</p>
<p>Here are the steps to wrap a function that returns a PL/SQL reference cursor so that it can also return a PL/SQL associative array.</p>
<ol start="1">
<li>Create a package specification to hold all the components that are required to manage the process. Assuming that they may have anchored the system reference cursor to something other than a table like a shared cursor, which is a cumbersome implementation design. (I actually chose to exclude this from the book because it&#8217;s a stretch as a good coding practice. At least, it is from my perspective. Also, I couldn&#8217;t find an example in the Oracle documentation, which led me to believe they didn&#8217;t think it&#8217;s a great idea either or I could have glossed over it.) You should note that the PL/SQL <code>RECORD</code>, Associative Array (collection), and the <code>REF CURSOR</code> are defined in this package specification.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Create a package to hold the PL/SQL record structure.</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> PACKAGE example <span style="color: #993333; font-weight: bold;">IS</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Force cursors to be read as if empty every time.</span>
  PRAGMA SERIALLY_REUSABLE;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Package-level record structure that mimics SQL object type.</span>
  TYPE common_lookup_record <span style="color: #993333; font-weight: bold;">IS</span> RECORD
  <span style="color: #66cc66;">&#40;</span> common_lookup_id      NUMBER
  <span style="color: #66cc66;">,</span> common_lookup_type    VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">,</span> common_lookup_meaning VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Package-level collection that mimics SQL object table.</span>
  TYPE common_lookup_record_table <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">TABLE</span> OF common_lookup_record
  <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #993333; font-weight: bold;">BY</span> PLS_INTEGER;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Cursor structure to support a strongly-typed reference cursor.</span>
  CURSOR c <span style="color: #993333; font-weight: bold;">IS</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span>   common_lookup_id
    <span style="color: #66cc66;">,</span>        common_lookup_type
    <span style="color: #66cc66;">,</span>        common_lookup_meaning
    <span style="color: #993333; font-weight: bold;">FROM</span>     common_lookup;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Package-level strongly-typed system reference cursor.</span>
  TYPE cursor_lookup <span style="color: #993333; font-weight: bold;">IS</span> REF CURSOR <span style="color: #993333; font-weight: bold;">RETURN</span> c%ROWTYPE;
&nbsp;
END;
<span style="color: #66cc66;">/</span></pre></div></div>

<ol start="2">
<li>Write a function to return a strongly typed system reference cursor that&#8217;s anchored to a cursor defined in the package. This is fairly straightforward when the package specification is done right. You should notice right away that anchoring the original cursor in the package was a <em>horrible</em> practice because you must repeat it all again in the function. In my opinion, you shouldn&#8217;t anchor any system reference cursor explicitly to anything other than a table. The cursor could have used the generic weak cursor data type &#8211; <code>SYS_REFCURSOR</code>. Doing so, saves all the extra lines required by a potential shared cursor.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_common_lookup_cursor
<span style="color: #66cc66;">&#40;</span> table_name VARCHAR2<span style="color: #66cc66;">,</span> column_name VARCHAR2<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">RETURN</span> example<span style="color: #66cc66;">.</span>cursor_lookup <span style="color: #993333; font-weight: bold;">IS</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Define a local variable of a strongly-typed reference cursor.</span>
  lv_cursor EXAMPLE<span style="color: #66cc66;">.</span>CURSOR_LOOKUP;
&nbsp;
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Open the cursor from a static cursor</span>
  OPEN lv_cursor <span style="color: #993333; font-weight: bold;">FOR</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span> common_lookup_id
    <span style="color: #66cc66;">,</span>      common_lookup_type
    <span style="color: #66cc66;">,</span>      common_lookup_meaning
    <span style="color: #993333; font-weight: bold;">FROM</span>   common_lookup
    <span style="color: #993333; font-weight: bold;">WHERE</span>  common_lookup_table <span style="color: #66cc66;">=</span> table_name
    <span style="color: #993333; font-weight: bold;">AND</span>    common_lookup_column <span style="color: #66cc66;">=</span> column_name;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Return the cursor handle.</span>
  <span style="color: #993333; font-weight: bold;">RETURN</span> lv_cursor;
&nbsp;
END;
<span style="color: #66cc66;">/</span></pre></div></div>

<ol start="3">
<li>Write a wrapper function that takes the reference cursor as a formal parameter and returns an Associative Array. You should note that this can&#8217;t be called from a SQL context. You must only use it in a PL/SQL context because system reference cursors are PL/SQL only data types.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> convert_common_lookup_cursor
<span style="color: #66cc66;">&#40;</span> pv_cursor EXAMPLE<span style="color: #66cc66;">.</span>CURSOR_LOOKUP<span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">RETURN</span> example<span style="color: #66cc66;">.</span>common_lookup_record_table <span style="color: #993333; font-weight: bold;">IS</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a local counter variable.</span>
  counter INTEGER :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Local PL/SQL-only variable.</span>
  out_record  EXAMPLE<span style="color: #66cc66;">.</span>COMMON_LOOKUP_RECORD;
  out_table   EXAMPLE<span style="color: #66cc66;">.</span>COMMON_LOOKUP_RECORD_TABLE;
&nbsp;
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Grab the cursor wrapper and return values to a PL/SQL-only record collection.</span>
  LOOP
    FETCH pv_cursor <span style="color: #993333; font-weight: bold;">INTO</span> out_record;
    EXIT WHEN pv_cursor%NOTFOUND;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Assign it one row at a time to an associative array.</span>
    out_table<span style="color: #66cc66;">&#40;</span>counter<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> out_record;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Increment the counter.</span>
    counter :<span style="color: #66cc66;">=</span> counter <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;
&nbsp;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Return the record collection.</span>
  <span style="color: #993333; font-weight: bold;">RETURN</span> out_table;
&nbsp;
END;
<span style="color: #66cc66;">/</span></pre></div></div>

<ol start="4">
<li>You can test the program in an anonymous block, like the one below. It defines a local Associative Array variable and then assigns the system reference cursor through the wrapper.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Open the session to see output from PL/SQL blocks.</span>
<span style="color: #993333; font-weight: bold;">SET</span> SERVEROUTPUT <span style="color: #993333; font-weight: bold;">ON</span>
&nbsp;
DECLARE
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Define a local associative array.</span>
  process_table  EXAMPLE<span style="color: #66cc66;">.</span>COMMON_LOOKUP_RECORD_TABLE;
&nbsp;
BEGIN
  <span style="color: #808080; font-style: italic;">-- Print title block.</span>
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Converting a SYS_REFCURSOR to TABLE'</span><span style="color: #66cc66;">&#41;</span>;
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'---------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Run the dynamic variables through the cursor generating function and then convert it.</span>
  process_table :<span style="color: #66cc66;">=</span> convert_common_lookup_cursor<span style="color: #66cc66;">&#40;</span>get_common_lookup_cursor<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'ITEM_TYPE'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Read the content of the Associative array.  </span>
  <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> 1<span style="color: #66cc66;">..</span>process_table<span style="color: #66cc66;">.</span>COUNT LOOP
    dbms_output<span style="color: #66cc66;">.</span>put<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'['</span><span style="color: #66cc66;">||</span>process_table<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>common_lookup_id<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'['</span><span style="color: #66cc66;">||</span>process_table<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>common_lookup_type<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'['</span><span style="color: #66cc66;">||</span>process_table<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>common_lookup_meaning<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
  END LOOP;
&nbsp;
END;
<span style="color: #66cc66;">/</span></pre></div></div>

<p>I hope this answers Gauss&#8217;s question. While writing it, I could envision another question that might pop-up. How do you convert an object table type to a PL/SQL context. It was an omission not to include it in that <a href="http://blog.mclaughlinsoftware.com/2009/03/23/object-record-collections/">original post on object table types</a>. Here&#8217;s how you wrap an object table type into a PL/SQL scope collection.</p>
<p>You might have guessed. It&#8217;s done with another wrapper function. At least this is the easiest way to convert the SQL data type to a PL/SQL data type that I see. If you&#8217;ve another approach, a better way, let us know.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_common_lookup_record_table
<span style="color: #66cc66;">&#40;</span> table_name  VARCHAR2
<span style="color: #66cc66;">,</span> column_name VARCHAR2 <span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">RETURN</span> example<span style="color: #66cc66;">.</span>common_lookup_record_table <span style="color: #993333; font-weight: bold;">IS</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a local counter variable.</span>
  counter INTEGER :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Define a dynamic cursor that takes two formal parameters.</span>
  CURSOR c <span style="color: #66cc66;">&#40;</span>table_name_in VARCHAR2<span style="color: #66cc66;">,</span> table_column_name_in VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">IS</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span>   <span style="color: #66cc66;">*</span>
    <span style="color: #993333; font-weight: bold;">FROM</span>     <span style="color: #993333; font-weight: bold;">TABLE</span><span style="color: #66cc66;">&#40;</span>get_common_lookup_object_table<span style="color: #66cc66;">&#40;</span>UPPER<span style="color: #66cc66;">&#40;</span>table_name_in<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>UPPER<span style="color: #66cc66;">&#40;</span>table_column_name_in<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- A local PL/SQL-only collection variable.</span>
  list EXAMPLE<span style="color: #66cc66;">.</span>COMMON_LOOKUP_RECORD_TABLE;
&nbsp;
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Grab the cursor wrapper and return values to a PL/SQL-only record collection.</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> c<span style="color: #66cc66;">&#40;</span>table_name<span style="color: #66cc66;">,</span> column_name<span style="color: #66cc66;">&#41;</span> LOOP
    list<span style="color: #66cc66;">&#40;</span>counter<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> i;
    counter :<span style="color: #66cc66;">=</span> counter <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Return the record collection.</span>
  <span style="color: #993333; font-weight: bold;">RETURN</span> list;
END get_common_lookup_record_table;
<span style="color: #66cc66;">/</span></pre></div></div>

<p>You can then test this in an anonymous block, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Open the session to see output from PL/SQL blocks.</span>
<span style="color: #993333; font-weight: bold;">SET</span> SERVEROUTPUT <span style="color: #993333; font-weight: bold;">ON</span>
&nbsp;
DECLARE
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a local PL/SQL-only collection and assign the value from the function call.</span>
  list EXAMPLE<span style="color: #66cc66;">.</span>COMMON_LOOKUP_RECORD_TABLE;
&nbsp;
  BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Print title block.</span>
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Converting a SQL Collection to a PL/SQL Collection'</span><span style="color: #66cc66;">&#41;</span>;
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'---------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Assign wrapped SQL collection to a PL/SQL-only collection.</span>
  list :<span style="color: #66cc66;">=</span> get_common_lookup_record_table<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'ITEM_TYPE'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Call the record wrapper function.</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> 1<span style="color: #66cc66;">..</span>list<span style="color: #66cc66;">.</span>COUNT LOOP
    dbms_output<span style="color: #66cc66;">.</span>put<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'['</span><span style="color: #66cc66;">||</span>list<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>common_lookup_id<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'['</span><span style="color: #66cc66;">||</span>list<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>common_lookup_type<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'['</span><span style="color: #66cc66;">||</span>list<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>common_lookup_meaning<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
  END LOOP;
&nbsp;
END;
<span style="color: #66cc66;">/</span></pre></div></div>

<p>As always, I hope this helps somebody without paying a fee for content. <img src='http://blog.mclaughlinsoftware.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/03/07/wrap-a-cursor-function/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sample PL/SQL Cursor Loops</title>
		<link>http://blog.mclaughlinsoftware.com/2010/01/21/sample-plsql-cursor-loops/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/01/21/sample-plsql-cursor-loops/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 04:53:36 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[OPAL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle XE]]></category>
		<category><![CDATA[pl/sql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=3406</guid>
		<description><![CDATA[A few of my students wanted me to post sample cursor loops, so here are examples of simple, FOR, and WHILE loops. There are a couple variations on approaches that demonstrate %TYPE and %ROWTYPE anchoring to data dictionary table definitions and local cursors. Part of the idea behind these examples is to show the basic [...]]]></description>
			<content:encoded><![CDATA[<p>A few of my students wanted me to post sample cursor loops, so here are examples of simple, <code>FOR</code>, and <code>WHILE</code> loops. There are a couple variations on approaches that demonstrate <code>%TYPE</code> and <code>%ROWTYPE</code> anchoring to data dictionary table definitions and local cursors.</p>
<p>Part of the idea behind these examples is to show the basic structure while mimicking the <code>\G</code> option of MySQL. The <code>\G</code> (Go) displays results as a list of column names and values by row. Ever since I discovered that in MySQL, I&#8217;ve hoped Oracle would incorporate something similar in their product. While discussing my wish list, I&#8217;d also like Oracle to make the <code>FROM dual</code> optional (like MySQL does) when selecting a string or numeric literal.</p>
<p>You can click any of the titles to view the code, which isn&#8217;t needed when you don&#8217;t have JavaScript enabled or the RSS expands them for you.</p>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Simple loop with local variables</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
<p>This <em>simple loop</em> example uses a static cursor and local variables that map to each column returned by the cursor. It uses the <code>%TYPE</code> to anchor local variables to the data dictionary.</p>
<div>
<p style="clear: both">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SET</span> SERVEROUTPUT <span style="color: #993333; font-weight: bold;">ON</span> SIZE <span style="color: #cc66cc;">1000000</span>
&nbsp;
DECLARE
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare local variables that are anchored to column data types.</span>
  lv_title     item<span style="color: #66cc66;">.</span>item_title%TYPE;
  lv_subtitle  item<span style="color: #66cc66;">.</span>item_subtitle%TYPE;
  lv_rating    item<span style="color: #66cc66;">.</span>item_rating%TYPE;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a static cursor.</span>
  CURSOR c <span style="color: #993333; font-weight: bold;">IS</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span>   i<span style="color: #66cc66;">.</span>item_title <span style="color: #993333; font-weight: bold;">AS</span> title
	<span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_subtitle <span style="color: #993333; font-weight: bold;">AS</span> subtitle
	<span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_rating <span style="color: #993333; font-weight: bold;">AS</span> rating
	<span style="color: #993333; font-weight: bold;">FROM</span>     item i;
&nbsp;
BEGIN
  <span style="color: #808080; font-style: italic;">-- Open the cursor.</span>
  OPEN c;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Print a starting line.</span>
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Start the simple loop block.</span>
  LOOP
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Fetch a row of the cursor and assign it to the three local variables.</span>
    FETCH c
    <span style="color: #993333; font-weight: bold;">INTO</span>  lv_title
    <span style="color: #66cc66;">,</span>     lv_subtitle
    <span style="color: #66cc66;">,</span>     lv_rating;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Exit when there aren't any more records in the cursor, without this you loop infinitely.</span>
    EXIT WHEN c%NOTFOUND;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print the local variables on a single line each to mimic MySQL \G equivalent.</span>
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_TITLE    ['</span><span style="color: #66cc66;">||</span>lv_title<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_SUBTITLE ['</span><span style="color: #66cc66;">||</span>lv_subtitle<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_RATING   ['</span><span style="color: #66cc66;">||</span>lv_rating<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print an ending line.</span>
   dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Close the cursor and release the resources.</span>
  CLOSE c;
END;
<span style="color: #66cc66;">/</span></pre></td></tr></table></div>

</div>
</div>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Simple loop with a local record structure variable</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
<p>This <em>simple loop</em> example uses a static cursor, a local record structure data type, and a local variable of the local record structure data type. The local record structure maps to the columns returned by the cursor. It uses explicit data types that match those of the table. You could also use the <code>%TYPE</code> to anchor the elements of the structure in the local data type, like the prior example. With explicit data types, you must modify the program when the definition of the table changes otherwise your program may fail at runtime.</p>
<div>
<p style="clear: both">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SET</span> SERVEROUTPUT <span style="color: #993333; font-weight: bold;">ON</span> SIZE <span style="color: #cc66cc;">1000000</span>
&nbsp;
DECLARE
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a local record data type, with explicit data types (you could use %TYPE here too).</span>
  TYPE title_type <span style="color: #993333; font-weight: bold;">IS</span> RECORD
  <span style="color: #66cc66;">&#40;</span> title     VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">,</span> subtitle  VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">,</span> rating    VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a local variable of the local record structure data type.</span>
  item_record TITLE_TYPE;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a static cursor.</span>
  CURSOR c <span style="color: #993333; font-weight: bold;">IS</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span>   i<span style="color: #66cc66;">.</span>item_title <span style="color: #993333; font-weight: bold;">AS</span> title
	<span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_subtitle <span style="color: #993333; font-weight: bold;">AS</span> subtitle
	<span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_rating <span style="color: #993333; font-weight: bold;">AS</span> rating
	<span style="color: #993333; font-weight: bold;">FROM</span>     item i;
&nbsp;
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Open the cursor.</span>
  OPEN c;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Print a starting line.</span>
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Start the simple loop block.</span>
  LOOP
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Fetch a row of the cursor and assign it to the local record structure variable.</span>
    FETCH c
    <span style="color: #993333; font-weight: bold;">INTO</span>  item_record;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Exit when there aren't any more records in the cursor, without this you loop infinitely.</span>
    EXIT WHEN c%NOTFOUND;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print the local variable elements on a single line each to mimic MySQL \G equivalent.</span>
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_TITLE    ['</span><span style="color: #66cc66;">||</span>item_record<span style="color: #66cc66;">.</span>title<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_SUBTITLE ['</span><span style="color: #66cc66;">||</span>item_record<span style="color: #66cc66;">.</span>subtitle<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_RATING   ['</span><span style="color: #66cc66;">||</span>item_record<span style="color: #66cc66;">.</span>rating<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print an ending line.</span>
   dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Close the cursor and release the resources.</span>
  CLOSE c;
END;
<span style="color: #66cc66;">/</span></pre></td></tr></table></div>

</div>
</div>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Simple loop with a local cursor structure variable</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
<p>This <em>simple loop</em> example uses a static cursor, a local variable that inherits its record structure from the local cursor. It does so by using the <code>%ROWTYPE</code> against the cursor. Often the <code>%ROWTYPE</code> is only applied when you return a structure that maps to the complete table definition. Sometimes I think using <em>cursor_name%ROWTYPE</em> is the only real purpose for shared cursors but I know that&#8217;s not really true.</p>
<div>
<p style="clear: both">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SET</span> SERVEROUTPUT <span style="color: #993333; font-weight: bold;">ON</span> SIZE <span style="color: #cc66cc;">1000000</span>
&nbsp;
DECLARE
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a static cursor.</span>
  CURSOR c <span style="color: #993333; font-weight: bold;">IS</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span>   i<span style="color: #66cc66;">.</span>item_title <span style="color: #993333; font-weight: bold;">AS</span> title
	<span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_subtitle <span style="color: #993333; font-weight: bold;">AS</span> subtitle
	<span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_rating <span style="color: #993333; font-weight: bold;">AS</span> rating
	<span style="color: #993333; font-weight: bold;">FROM</span>     item i;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a local variable of that inherits its structure from a local cursor.</span>
  item_record c%ROWTYPE;
&nbsp;
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Open the cursor.</span>
  OPEN c;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Print a starting line.</span>
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Start the simple loop block.</span>
  LOOP
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Fetch a row of the cursor and assign it to the local record structure variable.</span>
    FETCH c
    <span style="color: #993333; font-weight: bold;">INTO</span>  item_record;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Exit when there aren't any more records in the cursor, without this you loop infinitely.</span>
    EXIT WHEN c%NOTFOUND;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print the local variable elements on a single line each to mimic MySQL \G equivalent.</span>
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_TITLE    ['</span><span style="color: #66cc66;">||</span>item_record<span style="color: #66cc66;">.</span>title<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_SUBTITLE ['</span><span style="color: #66cc66;">||</span>item_record<span style="color: #66cc66;">.</span>subtitle<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_RATING   ['</span><span style="color: #66cc66;">||</span>item_record<span style="color: #66cc66;">.</span>rating<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print an ending line.</span>
   dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Close the cursor and release the resources.</span>
  CLOSE c;
END;
<span style="color: #66cc66;">/</span></pre></td></tr></table></div>

</div>
</div>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">For loop with an implicit record structure variable</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
<p>This <em><code>FOR</code> loop</em> example uses a static cursor. When a <code>FOR</code> loop uses a cursor it becomes a <em>cursor <code>FOR</code> loop</em>, and the iterator <em><code>i</code></em> becomes an implicit cursor record structure. You should note that this is a very compact program because a <em>cursor <code>FOR</code> loop</em> manages opening and closing the cursor, and handling the loop exit implicitly. Many programmers default to this approach whenever it fits because it is simple and easy to implement.</p>
<div>
<p style="clear: both">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SET</span> SERVEROUTPUT <span style="color: #993333; font-weight: bold;">ON</span> SIZE <span style="color: #cc66cc;">1000000</span>
&nbsp;
DECLARE
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a static cursor.</span>
  CURSOR c <span style="color: #993333; font-weight: bold;">IS</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span>   i<span style="color: #66cc66;">.</span>item_title <span style="color: #993333; font-weight: bold;">AS</span> title
	<span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_subtitle <span style="color: #993333; font-weight: bold;">AS</span> subtitle
	<span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_rating <span style="color: #993333; font-weight: bold;">AS</span> rating
	<span style="color: #993333; font-weight: bold;">FROM</span>     item i;
&nbsp;
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Print a starting line.</span>
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Start a cursor FOR loop block.</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> c LOOP
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print the local variable elements on a single line each to mimic MySQL \G equivalent.</span>
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_TITLE    ['</span><span style="color: #66cc66;">||</span>i<span style="color: #66cc66;">.</span>title<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_SUBTITLE ['</span><span style="color: #66cc66;">||</span>i<span style="color: #66cc66;">.</span>subtitle<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_RATING   ['</span><span style="color: #66cc66;">||</span>i<span style="color: #66cc66;">.</span>rating<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print an ending line.</span>
   dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  END LOOP;
END;
<span style="color: #66cc66;">/</span></pre></td></tr></table></div>

</div>
</div>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">For loop without a declaration block</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
<p>This <em><code>FOR</code> loop</em> example uses a static cursor. Like the prior example, this <code>FOR</code> loop uses a cursor but it is defined inside the actual <code>FOR</code> loop structure. That approach eliminates the need for the declaration block. It&#8217;s a nice feature that some may call a trick. As a rule, you should really avoid this style because formally defining your cursor is a good practice and improves code maintainability. Naturally, this is probably the most compact program because everything is managed implicitly including the cursor assignment to the loop structure.</p>
<div>
<p style="clear: both">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SET</span> SERVEROUTPUT <span style="color: #993333; font-weight: bold;">ON</span> SIZE <span style="color: #cc66cc;">1000000</span>
&nbsp;
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Print a starting line.</span>
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Start a cursor FOR loop block with the static cursor in the definition.</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span>   i<span style="color: #66cc66;">.</span>item_title <span style="color: #993333; font-weight: bold;">AS</span> title
	        <span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_subtitle <span style="color: #993333; font-weight: bold;">AS</span> subtitle
	        <span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_rating <span style="color: #993333; font-weight: bold;">AS</span> rating
	        <span style="color: #993333; font-weight: bold;">FROM</span>     item i<span style="color: #66cc66;">&#41;</span> LOOP
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print the local variable elements on a single line each to mimic MySQL \G equivalent.</span>
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_TITLE    ['</span><span style="color: #66cc66;">||</span>i<span style="color: #66cc66;">.</span>title<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_SUBTITLE ['</span><span style="color: #66cc66;">||</span>i<span style="color: #66cc66;">.</span>subtitle<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_RATING   ['</span><span style="color: #66cc66;">||</span>i<span style="color: #66cc66;">.</span>rating<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print an ending line.</span>
   dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  END LOOP;
END;
<span style="color: #66cc66;">/</span></pre></td></tr></table></div>

</div>
</div>
<p style="clear: both">
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%"><code>WHILE</code> loop with a cursor guard on entry statement</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
<p>This <em><code>WHILE</code> loop</em> example uses a static cursor, like the prior examples. Unlike the prior example, the <code>WHILE</code> loop is a guard on entry loop. The previous loops were guard on exit loops. This has much the same structure as the simple loop with a cursor record structure variable but differs on two key points.</p>
<p>Point one is that you must have two <code>FETCH</code> statements because the guard on entry condition checks whether any records are found in the cursor. The first <code>FETCH</code> statement checks whether at least a one row is returned. When true or false, it initializes the cursor attributes, like <code>%FOUND</code>. The second <code>FETCH</code> statement handles the second row returned to last row returned from the cursor.</p>
<p>Point two is that you don&#8217;t have an <code>EXIT WHEN <em>cursor_name</em>%NOTFOUND</code> inside the loop because the guard condition stops the loop when it fails to find at least one record.</p>
<div>
<p style="clear: both">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;">DECLARE
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a static cursor.</span>
  CURSOR c <span style="color: #993333; font-weight: bold;">IS</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span>   i<span style="color: #66cc66;">.</span>item_title <span style="color: #993333; font-weight: bold;">AS</span> title
	<span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_subtitle <span style="color: #993333; font-weight: bold;">AS</span> subtitle
	<span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_rating <span style="color: #993333; font-weight: bold;">AS</span> rating
	<span style="color: #993333; font-weight: bold;">FROM</span>     item i;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a local variable of that inherits its structure from a local cursor.</span>
  item_record c%ROWTYPE;
&nbsp;
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Open the cursor.</span>
  OPEN c;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Print a starting line.</span>
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Fetch the first record to put into context the cursor attributes, like %FOUND.</span>
  FETCH c <span style="color: #993333; font-weight: bold;">INTO</span> item_record;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Start the simple loop block with a guard on entry condition.</span>
  WHILE <span style="color: #66cc66;">&#40;</span>c%FOUND<span style="color: #66cc66;">&#41;</span> LOOP
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print the local variable elements on a single line each to mimic MySQL \G equivalent.</span>
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_TITLE    ['</span><span style="color: #66cc66;">||</span>item_record<span style="color: #66cc66;">.</span>title<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_SUBTITLE ['</span><span style="color: #66cc66;">||</span>item_record<span style="color: #66cc66;">.</span>subtitle<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_RATING   ['</span><span style="color: #66cc66;">||</span>item_record<span style="color: #66cc66;">.</span>rating<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print an ending line.</span>
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Fetch the second and subsequent rows of the cursor and assign it to a local variables.</span>
    FETCH c
    <span style="color: #993333; font-weight: bold;">INTO</span>  item_record;
&nbsp;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Close the cursor and release the resources.</span>
  CLOSE c;
END;
<span style="color: #66cc66;">/</span></pre></td></tr></table></div>

<p>The <code>WHILE</code> loop as presented is complex because of the pre-loop <code>FETCH</code> statement, and the internal <code>FETCH</code> statement. It&#8217;s may appear better to convert it to a pseudo-infinite loop. You do that by setting the condition in a <code>WHILE</code> loop to a <code>TRUE</code> constant, like this example:</p>
<p style="clear: both">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;">DECLARE
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a static cursor.</span>
  CURSOR c <span style="color: #993333; font-weight: bold;">IS</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span>   i<span style="color: #66cc66;">.</span>item_title <span style="color: #993333; font-weight: bold;">AS</span> title
	<span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_subtitle <span style="color: #993333; font-weight: bold;">AS</span> subtitle
	<span style="color: #66cc66;">,</span>        i<span style="color: #66cc66;">.</span>item_rating <span style="color: #993333; font-weight: bold;">AS</span> rating
	<span style="color: #993333; font-weight: bold;">FROM</span>     item i;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a local variable of that inherits its structure from a local cursor.</span>
  item_record c%ROWTYPE;
&nbsp;
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Open the cursor.</span>
  OPEN c;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Print a starting line.</span>
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Start the simple loop block with a guard on entry condition.</span>
  WHILE <span style="color: #66cc66;">&#40;</span>TRUE<span style="color: #66cc66;">&#41;</span> LOOP
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Fetch the record set into a user-defined variable.</span>
    FETCH c <span style="color: #993333; font-weight: bold;">INTO</span> item_record;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Exit when there aren't any more records in the cursor, without this you loop infinitely.</span>
    EXIT WHEN c%NOTFOUND;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print the local variable elements on a single line each to mimic MySQL \G equivalent.</span>
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_TITLE    ['</span><span style="color: #66cc66;">||</span>item_record<span style="color: #66cc66;">.</span>title<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_SUBTITLE ['</span><span style="color: #66cc66;">||</span>item_record<span style="color: #66cc66;">.</span>subtitle<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM.ITEM_RATING   ['</span><span style="color: #66cc66;">||</span>item_record<span style="color: #66cc66;">.</span>rating<span style="color: #66cc66;">||</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Print an ending line.</span>
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'----------------------------------------------------------------------'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Close the cursor and release the resources.</span>
  CLOSE c;
END;
<span style="color: #66cc66;">/</span></pre></td></tr></table></div>

<p>The preceding example behaves much like a simple loop, and you have to ask what is the benefit of <code>WHILE (TRUE) LOOP</code> over <code>LOOP</code>. Generally, it appears that the <code>WHILE</code> loop syntax is slighly longer to type.</p>
</div>
</div>
<p>I&#8217;m sure this will help my students and hope it helps somebody else.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/01/21/sample-plsql-cursor-loops/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Windows 7 and Zend CE</title>
		<link>http://blog.mclaughlinsoftware.com/2009/11/28/windows-7-and-zend-ce/</link>
		<comments>http://blog.mclaughlinsoftware.com/2009/11/28/windows-7-and-zend-ce/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 04:56:46 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[Microsoft Windows 7]]></category>
		<category><![CDATA[OPAL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=3183</guid>
		<description><![CDATA[Installed Zend Community Edition on Windows 7 64-bit. It worked easily. You just need to remember to install the JSDK 32-bit version for the Java Bridge. Clear notation about phpMyAdmin and MySQL being separate downloads has been added to the new Zend Community Edition Server (4.0.6), and it clearly does support Windows 7. If you [...]]]></description>
			<content:encoded><![CDATA[<p>Installed Zend Community Edition on Windows 7 64-bit. It worked easily. You just need to remember to install the <a href="http://blog.mclaughlinsoftware.com/2009/07/07/zend-java-bridge-32-bit/">JSDK 32-bit version for the Java Bridge</a>. Clear notation about <a href="http://www.phpmyadmin.net/home_page/index.php">phpMyAdmin</a> and MySQL being separate downloads has been added to the new Zend Community Edition Server (4.0.6), and it clearly does support Windows 7.</p>
<p>If you plan on installing MySQL and Oracle, I would recommend you install MySQL after you install Oracle and the Zend Community Server. However, it doesn&#8217;t matter because both ways work. </p>
<p>That completes my WAMP (Windows, Apache, MySQL, Perl, PHP, or Python) and OPAW (Oracle, Perl, PHP, or Python, Apache, Windows) installations. Actually, I&#8217;m not sure there is an <em>OPAW</em> acronym for a <a href="http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29">LAMP</a> stack running Oracle on a Windows platform. OPAL is the acronym for a LAMP stack running an Oracle database, but I&#8217;ve never seen one before for Windows. Therefore, I created one.</p>
<p><span style="font-size:125%;color:blue"><em>My two cents worth &#8230;</em></span> </p>
<p>I&#8217;d vote for clearer guidance on these acronyms. After all, they&#8217;re only purpose appears to be how to market variants of LAMP. The variants that I&#8217;ve seen for LAMP (Linux) are: MAMP (Mac OS X), SCAMP (Santa Cruz Operation), SAMP (Solaris), OAMP (OpenBSD, and WAMP (Windows) for MySQL database versions. The key seems to be swapping the first letter. I&#8217;ve only seen OPAL (Linux) officially for a LAMP stack that uses an Oracle database on a Linux platform. While my OPAW leverages what I perceive as a possible pattern, it may be wrong. Does anybody know what the right way to label these is?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2009/11/28/windows-7-and-zend-ce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Java Bridge 32-bit</title>
		<link>http://blog.mclaughlinsoftware.com/2009/07/07/zend-java-bridge-32-bit/</link>
		<comments>http://blog.mclaughlinsoftware.com/2009/07/07/zend-java-bridge-32-bit/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 03:39:14 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[MAMP]]></category>
		<category><![CDATA[Microsoft XP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OPAL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=2808</guid>
		<description><![CDATA[I just wanted to see how Zend Server Community Edition might be broken. Performing a full feature install on Windows x64, I confirmed that Zend Server&#8217;s Java Bridge depends on the 32-bit JRE (common sense prevails). Installing it against the JRE 64-bit jvm.dll did raised an exception but none of the instructions address the problem. [...]]]></description>
			<content:encoded><![CDATA[<p>I just wanted to see how Zend Server Community Edition might be broken. Performing a full feature install on Windows x64, I confirmed that Zend Server&#8217;s Java Bridge depends on the 32-bit JRE (common sense prevails). Installing it against the JRE 64-bit jvm.dll did raised an exception but none of the instructions address the problem.</p>
<p>It&#8217;s one of those simplifying assumptions &#8211; everybody knows 32-bit software works with 32-bit software. Anybody running on Windows XP x64 should know that they may need a JDK 64-bit and both a JRE 64-bit and JRE 32-bit for some applications. For those who don&#8217;t know this, like my students and other newbies, when you run Windows XP the 64-bit stuff goes in the <code>C:\Program Files</code> directory and the 32-bit stuff goes in the <code>C:\Program Files (x86)</code> directory. This lets you develop 32-bit or 64-bit Java applications on the same 64-bit machine.</p>
<p><a href="http://blog.mclaughlinsoftware.com/wp-content/uploads/2009/07/zendbroken.png"><img src="http://blog.mclaughlinsoftware.com/wp-content/uploads/2009/07/zendbroken.png" alt="zendbroken" title="zendbroken" style="border:none" width="268" height="186" class="aligncenter size-full wp-image-2809" /></a></p>
<p>Another tidbit of interest, don&#8217;t choose a full install if you&#8217;ve already installed MySQL. The Zend Community Server isn&#8217;t smart enough to alter the configuration to another port, and their <code>my.ini</code> points to a <code>3306</code> listener port. This causes the MySQL_ZendServer51 service to fail. It also doesn&#8217;t uninstall well. If you don&#8217;t want to clean the Windows Registry, don&#8217;t choose to install a second MySQL.</p>
<p>As an FYI, the Zend installation of MySQL doesn&#8217;t put a password on the root account. Don&#8217;t forget to add one after the install if you go down the full product road. This has the <a href="http://blog.mclaughlinsoftware.com/php-programming/zend-server-installation/">Zend Server Community Edition installation instructions</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2009/07/07/zend-java-bridge-32-bit/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP OUT mode Parameter</title>
		<link>http://blog.mclaughlinsoftware.com/2009/07/03/php-out-mode-parameter/</link>
		<comments>http://blog.mclaughlinsoftware.com/2009/07/03/php-out-mode-parameter/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 03:07:50 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[OPAL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[pl/sql]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=2798</guid>
		<description><![CDATA[I saw a post in the OTN forum that asked a simple question and had no simple example as an answer, so I thought it would be nice to provide one. Basically, somebody wanted to know how to call into a stored procedure and return a value with more or less one pass-by-value and another [...]]]></description>
			<content:encoded><![CDATA[<p>I saw a post in the <a href="http://forums.oracle.com/forums/thread.jspa?threadID=912546&#038;tstart=0">OTN forum that asked a simple question</a> and had no simple example as an answer, so I thought it would be nice to provide one. Basically, somebody wanted to know how to call into a stored procedure and return a value with more or less one pass-by-value and another pass-by-reference variable.</p>
<p>This defines a simple <code>echo</code> procedure, which takes a message and returns a formatted message:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span> <span style="color: #00F;">PROCEDURE</span> echo
<span style="color: #00F;">&#40;</span> message <span style="color: #00F;">IN</span>     <span style="color: #00F;">VARCHAR2</span>
<span style="color: #00F;">,</span> reply      <span style="color: #00F;">OUT</span> <span style="color: #00F;">VARCHAR2</span> <span style="color: #00F;">&#41;</span> <span style="color: #00F;">IS</span>
<span style="color: #00F;">BEGIN</span>
  reply <span style="color: #00F;">:=</span> <span style="color: #F00;">'Message ['</span><span style="color: #00F;">||</span>message<span style="color: #00F;">||</span><span style="color: #F00;">'] received.'</span><span style="color: #00F;">;</span>
<span style="color: #00F;">END</span><span style="color: #00F;">;</span>
<span style="color: #00F;">/</span></pre></td></tr></table></div>

<p>The following PHP calls the procedure and returns the value. It uses the required connection syntax for the Zend Server Community Edition.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// Attempt to connect to your database.</span>
  <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span>oci_connect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;student&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;student&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;localhost/xe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Sorry! The connection to the database failed. Please try again later.&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Initialize incoming message whether or not parameter sent.</span>
    <span style="color: #000088;">$msg_in</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'msg'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'msg'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Cat got your keyboard?&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Set the call statement, like a SQL statement.</span>
    <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;BEGIN echo(:a,:b); END;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Prepare the statement and bind the two strings.</span>
    <span style="color: #000088;">$stmt</span> <span style="color: #339933;">=</span> oci_parse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Bind local variables into PHP statement, you need to size OUT only variables.</span>
    oci_bind_by_name<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;:a&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$msg_in</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    oci_bind_by_name<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;:b&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$msg_out</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> SQLT_CHR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Execute it and print success or failure message.</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>oci_execute<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">print</span> <span style="color: #000088;">$msg_out</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Sorry, I can't do that Dave...&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// Free resources.</span>
    oci_free_statement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    oci_close<span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>You can then test it with or without a parameter, like this example with a parameter:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">http://localhost/message_reply.php?msg=&quot;Sample message&quot;</pre></div></div>

<p>I put a link in the forum to this, and I hope it helps a few folks.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2009/07/03/php-out-mode-parameter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring Zend Server</title>
		<link>http://blog.mclaughlinsoftware.com/2009/07/02/configuring-zend-server/</link>
		<comments>http://blog.mclaughlinsoftware.com/2009/07/02/configuring-zend-server/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 05:39:32 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Microsoft Vista]]></category>
		<category><![CDATA[Microsoft XP]]></category>
		<category><![CDATA[OPAL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=2788</guid>
		<description><![CDATA[I got all the screen shots out last night, then I realized that the configuration instructions were missing. They&#8217;ve been added now, and you can check if you&#8217;re interested. In the process, I noticed that Zend Server Community Edition is using connection pooling by default with Oracle. This means that the TNS alias must be [...]]]></description>
			<content:encoded><![CDATA[<p>I got all the screen shots out last night, then I realized that the configuration instructions were missing. They&#8217;ve been added now, and you can <a href="http://blog.mclaughlinsoftware.com/php-programming/zend-server-installation/">check if you&#8217;re interested</a>.</p>
<p>In the process, I noticed that Zend Server Community Edition is using connection pooling by default with Oracle. This means that the TNS alias must be qualified by a <code>hostname</code>.</p>
<p>For example, on your local PC with Oracle Database 10g Express Edition, the default TNS alias is <code>XE</code>. You can&#8217;t use that anymore when you&#8217;re running the Zend Server. You must qualify it as <code>localhost/XE</code> or <code>hostname/XE</code> as the connection string. A natural alternative is to insert a fully qualified TNS network map</p>
<p>Here are three possible connection patterns:</p>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Localhost Connection</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
This shows you how to connect with <code>localhost/XE</code>.</p>
<div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// Attempt to connect to your database.</span>
  <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span>oci_connect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;student&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;student&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;localhost/xe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Sorry! The connection to the database failed. Please try again later.&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Congrats! You've connected to an Oracle database!&quot;</span><span style="color: #339933;">;</span>
    oci_close<span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>If you connect with a <code>localhost</code> string, your listener logs will show the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">02-JUL-<span style="color: #000000;">2009</span> <span style="color: #000000;">23</span>:<span style="color: #000000;">32</span>:<span style="color: #000000;">11</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">CONNECT_DATA</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">SERVICE_NAME</span>=xe<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">CID</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">PROGRAM</span>=C:\Program?Files\Zend\ZendServer\bin\php-cgi.exe<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">HOST</span>=MCLAUGHLINXP32<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">USER</span>=SYSTEM<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">ADDRESS</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">PROTOCOL</span>=tcp<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">HOST</span>=127.0.0.1<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">PORT</span>=<span style="color: #000000;">1405</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> establish <span style="color: #000000; font-weight: bold;">*</span> xe <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span></pre></div></div>

<p>The two things to point out with this are: (1) The <code>host</code> is <code>127.0.0.1</code>; and (2) The TNS alias is lowercase.</p>
</div>
</div>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Hostname Connection</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
This shows you how to connect with <code>hostname/XE</code>.</p>
<div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// Attempt to connect to your database.</span>
  <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span>oci_connect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;student&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;student&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;hostname/xe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Sorry! The connection to the database failed. Please try again later.&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Congrats! You've connected to an Oracle database!&quot;</span><span style="color: #339933;">;</span>
    oci_close<span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>If you connect with a <code>hostname</code> string, your listener logs will show the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">02-JUL-<span style="color: #000000;">2009</span> <span style="color: #000000;">23</span>:<span style="color: #000000;">29</span>:<span style="color: #000000;">16</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">CONNECT_DATA</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">SERVICE_NAME</span>=xe<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">CID</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">PROGRAM</span>=C:\Program?Files\Zend\ZendServer\bin\php-cgi.exe<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">HOST</span>=MCLAUGHLINXP32<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">USER</span>=SYSTEM<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">ADDRESS</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">PROTOCOL</span>=tcp<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">HOST</span>=172.16.153.138<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">PORT</span>=<span style="color: #000000;">1403</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> establish <span style="color: #000000; font-weight: bold;">*</span> xe <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span></pre></div></div>

<p>The two things to point out with this are: (1) the <code>host</code> is the real IP address on the network; and (2) the TNS alias is lowercase.</p>
</div>
</div>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Overriding TNS Connection</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
This shows you how to connect with an overriding TNS connection.</p>
<div>
<p>Before you adopt this style, you may want to set a <code>%TNS_ADMIN%</code> for your Windows OS. The suggestion is made since you may be running the client software and there&#8217;s a connection problem. You can click on the <em>Setup a TNS_ADMIN Environment Variable</em> menu to get at the details.</p>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Set a TNS_ADMIN Environment Variable</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
You can also set a <code>%TNS_ADMIN%</code> environment variable, by taking the following steps.</p>
<div style="padding-left:20px">
<ol start="1">
<li>Open your System icon from the traditional <em>Control Panel</em>. Inside, click on the <em>Advanced</em> tab. Click the <em>Environment Variable</em> tab.</li>
</ol>
<p><a href="http://blog.mclaughlinsoftware.com/wp-content/uploads/2009/07/EnvVariable1.png"><img src="http://blog.mclaughlinsoftware.com/wp-content/uploads/2009/07/EnvVariable1.png" alt="EnvVariable1" title="EnvVariable1" style="border:none" width="419" height="486" class="aligncenter size-full wp-image-2857" /></a></p>
<ol start="2">
<li>The bottom window is where you set <em>System variables</em>. Click the <em>New</em> button to add a %TNS_ADMIN% variable.</li>
</ol>
<p><a href="http://blog.mclaughlinsoftware.com/wp-content/uploads/2009/07/EnvVariable2.png"><img src="http://blog.mclaughlinsoftware.com/wp-content/uploads/2009/07/EnvVariable2.png" alt="EnvVariable2" title="EnvVariable2" style="border:none" width="384" height="430" class="aligncenter size-full wp-image-2858" /></a></p>
<ol start="3">
<li>The <em>New System Variable</em> Window lets you enter the variable. Unless you&#8217;ve placed your <code>tnsnames.ora</code> in a different location, you find the file in the <em>ORACLE_HOME</em>\network\admin</em>. If you&#8217;ve installed Oracle XE and Oracle on the same machine, you should know which contains both values because you entered them. The utilities don&#8217;t do that. If somebody has a question on that, let me know and I&#8217;ll put instructions out.</li>
</ol>
<p><a href="http://blog.mclaughlinsoftware.com/wp-content/uploads/2009/07/NewSystemVariable.png"><img src="http://blog.mclaughlinsoftware.com/wp-content/uploads/2009/07/NewSystemVariable.png" alt="NewSystemVariable" title="NewSystemVariable" style="border:none" width="347" height="147" class="aligncenter size-full wp-image-2859" /></a></p>
</div>
</div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #000088;">$tns</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;(DESCRIPTION =
              (ADDRESS=(PROTOCOL = TCP)(HOST = mclaughlinxp32)(PORT = 1521))
              (CONNECT_DATA=(SERVER = DEDICATED)(SERVICE_NAME = XE)))&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Attempt to connect to your database.</span>
  <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span>oci_connect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;student&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;student&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tns</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Sorry! The connection to the database failed. Please try again later.&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Congrats! You've connected to an Oracle database!&quot;</span><span style="color: #339933;">;</span>
    oci_close<span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>If you connect with an overriding TNS connection, your listener logs will show the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">02-JUL-<span style="color: #000000;">2009</span> <span style="color: #000000;">23</span>:<span style="color: #000000;">27</span>:<span style="color: #000000;">10</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">CONNECT_DATA</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">SERVICE_NAME</span>=XE<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">CID</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">PROGRAM</span>=C:\Program?Files\Zend\ZendServer\bin\php-cgi.exe<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">HOST</span>=MCLAUGHLINXP32<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">USER</span>=SYSTEM<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">ADDRESS</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">PROTOCOL</span>=tcp<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">HOST</span>=172.16.153.138<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">PORT</span>=<span style="color: #000000;">1401</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> establish <span style="color: #000000; font-weight: bold;">*</span> XE <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span></pre></div></div>

<p>The two things to point out with this are: (1) the <code>host</code> is the real network IP address; and (2) the TNS alias is uppercase, which is consistent with the TNS connection string.</p>
</div>
</div>
<p>I&#8217;m sure it was in the documents but then again, I didn&#8217;t read them. <img src='http://blog.mclaughlinsoftware.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2009/07/02/configuring-zend-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zend Core Server</title>
		<link>http://blog.mclaughlinsoftware.com/2009/07/02/zend-core-server/</link>
		<comments>http://blog.mclaughlinsoftware.com/2009/07/02/zend-core-server/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 06:00:00 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[LAMP]]></category>
		<category><![CDATA[MAMP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OPAL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=2778</guid>
		<description><![CDATA[The Zend Core Server replaces the deprecated Zend Core for Oracle. I&#8217;ve put a quick installation guide here. It&#8217;s much nicer, and the licensed server is now the recommended direction from Oracle. The community edition also installs MySQL, phpMySQLAdmin, and a brand new console. You should try it out.]]></description>
			<content:encoded><![CDATA[<p>The Zend Core Server replaces the deprecated Zend Core for Oracle. I&#8217;ve put a quick <a href="http://blog.mclaughlinsoftware.com/php-programming/zend-server-installation/">installation guide here</a>. It&#8217;s much nicer, and the licensed server is now the recommended direction from Oracle.</p>
<p>The community edition also installs MySQL, phpMySQLAdmin, and a brand new console. You should try it out.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2009/07/02/zend-core-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP, LOBs, and Oracle</title>
		<link>http://blog.mclaughlinsoftware.com/2009/06/29/php-lobs-and-oracle/</link>
		<comments>http://blog.mclaughlinsoftware.com/2009/06/29/php-lobs-and-oracle/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 02:35:08 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[LAMP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MAMP]]></category>
		<category><![CDATA[OPAL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[pl/sql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=2736</guid>
		<description><![CDATA[I finally got around to summarizing how to use PHP to store, retrieve, and display CLOBs and BLOBs from an Oracle database. I think too often we default to BFILEs. I put all the code in zip files with instructions and suggestions for locations. This is really the second entry that goes with configuring Zend [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got around to summarizing how to use PHP to store, retrieve, and display CLOBs and BLOBs from an Oracle database. I think too often we default to BFILEs. I put all the code in zip files with instructions and suggestions for locations. This is really the second entry that goes with configuring <a href="http://blog.mclaughlinsoftware.com/php-programming/zend-server-installation/">Zend Server Community Edition</a> or the <strong>DEPRECATED</strong> <a href="http://blog.mclaughlinsoftware.com/php-programming/zend-core-for-oracle/">Zend Core for Oracle</a>.</p>
<p>If you&#8217;re new to PHP, check out the <a href="http://www.oracle.com/technology/tech/php/pdf/underground-php-oracle-manual.pdf">Underground PHP and Oracle</a> book from <a href="http://blogs.oracle.com/opal/" rel="pingback">Christopher Jones</a> and <a href="http://blogs.oracle.com/alison/" rel="pingback">Alison Holloway</a>. It&#8217;s FREE!</p>
<p>The Oracle LOB Processing entry is in <a href="http://blog.mclaughlinsoftware.com/php-programming/oracle-lob-processing/">this blog page</a>. I know it means another click, but I&#8217;ll probably add and modify it over time. If you&#8217;ve got time and interest, take a look and let me know what you think and what improvements you&#8217;d like to see. Thanks. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2009/06/29/php-lobs-and-oracle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle PHP Configuration</title>
		<link>http://blog.mclaughlinsoftware.com/2009/06/27/oracle-php-configuration/</link>
		<comments>http://blog.mclaughlinsoftware.com/2009/06/27/oracle-php-configuration/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 20:47:27 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[LAMP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OPAL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=2674</guid>
		<description><![CDATA[I finally got around to creating a blog page that shows you how to install Zend Core for Oracle, verify the installation of PHP, your connection to an Oracle XE database with PHP, and your connection to a MySQL database with PHP. It&#8217;s using the folding concepts I&#8217;ve adopted in the blog. One section unfolds [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got around to creating a <a href="http://blog.mclaughlinsoftware.com/php-programming/zend-core-for-oracle/">blog page that shows you how to install Zend Core for Oracle</a>, verify the installation of PHP, your connection to an Oracle XE database with PHP, and your connection to a MySQL database with PHP.</p>
<p>It&#8217;s using the folding concepts I&#8217;ve adopted in the blog. One section unfolds to display screen shots for the installation of Zend Core for Oracle. Another section shows you how to confirm your PHP and Apache installation. Two other sections show you how to confirm your connection to an Oracle or MySQL database.</p>
<p>I apologize to those who don&#8217;t like to click through to another page, but it was a long page with 20+ images. Hope it helps a few folks, I know it&#8217;ll help my students. <img src='http://blog.mclaughlinsoftware.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2009/06/27/oracle-php-configuration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
