<?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: Bug? with wrong results from all_objects in stored plsql procedures</title>
	<atom:link href="http://andrewfraserdba.com/2007/03/02/bug-with-wrong-results-from-all_objects-in-stored-plsql-procedures/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewfraserdba.com/2007/03/02/bug-with-wrong-results-from-all_objects-in-stored-plsql-procedures/</link>
	<description>Oracle DBA (plus SQL Server)</description>
	<lastBuildDate>Wed, 14 Jul 2010 09:54:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Gabriel Paulovic</title>
		<link>http://andrewfraserdba.com/2007/03/02/bug-with-wrong-results-from-all_objects-in-stored-plsql-procedures/#comment-43</link>
		<dc:creator>Gabriel Paulovic</dc:creator>
		<pubDate>Tue, 06 Mar 2007 04:53:54 +0000</pubDate>
		<guid isPermaLink="false">http://andrewfraser.wordpress.com/2007/03/02/bug-with-wrong-results-from-all_objects-in-stored-plsql-procedures/#comment-43</guid>
		<description>Nigel got it right, roles are disabled (unless using invoker rights),  all_objects contains only objects that a user has access to, all_objects shows you correctly only those objects you have access to. Try revoking roles from the user and the counts will match or grant all privileges granted via role directly to a user. Of course DBA users have DBA (or similar) role so the &quot;discrepancy&quot; seems larger, SYS has always access to all objects.
So this is not an anomaly but a useful feature.</description>
		<content:encoded><![CDATA[<p>Nigel got it right, roles are disabled (unless using invoker rights),  all_objects contains only objects that a user has access to, all_objects shows you correctly only those objects you have access to. Try revoking roles from the user and the counts will match or grant all privileges granted via role directly to a user. Of course DBA users have DBA (or similar) role so the &#8220;discrepancy&#8221; seems larger, SYS has always access to all objects.<br />
So this is not an anomaly but a useful feature.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Fraser</title>
		<link>http://andrewfraserdba.com/2007/03/02/bug-with-wrong-results-from-all_objects-in-stored-plsql-procedures/#comment-45</link>
		<dc:creator>Andrew Fraser</dc:creator>
		<pubDate>Mon, 05 Mar 2007 15:45:32 +0000</pubDate>
		<guid isPermaLink="false">http://andrewfraser.wordpress.com/2007/03/02/bug-with-wrong-results-from-all_objects-in-stored-plsql-procedures/#comment-45</guid>
		<description>Thanks Nigel. I checked this and yes, &quot;authid current user&quot; stops the discrepancy in results. But note that the anomaly occurs (with authid definer, the default) even when the owner and the current user are one and the same.

For example, in the below c+p I ran the code as the system user &lt;i&gt;and&lt;/i&gt; I created the procedure as the system user. So:
current user = SYSTEM; and
definer = SYSTEM
So it should not matter what authid is set to. But it does in fact - widely different results each way. Which is a bit of an unpleasant surprise.

Andrew.
&lt;code&gt;
SQL&gt; sho user
USER is &quot;SYSTEM&quot;
SQL&gt; set serverout on
SQL&gt; declare
  2    var1 number ;
  3  begin
  4    select count(*) into var1 from all_objects ;
  5    dbms_output.put_line(&#039;all_objects: &#039;&#124;&#124;var1) ;
  6  end ;
  7  /
all_objects: 14559

PL/SQL procedure successfully completed.

SQL&gt; create or replace procedure af_temp &lt;b&gt;authid definer&lt;/b&gt; as
  2    var1 number ;
  3  begin
  4    select count(*) into var1 from all_objects ;
  5    dbms_output.put_line(&#039;all_objects: &#039;&#124;&#124;var1) ;
  6  end ;
  7  /

Procedure created.

SQL&gt; exec af_temp ;
all_objects: &lt;b&gt;5380&lt;/b&gt;

PL/SQL procedure successfully completed.

SQL&gt; drop procedure af_temp ;

Procedure dropped.

SQL&gt; create or replace procedure af_temp &lt;b&gt;authid current_user&lt;/b&gt; as
  2    var1 number ;
  3  begin
  4    select count(*) into var1 from all_objects ;
  5    dbms_output.put_line(&#039;all_objects: &#039;&#124;&#124;var1) ;
  6  end ;
  7  /

Procedure created.

SQL&gt; exec af_temp ;
all_objects: &lt;b&gt;14560&lt;/b&gt;

PL/SQL procedure successfully completed.

SQL&gt; drop procedure af_temp ;

Procedure dropped.

SQL&gt; sho user
USER is &quot;SYSTEM&quot;
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Thanks Nigel. I checked this and yes, &#8220;authid current user&#8221; stops the discrepancy in results. But note that the anomaly occurs (with authid definer, the default) even when the owner and the current user are one and the same.</p>
<p>For example, in the below c+p I ran the code as the system user <i>and</i> I created the procedure as the system user. So:<br />
current user = SYSTEM; and<br />
definer = SYSTEM<br />
So it should not matter what authid is set to. But it does in fact &#8211; widely different results each way. Which is a bit of an unpleasant surprise.</p>
<p>Andrew.<br />
<code><br />
SQL&gt; sho user<br />
USER is "SYSTEM"<br />
SQL&gt; set serverout on<br />
SQL&gt; declare<br />
  2    var1 number ;<br />
  3  begin<br />
  4    select count(*) into var1 from all_objects ;<br />
  5    dbms_output.put_line('all_objects: '||var1) ;<br />
  6  end ;<br />
  7  /<br />
all_objects: 14559</p>
<p>PL/SQL procedure successfully completed.</p>
<p>SQL&gt; create or replace procedure af_temp <b>authid definer</b> as<br />
  2    var1 number ;<br />
  3  begin<br />
  4    select count(*) into var1 from all_objects ;<br />
  5    dbms_output.put_line('all_objects: '||var1) ;<br />
  6  end ;<br />
  7  /</p>
<p>Procedure created.</p>
<p>SQL&gt; exec af_temp ;<br />
all_objects: <b>5380</b></p>
<p>PL/SQL procedure successfully completed.</p>
<p>SQL&gt; drop procedure af_temp ;</p>
<p>Procedure dropped.</p>
<p>SQL&gt; create or replace procedure af_temp <b>authid current_user</b> as<br />
  2    var1 number ;<br />
  3  begin<br />
  4    select count(*) into var1 from all_objects ;<br />
  5    dbms_output.put_line('all_objects: '||var1) ;<br />
  6  end ;<br />
  7  /</p>
<p>Procedure created.</p>
<p>SQL&gt; exec af_temp ;<br />
all_objects: <b>14560</b></p>
<p>PL/SQL procedure successfully completed.</p>
<p>SQL&gt; drop procedure af_temp ;</p>
<p>Procedure dropped.</p>
<p>SQL&gt; sho user<br />
USER is "SYSTEM"<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel Thomas</title>
		<link>http://andrewfraserdba.com/2007/03/02/bug-with-wrong-results-from-all_objects-in-stored-plsql-procedures/#comment-44</link>
		<dc:creator>Nigel Thomas</dc:creator>
		<pubDate>Fri, 02 Mar 2007 17:07:46 +0000</pubDate>
		<guid isPermaLink="false">http://andrewfraser.wordpress.com/2007/03/02/bug-with-wrong-results-from-all_objects-in-stored-plsql-procedures/#comment-44</guid>
		<description>Andrew

I think this is a side effect of the not well enough known fact that by default PL/SQL procedures ignore privileges granted to you via roles (rather than directly). You need to create the procedure with invoker rights. See http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/08_subs.htm#18575.

CREATE PROCEDURE create_dept (
   my_deptno NUMBER,
   my_dname  VARCHAR2,
   my_loc    VARCHAR2) AUTHID CURRENT_USER AS
etc...

HTH

Regards Nigel</description>
		<content:encoded><![CDATA[<p>Andrew</p>
<p>I think this is a side effect of the not well enough known fact that by default PL/SQL procedures ignore privileges granted to you via roles (rather than directly). You need to create the procedure with invoker rights. See <a href="http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/08_subs.htm#18575" rel="nofollow">http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/08_subs.htm#18575</a>.</p>
<p>CREATE PROCEDURE create_dept (<br />
   my_deptno NUMBER,<br />
   my_dname  VARCHAR2,<br />
   my_loc    VARCHAR2) AUTHID CURRENT_USER AS<br />
etc&#8230;</p>
<p>HTH</p>
<p>Regards Nigel</p>
]]></content:encoded>
	</item>
</channel>
</rss>
