0

I'd like to write the data in a positional file. Only data which was not written before in a file will be written. Obviously, there's a column in the table to determine if the data has been written before.

In my case, say if the lenght of field is 80 but the length of data is 30 then rest of the space will be filled with spaces. For example,

----------------------------------------
|  Name    |    SSN      |  Integrated |
----------------------------------------
| Doe      |  453214     |     Y       |
| John     |  1234567890 |     N       |
| Scarlett |  123        |     N       |
----------------------------------------

The first record has been transferred/written in a previous file. Hence, it will not be transferred in the next file. The length of name is fixed 80 characters. So if a name is less than 80 characters then the rest of the space will be filled by spaces. It will look something like this. Same is true for other fields

Name           SSN         
John           1234567890
Scarlett       123

How may I do so? Thanks in advance. Iam using oracle 11g.

EDIT

Ok, I am able to write a code. However, I would like to call this code as a procedure which I can use in dbms_jobs. The problem is that I don't know how to write a procedure.

DECLARE
    v_file UTL_FILE.file_type;
BEGIN
    v_file := UTL_FILE.fopen('DIR_VR_AD_INTEGRATION', 'HRMtoAD1_'||sysdate, 'w', 32767);

    FOR x IN (select * from (select RPAD(user_id, 7, ' ') || ' ' || RPAD(pid_company_id, 10, ' ') str from arc_hrvr.vr_ad_integration where integrated = 'N') str where rownum <= 3 order by rownum)
    LOOP
        BEGIN
            UTL_FILE.put_line(v_file, x.str);
         END;
     END LOOP;

    UTL_FILE.fflush(v_file);
    UTL_FILE.fclose(v_file);
END;
Jaanna
  • 1,620
  • 9
  • 26
  • 46

1 Answers1

1

This is really a different question now than what you started with, and how it's titled. It's good that you've figured out the bulk of what you need to do, but this should really have been a separate question. However that would have been rather vague, so I might as well have a go at it here instead...

The documentation on procedure writing is fairly clear, and there are a lot of examples, such as this one which was the first hit on Google for 'oracle create procedure'.

At the moment you have an anonymous PL/SQL block, so you need to convert that to a stored procedure. In this case, and assuming you don't want it to be part of a package, you just need to change the DECLARE to CREATE PROCEDURE my_procedure_name AS:

CREATE PROCEDURE my_procedure_name AS
    v_file UTL_FILE.file_type;
BEGIN
   ...
END;
/
Alex Poole
  • 183,384
  • 11
  • 179
  • 318