Monday, October 22, 2012

How to export java class or java resource from Oracle database

If you need to export java class or java resource loaded to Oracle database with loadjava use this:

1) get fully qualified name of a class/resource:


SELECT DBMS_JAVA.longname (object_name), user_objects.*
  FROM SYS.user_objects
 WHERE object_type IN ('JAVA CLASS', 'JAVA RESOURCE')

2) use DBMS_JAVA.export_resource or DBMS_JAVA.export_resource accordingly. This example outputs first 4000 chars only but you get the idea once you have the BLOB:

DECLARE
   v_blob      BLOB;
   stringvar   VARCHAR2 (4000);
BEGIN
   DBMS_LOB.createtemporary (v_blob, TRUE, DBMS_LOB.SESSION);

   --dbms_java.export_class( 'com/mysource/MyClass', v_Blob ) ;

   DBMS_JAVA.export_resource ('resources/resource.xml', v_blob);
   stringvar := UTL_RAW.cast_to_varchar2 (DBMS_LOB.SUBSTR (v_blob, 4000, 1));
   DBMS_OUTPUT.put_line (stringvar);
END;

No comments:

Post a Comment