473,511 Members | 12,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Utl file

3 New Member
Hi All,

I've a problem with the utl file.

I'm using put_line to write the lines into the file.

The problem is that I'm getting new line character at the end of each line which i dont want.

How to solve this problem?
Jan 17 '08 #1
6 3902
debasisdas
8,127 Recognized Expert Expert
KIndly post your code for reference of our experts.
Jan 17 '08 #2
singharvind
3 New Member
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. vfile UTL_FILE.file_type;
  3. vdata VARCHAR2 (32767);
  4. vfilename VARCHAR2 (100);
  5. vsystime VARCHAR2 (10);
  6. CURSOR wcspolicydetails IS SELECT * FROM inf_wcs_policy_sub_tab
  7. WHERE wcsb_pol_tracker_id = 489 AND wcsbph_record_type IN (2, 3);
  8. BEGIN
  9. vsystime := TO_CHAR (SYSDATE, 'hh24miss');
  10. vfilename := 'ARVINDPOL164.WCA' || vsystime;
  11. vfile := UTL_FILE.fopen ('WCS_DIR', vfilename, 'W');
  12. FOR wcspolicydetailsrec IN wcspolicydetails
  13. LOOP -- vFile := UTL_FILE.FOPEN ('WCS_DIR', vFileName, 'A');
  14. IF wcspolicydetailsrec.wcsbpt_rec_id = 1
  15. THEN
  16. vdata := RPAD ('ARVIND SINGH', 100);
  17. UTL_FILE.put_line (vfile, vdata);
  18. END IF;
  19. IF wcspolicydetailsrec.wcsbpt_rec_id = 2
  20. THEN
  21. vdata := RPAD ('RAHUL DRAVID', 100);
  22. UTL_FILE.put_line (vfile, vdata);
  23. END IF;
  24. END LOOP;
  25. UTL_FILE.fclose (vfile);
  26. EXCEPTION
  27. WHEN OTHERS
  28. THEN
  29. DBMS_OUTPUT.put_line (SQLERRM);
  30. END;
Jan 17 '08 #3
debasisdas
8,127 Recognized Expert Expert
put_line always adds new line character at the end of each line .

try to use PUT instead.

NOTE :- You must have opened the file using mode 'w' or mode 'a'; otherwise, an INVALID_OPERATION exception is raised.
Jan 17 '08 #4
Dave44
153 New Member
just be aware that if you use PUT you are limited to 32K, thats all the buffer can hold. Put_line flushes the buffer and restarts counting at 0. so if you are making small (< 32K) files you are fine. otherwise the rest of your data will simply not appear in the file.
Jan 17 '08 #5
amitpatel66
2,367 Recognized Expert Top Contributor
make use of the UTL_FILE.FFLUSH procedure to flush out the previous data in the buffer and start from zero in case if you are using UTL_FILE.PUT
Jan 18 '08 #6
subashsavji
93 New Member
Hi All,

I've a problem with the utl file.

I'm using put_line to write the lines into the file.

The problem is that I'm getting new line character at the end of each line which i dont want.

How to solve this problem?

Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE OR REPLACE PROCEDURE sal_status
  3. (p_filedir IN VARCHAR2,  p_filename IN VARCHAR2)
  4. IS
  5.  v_filehandle UTL_FILE.FILE_TYPE;
  6.  CURSOR emp_info IS
  7.    SELECT ename, sal, deptno
  8.     FROM emp
  9.     ORDER BY deptno;
  10.  v_newdeptno emp.deptno%TYPE;
  11.  v_olddeptno emp.deptno%TYPE := 0;
  12. BEGIN
  13.  v_filehandle := UTL_FILE.FOPEN (p_filedir, p_filename,'w');
  14.  UTL_FILE.PUTF (v_filehandle,'SALARY REPORT: GENERATED ON
  15.                              %s\n', SYSDATE);
  16.  UTL_FILE.NEW_LINE (v_filehandle);
  17.  FOR v_emp_rec IN emp_info LOOP
  18.   v_newdeptno := v_emp_rec.deptno;
  19. IF v_newdeptno <> v_olddeptno THEN
  20.       UTL_FILE.PUTF (v_filehandle, 'DEPARTMENT: %s\n',
  21.                      v_emp_rec.deptno);
  22.     END IF;
  23.     UTL_FILE.PUTF (v_filehandle,'  EMPLOYEE: %s earns: %s\n',
  24.                    v_emp_rec.ename, v_emp_rec.sal);
  25.     v_olddeptno := v_newdeptno;
  26.   END LOOP;
  27.   UTL_FILE.PUT_LINE (v_filehandle, '*** END OF REPORT ***');
  28.   UTL_FILE.FCLOSE (v_filehandle);
  29. EXCEPTION
  30.   WHEN UTL_FILE.INVALID_FILEHANDLE THEN
  31.     RAISE_APPLICATION_ERROR (-20001, 'Invalid File.');
  32.   WHEN UTL_FILE.WRITE_ERROR THEN
  33.    RAISE_APPLICATION_ERROR (-20002, 'Unable to write to
  34.                                      file');
  35. END sal_status;
  36. /
  37.  
  38. create OR REPLACE DIRECTORY emp_dir as 'c:\';
  39. /
  40. execute sal_status('EMP_DIR','YY.TXT'); 
  41. /
  42. execute sal_status('EMP_DIR','C:\YYY.DOC');  -- ONLY CREATES UNDER THE C:\ DRIVE
  43.  
Feb 8 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3910
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
5435
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
7
3516
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
3
26240
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
0
3910
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
13
4281
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
1
5354
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
3
3151
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
0
2536
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a...
0
2015
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.