ORA-06502: PL/SQL: numeric or value error: hex to raw conversion error

I am getting the above  error here. How do I convert a rowtype to a varchar            

DBMS_LOB.writeappend(r_data, length(sll_rec.OracleRow), UTL_RAW.CAST_TO_VARCHAR2         (sll_rec.OracleRow));  ------------------------------------------------------------------------------------------------------------------       


function    createOracleFile ()

       cursor sll_cur is

        SELECT *from employees

sll_rec sll_cur%ROWTYPE ;

r_data CLOB;


     open sll_cur;

         fetch sll_cur into sll_rec;
         exit when sll_cur%NOTFOUND;

                 -- I am getting an error here
       DBMS_LOB.writeappend(r_data, length(sll_rec.OracleRow), UTL_RAW.CAST_TO_VARCHAR2         (sll_rec.OracleRow));         

       END LOOP;

       return r_data;

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tech_questionAuthor Commented:
I found what the error is, I had to add this statement but still I do not get the entire data that is being returned by the query ,  dbms_lob.createtemporary(lob_loc => r_data, cache=> TRUE, dur=> DBMS_LOB.call) !

How can I get the entire data returned by the query !
Mark GeerlingsDatabase AdministratorCommented:
"How do I convert a rowtype to a varchar?"  I'm not sure that is supported in Oracle, are you?

If what you want is a varchar (or varchar2) variable (or variables) that contain the contents of a particular database row, one option would be to declare varchar2 variables corresponding to each column in the table, then change your cursor from "select * from..." to: "select [column1], [column2], etc. from...", and change your "fetch" to:
  fetch sll_cur into [variable1], [variable2], etc.
ROW type only can convert with varchar(char) or nvarchar(nchar). Other types as date, number etc will fail to cast into row directly.

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

sorry, the above was wrong as I looked at the wrong place.

>> UTL_RAW.CAST_TO_VARCHAR2(sll_rec.OracleRow)

     function UTL_RAW.CAST_TO_VARCHAR2()  normally accept RAW datatype. If you pass in other datatype, it will do implicit conversion using hextoraw function.
     The error is triggered by hextoraw function.

      Try this:
      select utl_raw.cast_to_varchar2('31') from dual

      you will get '1'

     but this:
     select utl_raw.cast_to_varchar2(' 1') from dual
     you will get error which is about the same you got.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
%ROWTYPE hardly convert with raw or varchar , you might add each column value in as markgeer suggested.
I think it is related to your other question. I believe that you already got it and wrote your column value directly.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.