DBMS_METADATA in 9.2.0.7
Error message DBMS_METADATA was unable to use TABLE_EXPORT to generate SQL.
Is this a BUG or there an enhanced version for Oracle 9i?
Can you outline the what you were doing, which caused this error to display?
Donal
Similar Messages
-
Not able to create an object using dbms_metadata.put function
Hi,
I have the metadata of an object in one of my database table as xml. I failed to recreate the object in the other schema using metadata api. I developed a stored function to do the above job. My function doesn't throw any error meanwhile it doesn't create the object.
My code snippet is
CREATE OR REPLACE PROCEDURE DDI.move_table(
table_name in VARCHAR2,
from_schema in VARCHAR2,
to_schema in VARCHAR2 )
AUTHID CURRENT_USER
IS
-- Define local variables.
h1 NUMBER; -- handle returned by OPEN
h2 NUMBER; -- handle returned by OPENW
th1 NUMBER; -- handle returned by ADD_TRANSFORM for MODIFY
th2 NUMBER; -- handle returned by ADD_TRANSFORM for DDL
xml XMLTYPE; -- XML document
errs sys.ku$_SubmitResults := sys.ku$_SubmitResults();
err sys.ku$_SubmitResult;
result BOOLEAN;
BEGIN
SELECT REPOS INTO xml from ddi.ddi_repos_t where obj_id = '1801';
-- Specify the object type using OPENW (instead of OPEN).
h2 := DBMS_METADATA.OPENW('TABLE');
-- First, add the MODIFY transform.
th1 := DBMS_METADATA.ADD_TRANSFORM(h2,'MODIFY');
-- Specify the desired modification: remap the schema name.
DBMS_METADATA.SET_REMAP_PARAM(th1,'REMAP_SCHEMA',from_schema,to_schema);
-- Now add the DDL transform so that the modified XML can be
-- transformed into creation DDL.
th2 := DBMS_METADATA.ADD_TRANSFORM(h2,'DDL');
-- Call PUT to re-create the object.
result := DBMS_METADATA.PUT(h2,xml,0,errs);
DBMS_METADATA.CLOSE(h2);
IF NOT result THEN
-- Process the error information.
FOR i IN errs.FIRST..errs.LAST LOOP
err := errs(i);
FOR j IN err.errorLines.FIRST..err.errorLines.LAST LOOP
dbms_output.put_line(err.errorLines(j).errorText);
END LOOP;
END LOOP;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20510,'No xml is available as metadata');
END;
Could you tell me where is the probelm?
The schema where i created and execute my function having dba privilege also.
Regards,
Madhavi.Hi Madhavi,
The below code works for me:
SQL> conn sys as sysdba
Connected.
SQL> select count(*) from dba_objects where object_name = 'DEPT' and owner = 'OE';
COUNT(*)
0
SQL> CREATE OR REPLACE PROCEDURE move_table(
2 table_name in VARCHAR2,
3 from_schema in VARCHAR2,
4 to_schema in VARCHAR2 )
5 AUTHID CURRENT_USER
6 IS
7 -- Define local variables.
8 h1 NUMBER; -- handle returned by OPEN
9 h2 NUMBER; -- handle returned by OPENW
10 th1 NUMBER; -- handle returned by ADD_TRANSFORM for MODIFY
11 th2 NUMBER; -- handle returned by ADD_TRANSFORM for DDL
12 xml clob; -- XML document
13 errs sys.ku$_SubmitResults := sys.ku$_SubmitResults();
14 err sys.ku$_SubmitResult;
15 result BOOLEAN;
16 BEGIN
17
18 select DBMS_METADATA.GET_XML('TABLE','DEPT','SCOTT') into xml from dual;
19
20 -- Specify the object type using OPENW (instead of OPEN).
21 h2 := DBMS_METADATA.OPENW('TABLE');
22
23 -- First, add the MODIFY transform.
24 th1 := DBMS_METADATA.ADD_TRANSFORM(h2,'MODIFY');
25
26 -- Specify the desired modification: remap the schema name.
27 DBMS_METADATA.SET_REMAP_PARAM(th1,'REMAP_SCHEMA',from_schema,to_schema);
28
29 -- Now add the DDL transform so that the modified XML can be
30 -- transformed into creation DDL.
31 th2 := DBMS_METADATA.ADD_TRANSFORM(h2,'DDL');
32
33 -- Call PUT to re-create the object.
34 result := DBMS_METADATA.PUT(h2,xml,0,errs);
35
36 DBMS_METADATA.CLOSE(h2);
37 IF NOT result THEN
38
39 -- Process the error information.
40 FOR i IN errs.FIRST..errs.LAST LOOP
41 err := errs(i);
42 FOR j IN err.errorLines.FIRST..err.errorLines.LAST LOOP
43 dbms_output.put_line(err.errorLines(j).errorText);
44 END LOOP;
45 END LOOP;
46 END IF;
47 EXCEPTION
48 WHEN NO_DATA_FOUND THEN
49 RAISE_APPLICATION_ERROR(-20510,'No xml is available as metadata');
50 END;
51 /
Procedure created.
SQL> exec move_table('DEPT','SCOTT','OE');
PL/SQL procedure successfully completed.
SQL> select count(*) from dba_objects where object_name = 'DEPT' and owner = 'OE';
COUNT(*)
1
SQL> spool off;The xml returned by the get_xml function contains the tablespace name and storage parameters of the schema in which the object is present.
Check these parameters for both your schemas. -
Hi,
I am using the dbms_metadata to get the DDL for all the objects in a particular schema.
DDL is retrieved without any issue, but the SQLTERMINATOR is not added in end of any DDL.
The property used is
dmsf := dbms_metadata.session_transform;
dbms_metadata.set_transform_param(dmsf, 'SQLTERMINATOR', TRUE);
Please let me know on what should i change to fix this issue.
Below is the set of code that I use.
CREATE OR REPLACE TYPE ddl_ty AS OBJECT
object_name VARCHAR2(30),
object_type VARCHAR2(30),
orig_schema VARCHAR2(30),
orig_ddl CLOB
CREATE OR REPLACE TYPE ddl_ty_tb AS TABLE OF ddl_ty
CREATE OR REPLACE FUNCTION get_object_ddl(input_values SYS_REFCURSOR)
RETURN ddl_ty_tb
PIPELINED IS
PRAGMA AUTONOMOUS_TRANSACTION;
-- variables to be passed in by sys_refcursor */
object_name VARCHAR2(30);
object_type VARCHAR2(30);
orig_schema VARCHAR2(30);
-- setup output record of TYPE tableddl_ty
out_rec ddl_ty := ddl_ty(NULL, NULL, NULL, NULL);
/* setup handles to be used for setup and fetching metadata information handles are used
to keep track of the different objects (DDL) we will be referencing in the PL/SQL code */
hopenorig NUMBER;
hmodifyorig NUMBER;
htransddl NUMBER;
dmsf PLS_INTEGER;
CLOBs to hold DDL
orig_ddl CLOB;
BEGIN
/* Strip off Attributes not concerned with in DDL. If you are concerned with
TABLESPACE, STORAGE, or SEGMENT information just comment out these few lines. */
dmsf := dbms_metadata.session_transform;
dbms_metadata.set_transform_param(dmsf, 'SQLTERMINATOR', TRUE);
dbms_metadata.set_transform_param(dmsf, 'TABLESPACE', FALSE);
dbms_metadata.set_transform_param(dmsf, 'PRETTY', TRUE);
dbms_metadata.set_transform_param(dmsf, 'STORAGE', FALSE);
-- dbms_metadata.set_transform_param(dmsf, 'SEGMENT_ATTRIBUTES', FALSE);
-- Loop through each of the rows passed in by the reference cursor
LOOP
/* Fetch the input cursor into PL/SQL variables */
FETCH input_values
INTO object_name, orig_schema, object_type;
EXIT WHEN input_values%NOTFOUND;
hopenorig := dbms_metadata.open(object_type);
dbms_metadata.set_filter(hopenorig, 'NAME', object_name);
dbms_metadata.set_filter(hopenorig, 'SCHEMA', orig_schema);
/* Modify the transformation to remove "orig_schema" reference*/
hmodifyorig := dbms_metadata.add_transform(hopenorig, 'MODIFY');
dbms_metadata.set_remap_param(hmodifyorig,
'REMAP_SCHEMA',
orig_schema,
NULL);
-- This states to created DDL instead of XML to be compared
htransddl := dbms_metadata.add_transform(hopenorig, 'DDL');
-- Get the DDD and store into the CLOB PL/SQL variables
orig_ddl := dbms_metadata.fetch_clob(hopenorig);
out_rec.object_name := object_name;
out_rec.object_type := object_type;
out_rec.orig_schema := orig_schema;
out_rec.orig_ddl := orig_ddl;
PIPE ROW(out_rec);
-- Cleanup and release the handles
dbms_metadata.close(hopenorig);
END LOOP;
RETURN;
END get_object_ddl;
SELECT *
FROM TABLE(get_object_ddl(CURSOR (SELECT object_name, owner, object_type
FROM dba_objects
WHERE owner = 'ALERTSASIA'
AND object_type IN
('PACKAGE'))));Please mark this question ANSWERED as it is a duplicate of the thread you posted in the Database General forum:
Issue in dbms_metadata.set_transform_param , SQLTERMINATOR Property -
Error while using DBMS_METADATA.GET_DDL package.
Hi all,
I want script of DDL of all tables in Database not in particular schema,
As I am using below query
SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name)
FROM ALL_TABLES u
WHERE u.nested='NO'
AND (u.iot_type is null or u.iot_type='IOT')
but it gives error as below.
ORA-31603: object "ICOL$" of type TABLE not found in schema "SCOTT"
It should give DDL of all tables, also I am not having DBA Privs.
Please help me.
Thanks & Regards
Rajiv.It could be helpful if you have a look into [url http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_metada.htm#i1016867]documentation.
Security Model
The object views of the Oracle metadata model implement security as follows:
Nonprivileged users can see the metadata of only their own objects.
SYS and users with SELECT_CATALOG_ROLE can see all objects.
Nonprivileged users can also retrieve public synonyms, system privileges granted to them, and object privileges granted to them or by them to others. This also includes privileges granted to PUBLIC.
If callers request objects they are not privileged to retrieve, no exception is raised; the object is simply not retrieved.
If nonprivileged users are granted some form of access to an object in someone else's schema, they will be able to retrieve the grant specification through the Metadata API, but not the object's actual metadata.
In stored procedures, functions, and definers-rights packages, roles (such as SELECT_CATALOG_ROLE) are disabled. Therefore, such a PL/SQL program can only fetch metadata for objects in its own schema. If you want to write a PL/SQL program that fetches metadata for objects in a different schema (based on the invoker's possession of SELECT_CATALOG_ROLE), you must make the program invokers-rights.
Best regards
Maxim -
Error using DBMS_METADATA package
Hi All,
I have the following query and trying to get the DDLs for the foreign Key constraint on tables
SELECT TO_CHAR (DBMS_METADATA.get_ddl ('CONSTRAINT', constraint_name))
|| ';'
FROM all_constraints
WHERE status = 'ENABLED'
AND table_name IN
('OD_MF_ACCT_PLCY')
ORDER BY table_name;I am getting the following error:
ORA-31603: object "ACCTROLE_FK_ACCTPLCY" of type CONSTRAINT not found in schema "D_OD"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
ORA-06512: at "SYS.DBMS_METADATA", line 2806
ORA-06512: at "SYS.DBMS_METADATA", line 4333
ORA-06512: at line 1
Note able to decipher the same. Could you help me what it means?
Thanks,
SaffThe table is in D_OD only.
But I think I got the error...Was just reading about various constant types....instead of CONSTRAINT i think I need to give REF_CONSTRAINT as the type...
This worked out
SELECT TO_CHAR (DBMS_METADATA.get_ddl ('REF_CONSTRAINT', constraint_name))
|| ';'
FROM user_constraints
WHERE status = 'ENABLED' AND constraint_type = 'R'
AND table_name IN
('OD_MF_ACCT_PLCY')
ORDER BY table_name;Thanks,
Saff
Edited by: saffron on Feb 1, 2010 1:19 PM -
hello experts,
there is an error while using above package
SQL> ED
Wrote file afiedt.buf
1* select dbms_metadata.get_ddl( 'TABLE', 'T1' ) from dual
SQL> /
select dbms_metadata.get_ddl( 'TABLE', 'T1' ) from dual
ERROR at line 1:
ORA-01024: invalid datatype in OCI call
thanks
yashit works for me.
1* select dbms_metadata.get_ddl( 'TABLE','INSANE') from dual
SQL> /
DBMS_METADATA.GET_DDL('TABLE','INSANE')
CREATE TABLE "USER1"."INSANE"
( "DEPT" NUMBER NOT NULL ENABLE,
"FIRSTNAME" VARCHAR2(30),
"SURNAME" VARCHAR2(30),
"CITY" VARCHAR2(30),
"FIRSTNAME2" VARCHAR2(30),
"SURNAME2" VARCHAR2(30),
"CITY2" VARCHAR2(30),
"FIRSTNAME3" VARCHAR2(30),
"SURNAME3" VARCHAR2(30),
DBMS_METADATA.GET_DDL('TABLE','INSANE')
"CITY3" VARCHAR2(30)
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS"
SQL> -
Stange error when using dbms_metadata.get_ddl in PL/SQL procedure
Basic info:
Oracle 10.2.0.4.0 on linux.
I'm trying to extract ddl of indexes that I drop and recreate frequently during monthly loads and store it in a table.
This statement works on the command line:
insert into saved_indexes
select index_name,dbms_metadata.get_ddl('INDEX',index_name,owner_name)
from sys.all_indexes
where owner = owner_name
and table_name = table_name;
commit;
The table 'saved_indexes' is a two column table with a varchar2(40) and a CLOB.
When I use the following procedure, I get 'ORA-04044 procedure, function, package, or type is not allowed here -4044' every time.
PROCEDURE SAVE_INDEXES (v_table IN VARCHAR2, v_owner IN VARCHAR2) IS
v_errorcode number(8);
v_errortext varchar2(1000);
v_start_time date;
BEGIN
insert into saved_indexes
select index_name,dbms_metadata.get_ddl('INDEX',index_name,v_owner)
from sys.all_indexes
where owner = v_owner
and table_name = v_table;
commit;
EXCEPTION
WHEN others THEN
v_errorcode := sqlcode;
v_errortext := substr(sqlerrm, 1, 1000);
dbms_output.put_line(v_errortext || ' ' || v_errorcode);
END;
Alternatively I have tried it this way:
PROCEDURE SAVE_INDEXES (v_table IN VARCHAR2, v_owner IN VARCHAR2 ) IS
v_errorcode number(8);
v_errortext varchar2(1000);
v_index_ddl CLOB;
BEGIN
for x in (select index_name
from sys.all_indexes
where owner = v_owner
and table_name = v_table)
loop
select dbms_metadata.get_ddl('INDEX',x.index_name,v_owner) into v_index_ddl from dual;
insert into saved_indexes
values(v_table,v_index_ddl);
end loop;
commit;
EXCEPTION
WHEN others THEN
v_errorcode := sqlcode;
v_errortext := substr(sqlerrm, 1, 1000);
dbms_output.put_line(v_errortext || ' ' || v_errorcode);
END;
Always with the same result. I have poured over the documentation on this and have not found anything. All objects are in the same schema, so there is not an issues with invokers rights, or privileges.
Any suggestions would be helpful...qwe11126 wrote:
When I use the following procedure, I get 'ORA-04044 procedure, function, package, or type is not allowed here -4044' every time.There is nothing wrong with SP. Post a snippet of SQL*Plus code showing how you call SP along with errors.
SY. -
Calling DBMS_METADATA.GET_DDL on scheduler jobs owned by SYS
Hi!
While I can generally retrieve the DDL for scheduler jobs using the PROCOBJ type, this doesn't seem to work for scheduler jobs owned by SYS.
Does anybody happen to have a workaround for this?
SELECT user FROM dual
USER
SYS
1 row selected
select * from v$version
BANNER
Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for 64-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
5 rows selected
SELECT DBMS_METADATA.GET_DDL('PROCOBJ' ,'MGMT_CONFIG_JOB', 'ORACLE_OCM') DDL FROM dual
DDL
BEGIN dbms_scheduler.create_job( ...
1 row selected
SELECT DBMS_METADATA.GET_DDL('PROCOBJ' ,'AUTO_SPACE_ADVISOR_JOB', 'SYS') DDL FROM dual
ORA-31603: object "AUTO_SPACE_ADVISOR_JOB" of type PROCOBJ not found in schema "SYS"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
ORA-06512: at "SYS.DBMS_METADATA", line 2806
ORA-06512: at "SYS.DBMS_METADATA", line 4333
ORA-06512: at line 1Cheers,
MarcusI guess I need SELECT_CATALOG_ROLE role
http://www.orafaq.com/node/807
SYS and users with SELECT_CATALOG_ROLE can see all objects. -
[RESOLVED] dbms_metadata.get_ddl() issues
Hi all,
I'm having a bit of an issue using the dbms_metadata package. I've never used it so possibly I'm unaware of something basic.
I'm getting diferent results in my production and dev servers, both of which have this configuration:
Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.6.0 - Production
I am trying to replicate the DDL for one particular schema and so tried the following:
SQL> select dbms_metadata.get_ddl('TABLE',u.table_name)
2 from user_tables u
3 where rownum = 1;
ERROR:
ORA-06502: PL/SQL: numeric or value error
LPX-00210: expected '<' instead of 'n'
ORA-06512: at "SYS.UTL_XML", line 0
ORA-06512: at "SYS.DBMS_METADATA_INT", line 3698
ORA-06512: at "SYS.DBMS_METADATA_INT", line 4553
ORA-06512: at "SYS.DBMS_METADATA", line 458
ORA-06512: at "SYS.DBMS_METADATA", line 615
ORA-06512: at "SYS.DBMS_METADATA", line 1221
ORA-06512: at line 1I tried again with hard-coding a table name and got these very scary results:
SQL> select dbms_metadata.get_ddl('TABLE','CAMPAIGN_LOOKUP','XMLUSER') FROM DUAL;
ERROR:
ORA-06502: PL/SQL: numeric or value error
ORA-31605: the following was returned from LpxXSLResetAllVars in routine
kuxslResetParams:
LPX-1: NULL pointer
ORA-06512: at "SYS.UTL_XML", line 0
ORA-06512: at "SYS.DBMS_METADATA_INT", line 3722
ORA-06512: at "SYS.DBMS_METADATA_INT", line 4553
ORA-06512: at "SYS.DBMS_METADATA", line 458
ORA-06512: at "SYS.DBMS_METADATA", line 615
ORA-06512: at "SYS.DBMS_METADATA", line 1221
ORA-06512: at line 1in the above, I am logging in as the XMLUSER user and so owns the table campaign_lookup.
Next I tried getting the DDL for another schema that while still logged in as xmluser.
I'm certain that I have access read/write from the tclient table but got these results:
possibly the dbms_metadata package requires you to be loged in as the schema owner though
the oracle documentation link gives me a 404 error at the moment so I can't check.
SQL> select dbms_metadata.get_ddl('TABLE','TCLIENT','TRAVEL') from dual;
ERROR:
ORA-31603: object "TCLIENT" of type TABLE not found in schema "TRAVEL"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
ORA-06512: at "SYS.DBMS_METADATA", line 628
ORA-06512: at "SYS.DBMS_METADATA", line 1221
ORA-06512: at line 1So now I log into production:
SQL> select dbms_metadata.get_ddl('TABLE',u.table_name)
2 from user_tables u
3 where rownum = 1;
DBMS_METADATA.GET_DDL('TABLE',
CREATE TABLE "XMLUSER"."CAMPAIGN_LOOKUP"
( "SCHEME_ID" VARCHAR2(30),
"S
etc...but still can't extract DDL for another schema.
my main issue is, I can't log into production (or our implementation environment) as the schema
I want to extract due to big nasty DBAs locking it all down. however I can in dev, but get the above errors.
thoughts anyone?Hi,
For your table not existing error it could be
1) Table not existing
or
2) Nonprivileged users can see the metadata of only their own objects.
SYS and users with SELECT_CATALOG_ROLE can see all objects
For other problem, there is a bug reported for your version, can search in metalink for workaround
Regards -
I want to mirror a schema to a existing schema by creating DDL and recreate on the other schema with same name.
I wrote the code below:
create or replace
PROCEDURE SCHEMA_A."MAI__DWHMIRROR"
AS
v_sqlstatement CLOB:='bos';
str varchar2(3999);
BEGIN
select
replace(
replace(replace(
replace(DBMS_METADATA.GET_DDL('TABLE','XXXX','SCHEMA_A'),'(CLOB)',''),';','')
,'SCHEMA_A'
,'SCHEMA_B'
into v_sqlstatement
from dual;
select CAST(v_sqlstatement AS VARCHAR2(3999)) into str from dual;
execute immediate ''||str;
END;
And Executing this block with below code:
set serveroutput on
begin
SCHEMA_A.MAI__DWHMIRROR;
end;
But still getting the following error code:
Error report:
ORA-01031: insufficient privileges
ORA-06512: at "SCHEMA_A.MAI__DWHMIRROR", line 47
ORA-06512: at line 2
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to change the current username or password
without the appropriate privilege. This error also occurs if
attempting to install a database without the necessary operating
system privileges.
When Trusted Oracle is configure in DBMS MAC, this error may occur
if the user was granted the necessary privilege at a higher label
than the current login.
*Action: Ask the database administrator to perform the operation or grant
the required privileges.
For Trusted Oracle users getting this error although granted the
the appropriate privilege at a higher label, ask the database
administrator to regrant the privilege at the appropriate label.user5199319 wrote:
USER has DBA Role
when all else fails Read The Fine Manual
DBMS_METADATA -
Dbms_metadata.get_ddl including comments.
Hey all,
Is there a way to use the dbms_metadata package to fetch the DDL of a package/function/procedure without removing the comments? For instance if you are using SQL Developer and right click a function and then click edit. The DDL for the function will appear along with the comments. This is what I would like to see.
Any ideas?
Cheers,
Tyson Jouglet
Edited by: Tyson Jouglet on Aug 27, 2009 2:29 PMIs there a way to use the dbms_metadata package to fetch the DDL of a package/function/procedure without removing the comments? Why do you think that the comments are removed?
SQL> CREATE OR REPLACE PROCEDURE p
/* first comment*/
AS
-- some comments
BEGIN
/* some other comments*/
NULL;
END p;
Procedure created.
SQL> SELECT dbms_metadata.get_ddl (
'PROCEDURE',
'P',
USER
) ddl
FROM DUAL
DDL
CREATE OR REPLACE PROCEDURE "MICHAEL"."P"
/* first comment*/
AS
-- some comments
BEGIN
/* some other comments*/
NULL;
END p;
1 row selected. -
Dbms_metadata.get_ddl
Hi
I am having issues running this oracle package within a stored procedure. I can get the code to work within a select statement. I can even get it to work within a declare/begin/end statement but as soon as i put it in a SP i get the following error.
ORA-31603: object "MESSAGE_METRICS_PK" of type INDEX not found in schema "XMS"
ORA-06512: at "SYS.DBMS_SYS_ERROR";, line 105
ORA-06512: at "SYS.DBMS_METADATA";, line 2805
ORA-06512: at "SYS.DBMS_METADATA";, line 4333
ORA-06512: at line 1
ORA-06512: at "MBLOX_DBA.SP_TEST";, line 11
ORA-06512: at line 2
I am running this from a user that has dba access and all the described privileges described within oracle. The user is trying to get the create index ddl from a different users objects. I have even given the current users direct privs to the objects within the user that owns them.
Please can someone shed some light on to what i need to give the user to beable to run dbms_metadata within a SP.
Cheers
GaryHi,
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_metada.htm#i1016867
from above doc
>
In stored procedures, functions, and definers-rights packages, roles (such as SELECT_CATALOG_ROLE) are disabled. Therefore, such a PL/SQL program can only fetch metadata for objects in its own schema. If you want to write a PL/SQL program that fetches metadata for objects in a different schema (based on the invoker's possession of SELECT_CATALOG_ROLE), you must make the program invokers-rights
>
Edited by: user6806750 on 14.10.2011 4:34 -
dbms_metadata('SCHEMA_EXPORT, ...) how to use it ?
I'm try any variants with this objecttype but always get error
ORA-31604: invalid NAME parameter "NAME" for object type SCHEMA_EXPORT in function SET_FILTER
thanksRetrieving Collections of Different Object Types
There may be times when you need to retrieve collections of objects in which the objects are of different types, but comprise a logical unit. For example, you might need to retrieve all the objects in a database or a schema, or a table and all its dependent indexes, constraints, grants, audits, and so on. To make such a retrieval possible, the Metadata API provides a number of heterogeneous object types. A heterogeneous object type is an ordered set of object types.
Oracle supplies a number of heterogeneous object types:
•TABLE_EXPORT - a table and its dependent objects
•SCHEMA_EXPORT - a schema and its contents
•DATABASE_EXPORT - the objects in the database
These object types were developed for use by the Data Pump Export utility, but you can use them in your own applications.
You can use only the programmatic retrieval interface (OPEN, FETCH, CLOSE) with these types, not the browsing interface or the submit interface.
You can specify filters for heterogeneous object types, just as you do for the homogeneous types. For example, you can specify the SCHEMA and NAME filters for TABLE_EXPORT, or the SCHEMA filter for SCHEMA_EXPORT.
Example 18-8 shows how to retrieve the object types in the scott schema.
Example 18-8 Retrieving Heterogeneous Object Types
-- Create a table to store the retrieved objects.
CONNECT scott/tiger
DROP TABLE my_metadata;
CREATE TABLE my_metadata (md CLOB);
CREATE OR REPLACE PROCEDURE get_schema_md IS
-- Define local variables.
h NUMBER; -- handle returned by OPEN
th NUMBER; -- handle returned by ADD_TRANSFORM
doc CLOB; -- metadata is returned in a CLOB
BEGIN
-- Specify the object type.
h := DBMS_METADATA.OPEN('SCHEMA_EXPORT');
-- Use filters to specify the schema.
DBMS_METADATA.SET_FILTER(h,'SCHEMA','SCOTT');
-- Request that the metadata be transformed into creation DDL.
th := DBMS_METADATA.ADD_TRANSFORM(h,'DDL');
-- Fetch the objects.
LOOP
doc := DBMS_METADATA.FETCH_CLOB(h);
-- When there are no more objects to be retrieved, FETCH_CLOB returns NULL.
EXIT WHEN doc IS NULL;
-- Store the metadata in the table.
INSERT INTO my_metadata(md) VALUES (doc);
COMMIT;
END LOOP;
-- Release resources.
DBMS_METADATA.CLOSE(h);
END;
-- Execute the procedure.
EXECUTE get_schema_md;
-- See what was retrieved.
SET LONG 9000000
SET PAGESIZE 0
SELECT * FROM my_metadata;
Note the following about this example:
The objects are returned ordered by object type; for example, all tables are returned, then all grants on tables, then all indexes on tables, and so on. The order is, generally speaking, a valid creation order. Thus, if you take the objects in the order in which they were returned and use the submit interface to re-create them in the same order in another schema or database, there will usually be no errors. (The exceptions usually involve circular references; for example, if package A contains a call to package B, and package B contains a call to package A, then one of the packages will need to be recompiled a second time.)
Edited by: sac on Sep 16, 2009 4:51 PM -
Dbms_metadata.get_ddl and select_catalog_role
Hi,
We have been requested to give support staff the ability to see table triggers, stored procedures, etc only for specific schemas and they don't have access to the schema password. We can't give them SELECT_CATALOG_ROLE because they are not allowed to see all schemas. I wish there were a way to grant a version of SELECT_CATALOG_ROLE for only certain schemas......
I've played around with dbms_metadata.get_ddl with no luck (as per the documentation, but just had to try it anyway). I've even considered the script below, but it requires creating a view under the SYS schema and I can't figure out how to add triggers to the view.
Any ideas would be greatly appreciated!
Thanks,
Susan
accept 1 prompt "Enter Owner:"
create or replace view all_dev_source
(OWNER, NAME, TYPE, LINE, TEXT)
as
select u.name, o.name,
decode(o.type#, 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
11, 'PACKAGE BODY', 13, 'TYPE', 14, 'TYPE BODY',
'UNDEFINED'),
s.line, s.source
from sys.obj$ o, sys.source$ s, sys.user$ u
where
u.name = upper('&&1') and
o.obj# = s.obj#
and o.owner# = u.user#
and o.type# in (7, 8, 9, 11, 13, 14)
and
o.owner# in (userenv('SCHEMAID'), 1 /* PUBLIC */)
or
(o.type# = 7 or o.type# = 8 or o.type# = 9)
and
o.obj# in (select obj# from sys.objauth$
where grantee# in (select kzsrorol from x$kzsro)
and privilege# = 12 /* EXECUTE */)
or
exists
select null from sys.sysauth$
where grantee# in (select kzsrorol from x$kzsro)
and
/* procedure */
(o.type# = 7 or o.type# = 8 or o.type# = 9)
or
privilege# = -144 /* EXECUTE ANY PROCEDURE */
or
privilege# = -141 /* CREATE ANY PROCEDURE */
or
/* package body */
o.type# = 11 or
privilege# = -141 /* CREATE ANY PROCEDURE */
or
/* type */
o.type# = 13
or
privilege# = -184 /* EXECUTE ANY TYPE */
or
privilege# = -181 /* CREATE ANY TYPE */
or
/* type body */
o.type# = 14 and
privilege# = -181 /* CREATE ANY TYPE */
union
select u.name, o.name, 'JAVA SOURCE', s.joxftlno, s.joxftsrc
from sys.obj$ o, x$joxfs s, sys.user$ u
where
u.name = upper('&&1') and
o.obj# = s.joxftobn
and o.owner# = u.user#
and o.type# = 28
and
o.owner# in (userenv('SCHEMAID'), 1 /* PUBLIC */)
or
o.obj# in (select obj# from sys.objauth$
where grantee# in (select kzsrorol from x$kzsro)
and privilege# = 12 /* EXECUTE */)
or
exists
select null from sys.sysauth$
where grantee# in (select kzsrorol from x$kzsro)
and
/* procedure */
privilege# = -144 /* EXECUTE ANY PROCEDURE */
or
privilege# = -141 /* CREATE ANY PROCEDURE */
comment on table all_dev_source is
'Current source on stored objects that user is allowed to create'
comment on column all_dev_source.OWNER is
'Owner of the object'
comment on column all_dev_source.NAME is
'Name of the object'
comment on column all_dev_source.TYPE is
'Type of the object: "TYPE", "TYPE BODY", "PROCEDURE", "FUNCTION",
"PACKAGE", "PACKAGE BODY" or "JAVA SOURCE"'
comment on column all_dev_source.LINE is
'Line number of this line of source'
comment on column all_dev_source.TEXT is
'Source text'
grant select on all_dev_source to <username>
/user632322 wrote:
I think I am misunderstanding your reply becauseI had to be more specific. By "privileged user" I meant SYS. SELECT_CATALOG_ROLE is a role itself, so it will be ignored by definer rights SP/SF. That is why it has to be owned by privileged user SYS:
SQL> select * from v$version
2 /
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL> show user
USER is "SYS"
SQL> create user u1 identified by u1 default tablespace users quota unlimited on users
2 /
User created.
SQL> grant create session to u1
2 /
Grant succeeded.
SQL> create or replace
2 function get_ddl(
3 p_type varchar2,
4 p_object varchar2,
5 p_owner varchar2
6 )
7 return clob
8 is
9 begin
10 return dbms_metadata.get_ddl(p_type,p_object,p_owner);
11 end;
12 /
Function created.
SQL> grant execute on get_ddl to u1
2 /
Grant succeeded.
SQL> connect u1/u1
Connected.
SQL> set serveroutput on
SQL> exec dbms_output.put_line(dbms_metadata.get_ddl('TABLE','EMP','SCOTT'));
BEGIN dbms_output.put_line(dbms_metadata.get_ddl('TABLE','EMP','SCOTT')); END;
ERROR at line 1:
ORA-31603: object "EMP" of type TABLE not found in schema "SCOTT"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
ORA-06512: at "SYS.DBMS_METADATA", line 2806
ORA-06512: at "SYS.DBMS_METADATA", line 4333
ORA-06512: at line 1
SQL> exec dbms_output.put_line(sys.get_ddl('TABLE','EMP','SCOTT'));
CREATE TABLE "SCOTT"."EMP"
( "EMPNO" NUMBER(4,0),
"ENAME" VARCHAR2(10),
"JOB" VARCHAR2(9),
"MGR" NUMBER(4,0),
"HIREDATE" DATE,
"SAL"
NUMBER(7,2),
"COMM" NUMBER(7,2),
"DEPTNO" NUMBER(2,0),
CONSTRAINT
"PK_EMP" PRIMARY KEY ("EMPNO")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS
2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE,
CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")
REFERENCES "SCOTT"."DEPT" ("DEPTNO") ENABLE
) PCTFREE 10 PCTUSED 40 INITRANS
1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576
MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT)
TABLESPACE "USERS"
PL/SQL procedure successfully completed.
SQL> Now one more correction to my previous reply. Driver table shoudl not be owned by SYS (that would be bad practice). Create it in some other schema. Just make sure your "support staff" has no access to it.
SY. -
DBMS_METADATA.GET_DDL performance
Hi
My application need to run on a schema and get all the DDL of the schema objects.
This action is very heavy on the server and I get 100% on the server CPU.
my code look something like this:
SELECT
D.OBJECT_NAME,
D.OBJECT_TYPE,
TRIM(SYS.DBMS_METADATA.GET_DDL(REPLACE(REPLACE(OBJECT_TYPE,'DATABASE LINK','DB_LINK'),' ','_'),OBJECT_NAME,USER)) AS OBJECTCREATIONSCRIPT
FROM SYS.USER_OBJECTS D
INNER JOIN TEMPOBJECTSLIST OL
ON OL.DBOBJECT_NAME = D.OBJECT_NAME
AND OL.DBOBJECT_TYPE = D.OBJECT_TYPE
WHERE OBJECT_TYPE IN('TABLE', 'VIEW', 'FUNCTION', 'PROCEDURE', 'PACKAGE', 'PACKAGE BODY', 'SEQUENCE', 'TYPE', 'SYNONYM', 'MATERIALIZED VIEW', 'DATABASE LINK', 'TYPE BODY', 'TRIGGER')
Is ther any way to do this faster?
I was thinking on some ways but I do not know how to implement them:
1. working on paralel CPU - The action acording to Enterprise Manager is taking 100% of 1 of 4 CPUs.
2. Add some indexes or run statistics on some where in the database.
3. some other options...
thanksThanks, But I can't use an incremental table for this action becouse of some business logical restrictions of my application.
the application need to do the same action as GET_DDL for all the schema objects like one schema snapshot.
I have a new idea of solving this issue, perhaps someone could help me who to implement it (if it possible):
DMBS_METATDATA package has a procedure GET_XML this procedure is match faster than GET_DDL.
Is ther any way to convert the XML result of GET_XML to a DDL script?
Edited by: rronen on 00:06 01/09/2010
Edited by: rronen on 00:06 01/09/2010 -
DBMS_METADATA.GET_DDL and Materialized View
hi gurus,
In 10gR2, i have created a materialized view EMP_MV with a simple structure.
I wanted to get the DDL of EMP_MV.
I used DBMS_METADATA to get the DDL,
select DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW','EMP_MV','TARGET') into v_return from dual;
Output
CREATE MATERIALIZED VIEW "TARGET"."EMP_MV"
ORGANIZATION HEAP PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "TARGET_TS_01"
BUILD IMMEDIATE
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "TARGET_TS_01"
REFRESH FAST ON DEMAND
WITH PRIMARY KEY USING DEFAULT LOCAL ROLLBACK SEGMENT
DISABLE QUERY REWRITE
AS select empid,empname,address from web.emp
Is there any way to get only SELECT part of this MV, ie select empid,empname,address from web.emp directly from dictionary without any string manipulation?
tia,
newbieYes you can do it. By using INSTR and SUBTR against the result of GET_DDL function
Try this:
select substr(DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW','EMP_MV','TARGET'),instr(DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW','EMP_MV','TARGET'),'select'),1000)
into v_return from dual;- - - - - - - - - - - - - - - - - - - - -
Kamran Agayev A. (10g OCP)
http://kamranagayev.wordpress.com
[Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]
Maybe you are looking for
-
Hi! My powerbook was damaged & the insurers have returned my hard drive and are supplying me with a new MacBook Pro. The data on the Hard drive is encrypted with FileVault from 10.3.someting..... What's the best way to proceed, with regards to gettin
-
Hi there Hope everyone is doing well...... I have been trying to get this to work but cant figure it out...... First.... What I want is to be able to put an 'on sale' image ...... preferably an animated gif.... (little red flame circle with animated
-
Inter company Billing for service industry
Hi, I never workded over inter company billing.Please suggest me what to do? I am in a service industry project where no delivery takes place.So how should i go about for intercompany billing configuration? Thanx in advance. Regardds, Satya
-
Connection Failed--can anyone understand Netstat routing info?
Folks: Been chasing the problem of trying to get my two listed computers to connect by ethernet/Connect to Server with AFP and entering the IP address manually--which worked in 10.3.9. With 10.4.6 -- to 4.9 so far none of the Tiger OS are able to do
-
Magic mouse batteries drops fast, help!
is there anyway to solve this problem? in the mac store they told me that the batteries may last about 2 or 3 months aprox. but i think that's not true, put new ones and in less than a month they are dead. i tried 4 brands and still the same thing.