<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Not quite an invalid function</title>
	<atom:link href="http://blog.mclaughlinsoftware.com/2009/05/27/not-quite-an-invalid-function/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mclaughlinsoftware.com/2009/05/27/not-quite-an-invalid-function/</link>
	<description>Michael McLaughlin's Technical Blog</description>
	<lastBuildDate>Wed, 08 Sep 2010 23:39:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: TonyBoy</title>
		<link>http://blog.mclaughlinsoftware.com/2009/05/27/not-quite-an-invalid-function/comment-page-1/#comment-8868</link>
		<dc:creator>TonyBoy</dc:creator>
		<pubDate>Thu, 10 Sep 2009 23:03:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=2466#comment-8868</guid>
		<description>thanks for everything</description>
		<content:encoded><![CDATA[<p>thanks for everything</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: maclochlainn</title>
		<link>http://blog.mclaughlinsoftware.com/2009/05/27/not-quite-an-invalid-function/comment-page-1/#comment-5166</link>
		<dc:creator>maclochlainn</dc:creator>
		<pubDate>Fri, 29 May 2009 00:11:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=2466#comment-5166</guid>
		<description>My understanding of those is:

&lt;div style=&quot;padding-left:20px;background:#FFFFFF&quot;&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;code&gt;SYSDATE&lt;/code&gt; is a SQL*Plus session level alias for the result of an OS current time call.&lt;/li&gt;

	&lt;li&gt;&lt;code&gt;USER&lt;/code&gt; is a SQL*Plus environment variable that maps to the &lt;code&gt;CURRENT_USER&lt;/code&gt; in the &lt;code&gt;V$SESSION&lt;/code&gt; view.&lt;/li&gt;

	&lt;li&gt;&lt;code&gt;SYS_GUID()&lt;/code&gt; calls a function to return a &lt;em&gt;Globally Unique Identifier. This makes it a constructor function that requires open and closed parentheses in a SQL context and none in a PL/SQL context.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

In SQL, you call it like this with the parentheses. This type of call mechanic is required for user-definted object types that are instantiable.

&lt;pre lang=&quot;SQL&quot;&gt;
SQL&gt; SELECT sys_guid() FROM dual;
&lt;/pre&gt;

The PL/SQL syntax returns a different value because each call returns a unique value.

&lt;pre lang=&quot;PLSQL&quot;&gt;
BEGIN
  dbms_output.put_line(&#039;[&#039;&#124;sys_guid&#124;&#124;&#039;]&#039;);
END;
/
&lt;/pre&gt;

Laurent, while you know all this other don&#039;t and I figured it might help somebody. If you&#039;ve any followup comments, they&#039;re always appreciated.

Here&#039;s a quick little example of the object type, and it&#039;s call semantics. The first step is to create an object type that returns an instance of itself.

&lt;pre lang=&quot;PLSQL&quot; line=&quot;1&quot;&gt;
CREATE OR REPLACE TYPE hello_there IS OBJECT
( who VARCHAR2(20)
, CONSTRUCTOR FUNCTION hello_there
  RETURN SELF AS RESULT
, CONSTRUCTOR FUNCTION hello_there
  ( who VARCHAR2 )
  RETURN SELF AS RESULT )
INSTANTIABLE NOT FINAL;
/
&lt;/pre&gt;

After defining the object type, you create the body, like this:

&lt;pre lang=&quot;PLSQL&quot; line=&quot;1&quot;&gt;
CREATE OR REPLACE TYPE BODY hello_there IS

  CONSTRUCTOR FUNCTION hello_there RETURN SELF AS RESULT IS
    hello HELLO_THERE := hello_there(&#039;Generic Object.&#039;);
  BEGIN
    self := hello;
    RETURN;
  END hello_there;

  CONSTRUCTOR FUNCTION hello_there (who VARCHAR2) RETURN SELF AS RESULT IS
  BEGIN
    self.who := who;
    RETURN;
  END hello_there;

END;
/
&lt;/pre&gt;

If you attempt to call it without parentheses in a SQL statement, it&#039;ll fail like so ...

&lt;pre lang=&quot;SQL&quot;&gt;
SELECT hello_there FROM dual
       *
ERROR at line 1:
ORA-00904: &quot;HELLO_THERE&quot;: invalid identifier
&lt;/pre&gt;

You should note that the error message is quite different than that received with the &lt;code&gt;CALL&lt;/code&gt; triggered &lt;code&gt;ORA-06576&lt;/code&gt; error. If you provide paraentheses, like this

&lt;pre lang=&quot;SQL&quot;&gt;
SELECT hello_there() FROM dual;
&lt;/pre&gt;

it&#039;ll succeed with the following return value:

&lt;pre lang=&quot;SQL&quot;&gt;
HELLO_THERE()(WHO)
------------------------------
HELLO_THERE(&#039;Generic Object.&#039;)
&lt;/pre&gt;

There&#039;s no equivalent &lt;code&gt;CALL&lt;/code&gt; syntax into a bind variable because you can&#039;t define a bind variable of a user-defined type (e.g., object type). More on the right way to manage Oracle object types is found in Chapter 14 of &lt;a href=&quot;http://www.amazon.com/Oracle-Database-Programming-Osborne-ORACLE/dp/0071494456/ref=pd_ts_b_3?ie=UTF8&amp;s=books&quot; rel=&quot;nofollow&quot;&gt;Oracle Database 11g PL/SQL Programming&lt;/a&gt;.
</description>
		<content:encoded><![CDATA[<p>My understanding of those is:</p>
<div style="padding-left:20px;background:#FFFFFF">
<ul>
<li><code>SYSDATE</code> is a SQL*Plus session level alias for the result of an OS current time call.</li>
<li><code>USER</code> is a SQL*Plus environment variable that maps to the <code>CURRENT_USER</code> in the <code>V$SESSION</code> view.</li>
<li><code>SYS_GUID()</code> calls a function to return a <em>Globally Unique Identifier. This makes it a constructor function that requires open and closed parentheses in a SQL context and none in a PL/SQL context.</em></li>
</ul>
</div>
<p>In SQL, you call it like this with the parentheses. This type of call mechanic is required for user-definted object types that are instantiable.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">SQL<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> sys_guid<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> dual;</pre></div></div>

<p>The PL/SQL syntax returns a different value because each call returns a unique value.</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">BEGIN</span>
  <span style="color: #00F;">DBMS_OUTPUT</span><span style="color: #00F;">.</span>put_line<span style="color: #00F;">&#40;</span><span style="color: #F00;">'['</span>|sys_guid<span style="color: #00F;">||</span><span style="color: #F00;">']'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
<span style="color: #00F;">END</span><span style="color: #00F;">;</span>
<span style="color: #00F;">/</span></pre></div></div>

<p>Laurent, while you know all this other don&#8217;t and I figured it might help somebody. If you&#8217;ve any followup comments, they&#8217;re always appreciated.</p>
<p>Here&#8217;s a quick little example of the object type, and it&#8217;s call semantics. The first step is to create an object type that returns an instance of itself.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</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;">TYPE</span> hello_there <span style="color: #00F;">IS</span> OBJECT
<span style="color: #00F;">&#40;</span> who <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">20</span><span style="color: #00F;">&#41;</span>
<span style="color: #00F;">,</span> CONSTRUCTOR <span style="color: #00F;">FUNCTION</span> hello_there
  <span style="color: #00F;">RETURN</span> SELF <span style="color: #00F;">AS</span> RESULT
<span style="color: #00F;">,</span> CONSTRUCTOR <span style="color: #00F;">FUNCTION</span> hello_there
  <span style="color: #00F;">&#40;</span> who <span style="color: #00F;">VARCHAR2</span> <span style="color: #00F;">&#41;</span>
  <span style="color: #00F;">RETURN</span> SELF <span style="color: #00F;">AS</span> RESULT <span style="color: #00F;">&#41;</span>
INSTANTIABLE <span style="color: #00F;">NOT</span> FINAL<span style="color: #00F;">;</span>
<span style="color: #00F;">/</span></pre></td></tr></table></div>

<p>After defining the object type, you create the body, like this:</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
</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;">TYPE</span> <span style="color: #00F;">BODY</span> hello_there <span style="color: #00F;">IS</span>
&nbsp;
  CONSTRUCTOR <span style="color: #00F;">FUNCTION</span> hello_there <span style="color: #00F;">RETURN</span> SELF <span style="color: #00F;">AS</span> RESULT <span style="color: #00F;">IS</span>
    hello HELLO_THERE <span style="color: #00F;">:=</span> hello_there<span style="color: #00F;">&#40;</span><span style="color: #F00;">'Generic Object.'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
  <span style="color: #00F;">BEGIN</span>
    self <span style="color: #00F;">:=</span> hello<span style="color: #00F;">;</span>
    <span style="color: #00F;">RETURN</span><span style="color: #00F;">;</span>
  <span style="color: #00F;">END</span> hello_there<span style="color: #00F;">;</span>
&nbsp;
  CONSTRUCTOR <span style="color: #00F;">FUNCTION</span> hello_there <span style="color: #00F;">&#40;</span>who <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">RETURN</span> SELF <span style="color: #00F;">AS</span> RESULT <span style="color: #00F;">IS</span>
  <span style="color: #00F;">BEGIN</span>
    self<span style="color: #00F;">.</span>who <span style="color: #00F;">:=</span> who<span style="color: #00F;">;</span>
    <span style="color: #00F;">RETURN</span><span style="color: #00F;">;</span>
  <span style="color: #00F;">END</span> hello_there<span style="color: #00F;">;</span>
&nbsp;
<span style="color: #00F;">END</span><span style="color: #00F;">;</span>
<span style="color: #00F;">/</span></pre></td></tr></table></div>

<p>If you attempt to call it without parentheses in a SQL statement, it&#8217;ll fail like so &#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> hello_there <span style="color: #993333; font-weight: bold;">FROM</span> dual
       <span style="color: #66cc66;">*</span>
ERROR at line <span style="color: #cc66cc;">1</span>:
ORA<span style="color: #66cc66;">-</span>00904: <span style="color: #ff0000;">&quot;HELLO_THERE&quot;</span>: invalid identifier</pre></div></div>

<p>You should note that the error message is quite different than that received with the <code>CALL</code> triggered <code>ORA-06576</code> error. If you provide paraentheses, like this</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> hello_there<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> dual;</pre></div></div>

<p>it&#8217;ll succeed with the following return value:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">HELLO_THERE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>WHO<span style="color: #66cc66;">&#41;</span>
<span style="color: #808080; font-style: italic;">------------------------------</span>
HELLO_THERE<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Generic Object.'</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>There&#8217;s no equivalent <code>CALL</code> syntax into a bind variable because you can&#8217;t define a bind variable of a user-defined type (e.g., object type). More on the right way to manage Oracle object types is found in Chapter 14 of <a href="http://www.amazon.com/Oracle-Database-Programming-Osborne-ORACLE/dp/0071494456/ref=pd_ts_b_3?ie=UTF8&#038;s=books" rel="nofollow">Oracle Database 11g PL/SQL Programming</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurent Schneider</title>
		<link>http://blog.mclaughlinsoftware.com/2009/05/27/not-quite-an-invalid-function/comment-page-1/#comment-5134</link>
		<dc:creator>Laurent Schneider</dc:creator>
		<pubDate>Thu, 28 May 2009 07:37:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=2466#comment-5134</guid>
		<description>it is a bit puzzling why you have 
SYS_GUID(), SYSDATE, USER 
but not 
SYS_GUID, SYSDATE(), USER()

...</description>
		<content:encoded><![CDATA[<p>it is a bit puzzling why you have<br />
SYS_GUID(), SYSDATE, USER<br />
but not<br />
SYS_GUID, SYSDATE(), USER()</p>
<p>&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
