0

when I ran below store procedure then it shows error. here some special char related issue ,so i cant generate xml file , here xml format same as generate XML from oracle tables

Connecting to the database DB_old.
ORA-29285: file write error
ORA-06512: at "SYS.UTL_FILE", line 148
ORA-06512: at "SYS.UTL_FILE", line 889
ORA-06512: at "DBO_17FEB.EXPOR1", line 60
ORA-06512: at line 6
Process exited.
Disconnecting from the database DB_old.



-------------------



create or replace 
PROCEDURE Expor1 
(
   V_TABLE_NAME IN varchar2
  )
AS
BEGIN
         ----- Export  table data
      DECLARE
        v_file  UTL_FILE.file_type;
        qryCtx DBMS_XMLGEN.ctxHandle;
        result CLOB;
        result1 CLOB;
        v_FILENAME varchar2(30);
      BEGIN

       IF UPPER(V_TABLE_NAME) = 'PROJECT' THEN
      qryCtx :=  dbms_xmlgen.newContext ('SELECT * from '||V_TABLE_NAME ||'' );

       ELSIF UPPER(V_TABLE_NAME) = 'LOGFILE' THEN

      qryCtx :=  dbms_xmlgen.newContext ('select LOG_ID, USER_ID,RUN_DATE,PROCESS,MPOID,MODE_,trim(STATUS) as STATUS,
                                                 trim(regexp_replace(unistr(NOTES), ''[[:punct:]] '','''')) as NOTES, 
                                                 MARKDELETED from logfile where rownum<100 ' );

       ELSE
       qryCtx :=  dbms_xmlgen.newContext ('SELECT * from '||V_TABLE_NAME ||'' );
      END IF;


      v_FILENAME :=V_TABLE_NAME;
      DBMS_XMLGEN.setMaxRows(qryCtx, 5);
         v_file := UTL_FILE.fopen('MYXML', v_FILENAME || '.xml', 'W');
       UTL_FILE.put_line(v_file, '<XML><'||v_FILENAME||'></'||v_FILENAME||'> <RECORDS>');
       -- v_file := UTL_FILE.FOPEN('MYXML', v_FILENAME|| '.xml', 'R');

       LOOP
         DBMS_XMLGEN.SETNULLHANDLING(qryCtx ,null);
         DBMS_XMLGEN.setRowSetTag(qryCtx, 0);
         DBMS_XMLGEN.setRowTag(qryCtx, 'RECORD');

      -- save the XML into the CLOB field
       result :=  DBMS_XMLGEN.getXML(qryCtx);
       --result := REPLACE( result, '<?xml version="1.0"?>','<XML><'||v_FILENAME||'>'||result1 ||'</'||v_FILENAME||'>' );
         result := REPLACE( result, '<?xml version="1.0"?>',' ');
         result := REPLACE( result, '<_x0030_>',' ');
         result := REPLACE( result, '</_x0030_>',' '); 
         --result :=trim(result);
      -- UTL_FILE.put_line(v_file, '');
       EXIT WHEN DBMS_XMLGEN.getNumRowsProcessed(qryCtx) = 0; 
          -- store the XML to a XML files
       UTL_FILE.put_line(v_file, result);
      --UTL_FILE.put_line(v_file, '</XML>');
       END LOOP; 
      UTL_FILE.put_line(v_file, '</RECORDS></XML>');
       UTL_FILE.FCLOSE(v_file);

       END; 


END Expor1;

i am not able to handle some special char like : & / ; :/ . etc please help
1
  • The error you've shown doesn't correspond with the problem you say you're having; I assume you're actually still getting ORA-31061, when you call this for LOGFILE? Commented Feb 26, 2014 at 13:25

1 Answer 1

0

The ORA-29285: file write error isn't the same character-conversion error you referred to before, which was ORA-31061: XDB error: special char to escaped char conversion failed. It really isn't clear which error you're getting; if it's the file one then the character conversion isn't relevant.

When I run your version of my code against my table, it works OK for smaller tables, and gets ORA-06502: PL/SQL: numeric or value error if result is more than 32k characters; or ORA-29285 if there is more than 32k without a line break. You've lost the looping over the clob to write it to the file in chunks. To output larger values, as I did before:

position pls_integer := 1;
chars pls_integer := 32767;
...
while position < dbms_lob.getlength(result) loop
  utl_file.put(v_file, dbms_lob.substr(result, chars, position));
  utl_file.fflush(v_file);
  position := position + chars;
end loop;

Not sure why you have an inner block (declare/begin/`end') within the procedure.

If you are getting the ORA-31061 then I'm still unclear which data is causing you a problem, but assuming that the NOTES transformation you're doing solves that and you're still seeing ORA-31061 when you call this for your LOGFILE table, then that's probably because you reset qryCtx.

You're creating that at line 23 in the code you provided as:

      qryCtx :=  dbms_xmlgen.newContext ('select LOG_ID, 
        USER_ID,RUN_DATE,PROCESS,MPOID,MODE_,STATUS,
        regexp_replace(unistr(NOTES), ''[[:punct:]]'','''') as NOTES,
        MARKDELETED from logfile' );

... but then after the if/elsif/else block where you do that, you then overwrite it at line 39 with:

      qryCtx :=  dbms_xmlgen.newContext ('SELECT * from '||V_TABLE_NAME ||'' );

So when you then call getXML(qryCtx) you aren't getting the modified values for NOTES.

Sign up to request clarification or add additional context in comments.

14 Comments

please comment this line qryCtx := dbms_xmlgen.newContext ('SELECT * from '||V_TABLE_NAME ||'' ); and i found data like "YNC 0094: DB table Project does not have a record for that <docyear> & <chg_offcl>=1" so I replace it to this " 94 CTIPS table Project does not have a record for that docyear chgoffcl1" by using function "regexp_replace(unistr()) "
@hardikrawal - the special characters in that string would be converted to &lt; etc. in the file anyway. I don't see an error with that data, either leaving it alone or with your regexp_replace(). Which error are you actually getting now? If you are getting ORA-29285 then it is nothing to do with character conversion, it's the amount of data you're trying to write out at once.
yes, how to resolve it for same store procedure currently i am facing bellow error Connecting to the database CTIPS_old. ORA-29285: file write error ORA-06512: at "SYS.UTL_FILE", line 148 ORA-06512: at "SYS.UTL_FILE", line 889 ORA-06512: at "DBO_CTIPS17FEB.EXPOR1", line 51 ORA-06512: at line 6 Process exited. Disconnecting from the database CTIPS_old.
@hardikrawal - I've already said in this answer that you need to write the result out to the file in chunks, and I've said how to do that in a loop here, and in the previous answer. The ORA-29285 is from trying to write more then 32k in one utl_file.put. Do it in a loop, with a fflush.
hi, thanks for your reply, but still i am not able to solve this issue, i has made one new store procedure for this please check it, how i will solve it. stackoverflow.com/questions/22060483/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.