Home » SQL & PL/SQL » SQL & PL/SQL » ".." Character coming instead of "." while creating an excel spreadsheet from Oracle 10g (Oracle 10g)
".." Character coming instead of "." while creating an excel spreadsheet from Oracle 10g [message #597020] Mon, 30 September 2013 03:17 Go to next message
peterf
Messages: 5
Registered: September 2013
Location: India
Junior Member
Hello Guys,
I have a task where I have to create an excel report from the data fetched by a query. I use excel spreadheet where I write all the xml data into an clob and then mail that clob as an attachment to users. All was working fine except that this morning when users tried to open the xls file they received an error. Sad
XML ERROR in Table
REASON: Bad Value
FILE: C:\Documents and Settings\pp77403\Local Settings\Temporary Internet Files\Content.Outlook\3OD2Z8PX\actual_shift_report.xls
GROUP: Cell
TAG: Data
VALUE: 2..73

Basically what happened is that 2.73 became 2..73
I am not able to understand why this will happen. Can anyone help me pls. I am attaching the code. Basically I save an excel template as xml and then use those tags to generate a report from DB using Pl-SQL. Any help would be highly appreciated. Note : I am new to Pl-SQL programming
  • Attachment: code.txt
    (Size: 18.35KB, Downloaded 1588 times)
Re: ".." Character coming instead of "." while creating an excel spreadsheet from Oracle 10g [message #597046 is a reply to message #597020] Mon, 30 September 2013 08:53 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>All was working fine except that this morning when users tried to open the xls file they received an error.

if it was OK last week & now throws errors, then something changed.
what changed?


Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/

[Updated on: Mon, 30 September 2013 08:54]

Report message to a moderator

Re: ".." Character coming instead of "." while creating an excel spreadsheet from Oracle 10g [message #597048 is a reply to message #597020] Mon, 30 September 2013 09:38 Go to previous messageGo to next message
peterf
Messages: 5
Registered: September 2013
Location: India
Junior Member
Ok I tried a few things and I think I am getting why this Particular case is happening.

FOR i IN 0 .. TRUNC((DBMS_LOB.getlength(p_attach_clob) - 1 )/l_step) LOOP
      UTL_SMTP.write_data(l_mail_conn, DBMS_LOB.substr(p_attach_clob, l_step, i * l_step + 1));
	  
    END LOOP;


I was using the above code for adding an attachment. So the issue is happening when I reach the limit set by me using l_step. Currently I had set it to 24573. The issue happened this week because the size of the report changed and basically the buffer reached it's limit inside an xml tag. So when it wrote the data again somehow it inserted a extra decimal character. So 2.73 became 2..73 I will investigate it further.

I will keep the rules in mind next time before posting BlackSwan Smile

Re: ".." Character coming instead of "." while creating an excel spreadsheet from Oracle 10g [message #597049 is a reply to message #597048] Mon, 30 September 2013 09:41 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
thanks for the feedback
Re: ".." Character coming instead of "." while creating an excel spreadsheet from Oracle 10g [message #623611 is a reply to message #597049] Thu, 11 September 2014 17:45 Go to previous message
djbjr70
Messages: 1
Registered: September 2014
Location: Las Vegas
Junior Member
I started running into this problem and have searched high and low for a solution and this is the only forum thread where I see the same problem.

I know this thread is a little old but thought I would share my solution since this is the only other mention of it I could find....

So I finally figured out that the decimal was being repeated every time there was a chunk being written to a file that started with a decimal. The example above stated that "l_step" was set to 24573. That means every time the next position was a decimal, it would be repeated.

I rewrote the loop to check for this occurrence and adjusted the "l_step" every time it was found.

Variables Added:
l_step_default -- Currently set to 12000
l_step_max -- Set to 24573. This is to ensure we don't go over the max allowed
p_check -- BOOLEAN set to TRUE, value set to false when confirmed that the next character is no '.'
v_length -- Set to the length of the CLOB because the for i.. loop won't work here
v_parsed -- Placeholder to keep track of how many characters we have loaded.

Code Change Summary

So before that for loop opens, I check the length of the clob and place in v_length.
Then instead of the for loop I created a WHILE loop checking that the length of the CLOB is < what has been parsed already.

Then inside the loop I check if the next set to be appended to the file will start with a decimal. If this returns true, I increment the l_step by 3 until the next chunk will not start with a decimal.

I then reset the BOOLEAN and add the current l_step to the parsed variable so it will exit when complete.

The only downside here would be if every 3rd character was a decimal for 12573 characters. If that happens to be the case, I just exit out of the loop and allow the double decimal. I can't imagine a case where that would happen though.

Hope this helps, here is my code:



PROCEDURE send_mail (   p_to        IN VARCHAR2,
                                           p_from      IN VARCHAR2,
                                           p_subject   IN VARCHAR2,
                                           p_text_msg  IN VARCHAR2 ,
                                           p_attach_name  IN VARCHAR2,
                                           p_attach_clob IN CLOB) 
                                           
    
        AS
      l_mail_conn   UTL_SMTP.connection;
      l_boundary    VARCHAR2(50) := '----=*#abc1234321cba#*=';
      v_length NUMBER; 
      v_parsed NUMBER := 0; 


      l_step          PLS_INTEGER  := 12000;
      l_step_default  PLS_INTEGER  := 12000; 
      l_step_max      PLS_INTEGER  := 24573;
      p_check         BOOLEAN :=TRUE; 
      
      CURSOR cur_to IS
        WITH T AS (SELECT p_to col1 from dual)
        SELECT
        REGEXP_SUBSTR(col1,'[[:alnum:]]+[@]+[[:alnum:]]+[.]+[[:alnum:]]+',1,lvl) email
        FROM
        (
            SELECT col1,level lvl
            FROM
            t CONNECT BY level <= LENGTH(col1) - LENGTH(REPLACE(col1,',')) + 1
        );      
      
    BEGIN
          --REMOVED CODE NOT RELEVANT--

       v_length :=    DBMS_LOB.getlength(p_attach_clob);

WHILE v_length > v_parsed LOOP
    
    l_step :=l_step_default; 
 
    
        WHILE p_check LOOP
                IF 
                DBMS_LOB.substr(p_attach_clob, 1, v_parsed + l_step + 1) = '.'
                THEN
                l_step := l_step + 3;
                ELSE 
                p_check := FALSE; 
                END IF; 
                
                IF l_step = l_step_max
                THEN 
                    p_check := FALSE;
                END IF; 

        END LOOP;      
        
        p_check := TRUE;     
        
        UTL_SMTP.write_data(l_mail_conn, DBMS_LOB.substr(p_attach_clob, l_step , (v_parsed + 1)));      

    
     
     v_parsed := v_parsed + l_step;         
        
    END LOOP;

  
          --REMOVED CODE NOT RELEVANT--
Previous Topic: RAISE_APPLICATION_ERROR
Next Topic: join query
Goto Forum:
  


Current Time: Thu Apr 25 12:04:50 CDT 2024