Question

I use TOAD for executing my procedures and running my PL/SQL scripts.

Recently, I tried the dbms_obfuscation_toolkit.md5() function in PL/SQL to retrieve encrypted text of the string I pass as a parameter. I found that, the function gives the proper result when I call the function as a separate statement. However, when I call it via a SELECT query, it does not respond the same format.

Below, I have mentioned this peculiar case with the results that appear once I run it in TOAD application.

--CASE:1 (Proper result is obtained here)
DECLARE
vinput  varchar2(255) := 'SRINI';
well    varchar2(50);
BEGIN
    WELL := DBMS_OBFUSCATION_TOOLKIT.MD5(input_string =>VINPUT);
    dbms_output.put_line(well);
END;

Output: Áýg¿Zq!Ù´¿Ke>ÏQ

--CASE:2 (Unexpected response is obtained here)
DECLARE
vinput  varchar2(255) := 'SRINI';
well    varchar2(50);
BEGIN
    SELECT DBMS_OBFUSCATION_TOOLKIT.MD5(VINPUT)
        INTO    WELL
    FROM    DUAL;    
    dbms_output.put_line(well);
END;

Error Output: ORA-06550: line 5, column 37: PLS-00307: too many declarations of 'MD5' match this call ORA-06550: line 5, column 12: PL/SQL: ORA-00904: "DBMS_OBFUSCATION_TOOLKIT"."MD5": invalid identifier ORA-06550: line 5, column 5: PL/SQL: SQL Statement ignored

Why is there such a disparity in the results, even though both of them are syntactically and semantically correct ? Please provide your opinion and feedback.

Was it helpful?

Solution

Your function calls are not identical, syntactically nor semantically. If you call the function in PL/SQL as you did in SQL, you will get the same exact error:

SQL> DECLARE
  2     vinput VARCHAR2(255) := 'SRINI';
  3     well   VARCHAR2(50);
  4  BEGIN
  5     WELL := DBMS_OBFUSCATION_TOOLKIT.MD5(vinput);
  6     dbms_output.put_line(well);
  7  END;
  8  /

ORA-06550: Ligne 5, colonne 12 :
PLS-00307: too many declarations of 'MD5' match this call

This is because the function called MD5 is overloaded in the package DBMS_OBFUSCATION_TOOLKIT and you need to specify which function exactly to call.

In Oracle 11g, you can use the same synthax as PL/SQL:

SQL> DECLARE
  2     vinput VARCHAR2(255) := 'SRINI';
  3     well   VARCHAR2(50);
  4  BEGIN
  5     SELECT DBMS_OBFUSCATION_TOOLKIT.MD5(input_string => VINPUT)
  6       INTO WELL FROM DUAL;
  7     dbms_output.put_line(well);
  8  END;
  9  /

Áýg¿Zq!Ù´¿Ke>ÏQ

PL/SQL procedure successfully completed

Before 11g, you can define a wrapper function:

SQL> CREATE OR REPLACE FUNCTION wrap_md5(input_string VARCHAR2)
  2     RETURN dbms_obfuscation_toolkit.varchar2_checksum
  3  IS
  4  BEGIN
  5     RETURN dbms_obfuscation_toolkit.md5(input_string => input_string);
  6  END;
  7  /

Function created

SQL> DECLARE
  2     vinput VARCHAR2(255) := 'SRINI';
  3     well   VARCHAR2(50);
  4  BEGIN
  5     SELECT wrap_md5(VINPUT)
  6       INTO WELL FROM DUAL;
  7     dbms_output.put_line(well);
  8  END;
  9  /

Áýg¿Zq!Ù´¿Ke>ÏQ

PL/SQL procedure successfully completed

OTHER TIPS

select dbms_obfuscation_toolkit.md5(input_string => 'SRINI') from dual; use this in select for the such type of function uses input string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top