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: Thomas J. Kyte <tkyte_at_us.oracle.com>
Date: 1996/11/26
Message-ID: <329b556d.22367112@dcsun4>#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


statements and opinions are mine and do not necessarily reflect the opinions of Oracle Corporation Received on Tue Nov 26 1996 - 00:00:00 CST

Original text of this message

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