-- ddlmeta.sql

CREATE OR REPLACE FUNCTION get_ddl_meta(tablename VARCHAR2)
 RETURN CLOB
IS
     handle NUMBER;
     temp_handle NUMBER;
     doc CLOB;
BEGIN
     handle := DBMS_METADATA.OPEN('TABLE');
     DBMS_METADATA.SET_FILTER(handle,'SCHEMA',USER);
     DBMS_METADATA.SET_FILTER(handle,'NAME',tablename);
     temp_handle := DBMS_METADATA.ADD_TRANSFORM(handle,'DDL');
     doc := DBMS_METADATA.FETCH_CLOB(handle); 
     DBMS_METADATA.CLOSE(handle);
     RETURN doc;
END;  
/
