Solved

RAW Data column to VARCHAR2.UTL_RAW.CAST_TO_VARCHAR2 didn't work?

Posted on 2004-08-13
2
2,180 Views
Last Modified: 2010-07-27
Hello All,
I am tying to migrate data from some existing DB tables to another.I came across a  strange problem in converting a RAW datatype to VARCHAR2/NUMBER.

The source table has got one column(friend_group_ids) which is of RAW(500) datatype.I found in the PL/SQL script which populates the values to the table as follows (snipped unnecessary code):
 friend_group_id number :=101000000
 group_id varchar2(10);

 group_id := NumbertoHex(friend_group_id, 16,8);

NumbertoHex is a user defined function which converts this number to Hex(101000000 => 06052340).

The INSERT statement in PL/SQL procedure is as follows:
insert into tst_friends (NUMERIC_ID , FRIEND_GID ,  NUM_OF_GROUPS, FRIEND_GROUP_IDS)
      values ( NUMERIC_ID , friend_gid,1 , group_id );

I understand this is possible,since it works.But is it correct to store varchar2 in RAW datatype.

Since I don't have the access to the actual tables, I created the table with the same schema structure but to insert the sample values I used the following INSERT statement:
insert into ODG_FRIENDS
(NUMERIC_ID, FRIEND_GID, NUM_OF_GROUPS, FRIEND_GROUP_IDS)
VALUES
(12003,'user05@foo.com',1,'06052340');

The INSERT was successful.

But I wanted to convert the friend_group_ids to "VARCHAR2"  back to do some manipulation  before I store the data in another table.I tried UTL_RAW.CAST_TO_VARCHAR2(friend_group_ids) but it produced some ascii characters.

May I know how can I get the column data value as "06052340"?

Thanks
Karthik

0
Comment
Question by:karthikd22
2 Comments
 

Accepted Solution

by:
suganthkumar1 earned 125 total points
ID: 11807270
hi,

declare
 v varchar2(100);
begin
 select rawtohex(col1) into v from temp;
 dbms_output.put_line(v);
end;
/

using this way, you can get the raw data in the form of hex value represented in varchar2 datatype.

when you use the UTL_RAW package, it does an ascii character mapping. that is why you got the junk characters

Have a hice day
Suganth
0
 

Author Comment

by:karthikd22
ID: 11808862
Hi Suganth,
Thanks.That worked.Once again thanks for your help.

Regards,
Karthik
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Deleting Rows from an Oracle Database - Performance 19 73
Read XML values 8 52
Oracle create type table from existing table%rowtype ? 6 61
plsql job on oracle 18 72
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question