Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: How to convert raw (or long raw) to varchar2 in PL/SQL?

Re: How to convert raw (or long raw) to varchar2 in PL/SQL?

From: Protasov <protasov_at_percombank.kiev.ua>
Date: 1996/11/27
Message-ID: <ABw_2domO5@percombank.kiev.ua>#1/1

>
>with 7.1.6 and up you should find a package called UTL_RAW. If you cd to
>$ORACLE_HOME/rdbms/admin and do "ls *raw*" in there, you'll find the spec and
>body.
>
>In this package there is a function utl_raw.cast_to_varchar2. It just changes
>the type information of a long raw or raw to be varchar2 (fast, no conversion).
>
>You should run the spec and body in svrmgrl or sql*dba under the sys or internal
>account.
>
>UTL_RAW is used by the procedural gateway stuff btw....
>
>
>On 26 Nov 1996 20:54:40 +0200, Protasov <protasov_at_percombank.kiev.ua> wrote:
>
>>
>>Hello all
>>
>>I want to convert raw (or long raw) data type in varchar2 data type
>>in PL/SQL. This must be an identity function - each source byte maps
>>into the equal target byte. I can propose the solution, but it is too
>>slow:
>>
>> FUNCTION RAWTOCHAR
>> ( X LONG RAW
>> ) RETURN VARCHAR2 IS
>> I INTEGER;
>> J1 INTEGER;
>> J2 INTEGER;
>> Y VARCHAR2(30000);
>> Z VARCHAR2(30000);
>> BEGIN
>> Z:=RAWTOHEX(X);
>> Y:='';
>> IF X IS NOT NULL THEN
>> I:=1;
>> WHILE I<LENGTH(Z) LOOP
>> J1:=ASCII(UPPER(SUBSTR(Z,I,1)));
>> IF 48<=J1 AND J1<=57 THEN
>> J1:=J1-48;
>> ELSE
>> J1:=J1-65+10;
>> END IF;
>> J2:=ASCII(UPPER(SUBSTR(Z,I+1,1)));
>> IF 48<=J2 AND J2<=57 THEN
>> J2:=J2-48;
>> ELSE
>> J2:=J2-65+10;
>> END IF;
>> Y:=Y||CHR(J1*16+J2);
>> I:=I+2;
>> END LOOP;
>> END IF;
>> RETURN Y;
>> EXCEPTION WHEN OTHERS THEN
>> RETURN NULL;
>> END;
>>
>>Does anybody know better solution?
>>
>> Protasov Andrew
>> email: protasov_at_percombank.kiev.ua
>>
>
>Thomas Kyte
>Oracle Government
>tkyte_at_us.oracle.com
>
>http://govt.us.oracle.com
>
>---- Check out Oracle Governments web site! -----
> Follow the link to "Tech Center"
> and then downloadable Utilities for some free software...
>
>
>-------------------
>statements and opinions are mine and do not necessarily
>reflect the opinions of Oracle Corporation
>

Hello Thomas,

Thank you very much for your information about UTL_RAW. We have Oracle Server 7.1.4 and 7.2.2. Yes, Oracle 7.1.4 does not implement this package, but Oracle 7.2.2 contains it. UTL_RAW.CAST_TO_VARCHAR2 is the solution of the problem and works fine. Now I am upgrading 7.1.4 to 7.2.2 and really happy with your help.

                                     Protasov Andrew
                                     email: protasov_at_percombank.kiev.ua
Received on Wed Nov 27 1996 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US