Forum Stats

  • 3,872,914 Users
  • 2,266,489 Discussions
  • 7,911,381 Comments

Discussions

need to generate SHA256 hash form xmltype column

Ateeq
Ateeq Member Posts: 21 Green Ribbon

Hi,

Oracle DB 11.2.0.4

Windows Server

I have a requirement to generate SHA256 hash of xmltype column.

I searched for solutions but found that SHA256 is supported from 12.1 onwards.

Does anyone have any alternate ideas, please let me know.


Thank You

Tagged:

Answers

  • Jason_(A_Non)
    Jason_(A_Non) Member Posts: 2,156 Gold Trophy

    Write some Java code that accepts a CLOB, performs the hashing using SHA256 and returns the result. Compile that java code on the DB server, load it into the DB, and then create a function that calls the Java. If it's possible to pass along an XMLType, you can do that as well. I only mentioned CLOB as that is the solution we use for some needed Java call-outs our application has to perform some tasks that couldn't be done in Oracle. Here are some snippets from what we setup back in the 10.1 days. The code has ran on 11.2, 18c, and 19c with a few minor tweaks. As Oracle 11.2 uses Java 1.5, whatever you write will need to be compatible with that. At least that's what an old note shows.

    Java snippet

    public class PlsqlJavaXMLUtils
    {
     public static String validateXML(CLOB xmlDoc, String schemaUrl)
     {
       return returnValue;
     }
    }
    

    Sample Java compile/load commands

    javac -deprecation -source 1.5 -target 1.5 -classpath $ORACLE_HOME/jdbc/lib/ojdbc5.jar:$ORACLE_HOME/lib/xmlcomp.jar -d $LDIR/lib $LDIR/source/PlsqlJavaXMLUtils.java
    loadjava -resolve -verbose -thin -user <uname>/<pass>@<connString> $LDIR/lib/PlsqlJavaXMLUtils.class
    

    Needed PL/SQL function definition (from a package spec)

      FUNCTION f_Validate_XML(xml IN CLOB, xsdFileURL IN VARCHAR2) RETURN VARCHAR2 IS
        LANGUAGE JAVA NAME 'PlsqlJavaXMLUtils.validateXML(oracle.sql.CLOB, java.lang.String) returns java.lang.String';