Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, gs.

Asked: April 17, 2003 - 3:28 pm UTC

Last updated: February 10, 2004 - 7:14 am UTC

Version: 9.2.0.3

Viewed 1000+ times

You Asked

Dear Tom,

1, Where can I find the source of DESCRIBE (ex DESC mytab). Is it a function, procedure or just a sql script?

2, Why is it different when I used all_objects vs dba_objects in a procedure? The owner of the proc is a DBA. (I assume it has to do with the roles). isn't all_objects and dba_objects almost same when run by a DBA user?

thanks.

and Tom said...

1) it is an internal function in sqlplus. there is a package DBMS_DESCRIBE that you can use to achieve the same.


2) read the view text out and compare them. ALL_OBJECTS has security builtin. DBA_OBJECTS -- shows everything.

ops$tkyte@ORA920> select 'all', count(*) from all_objects union all
2 select 'dba', count(*) from dba_objects;

'AL COUNT(*)
--- ----------
all 31622
dba 32121



they return different answers in all environments -- but the results are more pronounced in a procedure. Consider:

ops$tkyte@ORA920> begin
2 for x in ( select 'all' a , count(*) b from all_objects union all
3 select 'dba', count(*) from dba_objects )
4 loop
5 dbms_output.put_line( x.a || ' ' || x.b );
6 end loop;
7 end;
8 /
all 31623
dba 32122

PL/SQL procedure successfully completed.

ops$tkyte@ORA920> create or replace procedure p
2 as
3 begin
4 for x in ( select 'all' a , count(*) b from all_objects union all
5 select 'dba', count(*) from dba_objects )
6 loop
7 dbms_output.put_line( x.a || ' ' || x.b );
8 end loop;
9 end;
10 /

Procedure created.

ops$tkyte@ORA920> exec p
all 29564
dba 32122

PL/SQL procedure successfully completed.



all_objects appears to have lots less rows in a procedure without roles -- but you can see this in plus as well;


ops$tkyte@ORA920> set role none
2 /

Role set.

ops$tkyte@ORA920>
ops$tkyte@ORA920> select 'all' a , count(*) b from all_objects union all
2 select 'dba', count(*) from dba_objects
3 /

A B
--- ----------
all 29564
dba 32122



Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Thanks Tom.

gs, April 17, 2003 - 8:05 pm UTC


A reader, April 18, 2003 - 11:21 am UTC


More on DBMS_DESCRIBE

A reader, February 10, 2004 - 7:12 am UTC


How can this package be used in Stored procs to describe some objects?

Tom Kyte
February 10, 2004 - 7:14 am UTC

as it gives the same output as ALL_ARGUMENTS and I find many times SQL to be easier then a bunch of plsql tables -- i would suggest you use that documented view.


short of that, we document all supplied packages in a supplied packages guide:

</code> http://docs.oracle.com/docs/cd/B10501_01/appdev.920/a96612/d_descrb.htm#998100 <code>



More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library