Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Create file, and export it to Network drive?

624480Apr 17 2008 — edited Apr 17 2008
Ok. I have said this a few times - I am a java developer, and I am not that great at writing procedures, or function, but I try. Here is my situation. I would like a procedure that will query a table, and output this data into a file based on the queries. So for example. I would like to output something like this:
Report Name: Date:

Total Number of Proposals Missing PSR: 247

Proposals missing PSR pending credit check: 147

proposal id      prospect id   psr/document_number   credit check  description
========         ========      ================      ============= =============
818356           434345                              fail          credit check failed
634466           134556                              fail          credit check failed
etc.....

Proposals missing PSR but credit check passed: 46
proposal id      prospect id   psr/document_number   credit check  description
========         ========      ================      ============= =============
345345            345453                           pass          credit check passed 
                                                                   but missing psr
345653            864564                           pass          credit check failed
                                                                   but missing psr

 
Proposals update with missing psr/document_number:                                     26
-----------------------------------------------------------------------------------------------------------------------------------
proposal id      prospect id   psr/document_number   credit check  description
========         ========      ================      ============= =============
778978            456473       345366                pass          proposal id [778978]
                                                                   updated with psr [345366]
944564            457756       64332                 pass          proposal id [944564]
                                                                   updated with psr [345366]
Now I would like to put this data in a file.

Once I get the file I would like to put it out on the network drive.
Now I have done this with java, but I think there is a way to do it in oracle.
I found this code
create or replace
PROCEDURE PR_OUTPUT_TOFILE IS
           file_handle UTL_FILE.FILE_TYPE; -- file handle of OS flat file
           prop_id  NUMBER;  
           c1 NUMBER(9); -- C1 retrieved from testtab table
           retrieved_buffer VARCHAR2(100); -- Line retrieved from flat file
         BEGIN
           -- Open file to write into  and get its file_handle
           file_handle :=
             UTL_FILE.FOPEN('/tmp','myTestfile.txt','W');

           -- Write a line of text out to the file.
           UTL_FILE.PUT_LINE(file_handle, 'this is line 1 as a test');

           -- Select the c1 from the sat_proposal table 
          SELECT c1 INTO prop_id FROM pon_user.sat_proposal
              WHERE proposal_id > 838300 and proposal_id < 840000;   

           -- Using PUTF write text with the col1 argument out to the file.      
           UTL_FILE.PUTF (file_handle,
              'This is the c1 %s.\n', prop_id);

           -- Close the file.
           UTL_FILE.FCLOSE(file_handle);
        
        EXCEPTION

           WHEN NO_DATA_FOUND THEN
              DBMS_OUTPUT.PUT_LINE('no_data_found');
              UTL_FILE.FCLOSE(file_handle);
           WHEN UTL_FILE.INVALID_PATH THEN
              DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_PATH');
              UTL_FILE.FCLOSE(file_handle);         
           WHEN UTL_FILE.WRITE_ERROR THEN
              DBMS_OUTPUT.PUT_LINE('UTL_FILE.WRITE_ERROR');
              UTL_FILE.FCLOSE(file_handle);
           WHEN OTHERS THEN
              DBMS_OUTPUT.PUT_LINE('other stuff');
              UTL_FILE.FCLOSE(file_handle);

END PR_OUTPUT_TOFILE;
and it puts a file out their on the oracle server in the /tmp directory that I am running from. Is there a way to get a network connection and upload this file to the mapped drive?

you know like \\nvlplace\SAT\Reports\etc

orozcom
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 15 2008
Added on Apr 17 2008
5 comments
1,365 views