oracle - How to make a copy of a database package -
i have package (potentially, many) i'd copy new package different name.
ideally i'd run this:
begin copy_package('my_package_name','my_package_name$bk'); end; /
this find package named my_package_name
, , create/replace new package called my_package_name$bk
references my_package_name
(if any) changed on well.
it reasonable assume package names not case-sensitive, , references package name in source either uppercase or lowercase (i.e. there won't references my_package_name
in source).
this procedure copy specified package, replacing references package name (all uppercase or lowercase) goes - including references in comments.
procedure copy_package (old_name in varchar2 ,new_name in varchar2 ) ddl clob; begin ddl := dbms_metadata.get_ddl (object_type => 'package_spec' ,name => old_name ); ddl := replace(ddl, upper(old_name), upper(new_name)); ddl := replace(ddl, lower(old_name), lower(new_name)); execute immediate ddl; ddl := dbms_metadata.get_ddl (object_type => 'package_body' ,name => old_name); ddl := replace(ddl, upper(old_name), upper(new_name)); ddl := replace(ddl, lower(old_name), lower(new_name)); execute immediate ddl; end copy_package;
if new package name exists in schema, overwritten without warning.
the old package left untouched.
if there grants or synonyms needed, not copied across.
if package has code happens include package name within longer identifier (e.g. not_my_package_name
) fail replace text indiscriminately.
if package spec or body greater 32k in size, procedure fail.
if package spec or body not found, procedure raises ora-31603. if spec found body not, spec copied, , raise exception.
Comments
Post a Comment