CREATE OR REPLACE FUNCTION DECRYPT (xData in varchar2, xKey in varchar2) return varchar2 is
   yData  varchar2(256);
   zData  varchar2(256);
   xFill  varchar2(256):=null;
   xLargo number(3):=length(xData);
BEGIN
   DBMS_OBFUSCATION_TOOLKIT.DESENCRYPT(INPUT_STRING => lpad(' ', 8),
                                       KEY_STRING => xKey, ENCRYPTED_STRING => xFill);
   DBMS_OBFUSCATION_TOOLKIT.DESDECRYPT(INPUT_STRING => xData,
                                       KEY_STRING => xKey, DECRYPTED_STRING => yData);
   DBMS_OBFUSCATION_TOOLKIT.DESDECRYPT(INPUT_STRING => yData,
                                       KEY_STRING => xKey, DECRYPTED_STRING => zData);
   For i in reverse 1..7
   loop
      if substr(zData, xLargo-i+1, i)=Substr(XFill,1,i) then
         xLargo:=xLargo-i;
         exit;
      end if;
   end loop;
   return substr(zData, 1, xLargo);
END;
/

CREATE OR REPLACE FUNCTION ENCRYPT (xData in varchar2, xKey in varchar2) return varchar2 is
   yData  varchar2(256);
   zData  varchar2(256);
   xFill  varchar2(256):=null;
   xLargo number(3):=length(xData);
BEGIN
   if Mod(xLargo,8)!=0 then
      DBMS_OBFUSCATION_TOOLKIT.DESENCRYPT(INPUT_STRING => lpad(' ',8) ,
                                          KEY_STRING => xKey, ENCRYPTED_STRING => xFill);
      xFill:=substr(xFill, 1, 8-mod(xlargo,8));
   end if;
   DBMS_OBFUSCATION_TOOLKIT.DESENCRYPT(INPUT_STRING => xData||xFill,
                                       KEY_STRING => xKey, ENCRYPTED_STRING => yData);
   DBMS_OBFUSCATION_TOOLKIT.DESENCRYPT(INPUT_STRING => '12345678',
                                       KEY_STRING => 'abcdefgh', ENCRYPTED_STRING => XFill);
   DBMS_OBFUSCATION_TOOLKIT.DESENCRYPT(INPUT_STRING => yData,
                                       KEY_STRING => xKey, ENCRYPTED_STRING => zData);
   return zData;
END;
/

CREATE OR REPLACE FUNCTION DUMPH (x varchar2) RETURN varchar2 IS
   y varchar2(256);
BEGIN
   select dump(x) into y from dual;
   return y;
END;
/

CREATE OR REPLACE FUNCTION PI return number is
begin
   return 3.1415926535897932384626433832795;
end;
/

CREATE OR REPLACE FUNCTION CNVMED(x in number, mori in varchar2, mdes in varchar2) RETURN number IS
BEGIN
   return convmedida.convertir(x, mori, mdes);
END;
/

drop function cnv;
drop synonym cnv;

drop function cnvmon$;
drop synonym cnvmon$;
CREATE OR REPLACE FUNCTION CNVMONS(x in number, mori in varchar2, mdes in varchar2) RETURN number IS
BEGIN
   return convmoneda.convertir(x, mori, mdes);
END;
/
drop function cnv$;
drop synonym cnv$;

CREATE OR REPLACE FUNCTION CNVMON(x in number, tori in number, tdes in number) RETURN number IS
BEGIN
   return convmoneda.convertir(x, tori, tdes);
END;
/

CREATE OR REPLACE FUNCTION Xxname(Xfile bfile) RETURN varchar2 IS
   Xdir  varchar2(60);
   Xname varchar2(60);
BEGIN
   dbms_lob.FILEGETNAME(Xfile, Xdir, Xname);
   return Xdir||'/'||Xname;
END;
/

Drop function SqlErrm;
Create or replace FUNCTION SqlErrMsg(x number) RETURN varchar2 IS
BEGIN
   return sqlerrm(x);
END;
/
