2. SELECT ANY TABLEreally??? wow.
1)) you are seeing that error message because you are not passing in the owner to dbms_metadata. before you get excited - when you do pass in the schema, you'll get:
ops$tkyte%ORA11GR2> create user a identified by a;
User created.
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> grant create session, select any table, select any dictionary to a;
Grant succeeded.
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> connect a/a
Connected.
a%ORA11GR2>
a%ORA11GR2> select dbms_metadata.get_ddl( 'TABLE', 'EMP' ) from dual;
ERROR:
ORA-31603: object "EMP" of type TABLE not found in schema "A"
ORA-06512: at "SYS.DBMS_METADATA", line 5088
ORA-06512: at "SYS.DBMS_METADATA", line 7589
ORA-06512: at line 1
no rows selected
a%ORA11GR2> select dbms_metadata.get_ddl( 'TABLE', 'EMP', 'SCOTT' ) from dual;
ERROR:
ORA-31603: object "EMP" of type TABLE not found in schema "SCOTT"
ORA-06512: at "SYS.DBMS_METADATA", line 5088
ORA-06512: at "SYS.DBMS_METADATA", line 7589
ORA-06512: at line 1
no rows selected
as documented here:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_metada.htm#i1016867 you would need select_catalog_role:
a%ORA11GR2>
a%ORA11GR2> connect /
Connected.
ops$tkyte%ORA11GR2> grant select_catalog_role to a;
Grant succeeded.
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> connect a/a
Connected.
a%ORA11GR2> select dbms_metadata.get_ddl( 'TABLE', 'EMP', 'SCOTT' ) from dual;
DBMS_METADATA.GET_DDL('TABLE','EMP','SCOTT')
-------------------------------------------------------------------------------
CREATE TABLE "SCOTT"."EMP"
( "EMPNO" NUMBER(4,0) NOT NULL ENABLE,
"ENAME" VARCHAR2(10),
"JOB" VARCHAR2(9),
"MGR" NUMBER(4,0),
"HIREDATE" DATE,
"SAL" NUMBER(7,2),
"COMM" NUMBER(7,2),
"DEPTNO" NUMBER(2,0)
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS NOLOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "EXAMPLE"
2)
Do you know what TOAD or any such equivalent tool might be querying internally
to get to the DDL?trace it, they are probably just querying the dictionary and doing it themselves.
3) see the dbms_metadata documentation, it very clearly listed what privileges you need at a minimum.