我需要一个单独的SQL查询,它将从模式中检索我的所有元数据信息。我们无法在此处创建数据库链接。因此,需要从两个不同表中的模式中转储元数据,然后比较模式
答案 0 :(得分:0)
我以前为别人做过。如果你愿意,可以随意使用它。
CREATE PROCEDURE copy_prc
AS
BEGIN
NULL;
END;
CREATE FUNCTION copy_fun RETURN BOOLEAN
AS
BEGIN
RETURN TRUE;
END;
CREATE PACKAGE copy_pkg AS
PROCEDURE pkg_prc;
END copy_pkg;
CREATE PACKAGE BODY copy_pkg AS
PROCEDURE pkg_prc
AS
BEGIN
NULL;
END;
END copy_pkg;
CREATE TABLE source_codes
(
s_database VARCHAR2(30)
, s_package_name VARCHAR2(30)
, s_source_code CLOB
);
DECLARE
CURSOR objects_cur IS
SELECT object_name, DBMS_METADATA.GET_DDL(object_type, object_name) r_source_code
FROM dba_objects
WHERE owner = USER
AND object_type IN ('PROCEDURE', 'FUNCTION', 'PACKAGE')
AND object_name IN ('COPY_PRC', 'COPY_FUN', 'COPY_PKG');
TYPE objects_ntt IS TABLE OF objects_cur%ROWTYPE;
l_objects objects_ntt;
l_database_name VARCHAR2(100);
BEGIN
OPEN objects_cur;
FETCH objects_cur BULK COLLECT INTO l_objects;
CLOSE objects_cur;
l_database_name := sys_context('USERENV', 'DB_NAME');
FORALL indx IN 1..l_objects.COUNT
INSERT INTO source_codes
(
s_database
, s_package_name
, s_source_code
)
VALUES
(
l_database_name
, l_objects(indx).object_name
, l_objects(indx).r_source_code
);
COMMIT;
END;
SELECT s_database, s_package_name, DBMS_LOB.SUBSTR(s_source_code, 40)
FROM source_codes;
/*
my_db_name COPY_FUN " CREATE OR REPLACE FUNCTION "SCHEMA_NAME".""
my_db_name COPY_PKG " CREATE OR REPLACE PACKAGE "SCHEMA_NAME"."C"
my_db_name COPY_PRC " CREATE OR REPLACE PROCEDURE "SCHEMA_NAME"."
*/