How to open direct CSV file using TEXT_IO in oracle forms?

余生颓废 提交于 2019-12-20 06:25:13

问题


I applied this code in oracle forms 10g on trigger WHEN-BUTTON-PRESSED. This code only save the file on target location.

CODE:

PROCEDURE GEN_EXCEL IS

 IN_FILE TEXT_IO.FILE_TYPE;
 VC_HEAD Varchar2(32000);
 vc_file_path Varchar2(50) := 'C:\';

BEGIN

 IN_FILE := TEXT_IO.FOPEN(vc_file_path||'Test'||'.CSV','W'); 
 TEXT_IO.PUT_LINE(IN_FILE,'YOUR_TITLE'||chr(10));
 VC_HEAD := 'header1,header2,header3,header4';

 TEXT_IO.PUT_LINE(IN_FILE,VC_HEAD);
 FOR C1 IN ( SELECT column1, column2, column3, column4
             FROM Table_name)
 LOOP
   TEXT_IO.PUT_LINE(IN_FILE,C1.col1||','||C1.col2||','||C1.col3||','||C1.col4);

 END LOOP;

 TEXT_IO.FCLOSE(IN_FILE);
 MESSAGE('Excel file has been created!');
 MESSAGE('Excel file has been created!');

 EXCEPTION
  WHEN Others THEN
 TEXT_IO.FCLOSE(IN_FILE);
 MESSAGE('Error while writing file.');
 MESSAGE('Error while writing file.');
 END;

I want when-button-pressed then direct open CSV file from oracle forms

How to achieve this target?


回答1:


You can use webutil to do this. It has a function client_host.

Also instead of duplicating your messages you can put pause after the first message. Then you don't need the second message for a popup of the message.




回答2:


If you want to read-in your .csv file I've found a suitable solution for my problem.

Maybe it helps you too if I did understand it right what you want.

Reading From File 
March 19, 2009
--------------------------------------------------
Declare
  vfilename varchar2(500);
  in_file   Client_Text_IO.File_Type;
  linebuf   VARCHAR2(1800); 
BEGIN
    vfilename := client_get_file_name('c:/temp/', File_Filter=>'Comma Dialimeted Files (*.csv)|*.csv|'); 
    in_file := client_Text_IO.Fopen(vfilename, 'r');  
    GO_BLOCK('Emp'); 
    FIRST_RECORD;  
  LOOP
    Client_Text_IO.Get_Line(in_file, linebuf); 
    p_output_line(linebuf);
    Client_Text_IO.New_Line; 
    Next_record; 
  END LOOP; 
   FIRST_RECORD;
EXCEPTION
  WHEN no_data_found THEN
    Client_Text_IO.Put_Line('Closing the file...');
    Client_Text_IO.Fclose(in_file);
END;
-------------------------------------------------------
PROCEDURE p_output_line(p_line varchar2) IS 
vLINE VARCHAR2(4000);
vVALUE VARCHAR2(1000); 
vCOMMA_COUNT NUMBER;
vREPORT_DATE DATE;
BEGIN                    
 vLINE := p_line;
 vCOMMA_COUNT := LENGTH(vLINE)- LENGTH(REPLACE(vLINE,',','')); -- COUNT THE NUMBER OF COMMAS
  FOR I IN 1.. vCOMMA_COUNT+1 LOOP  
   vVALUE := SUBSTR(vLINE,1,INSTR(vLINE,',')-1);                             -- IF vLINE = 123,ABC,9877 THEN VVALUE WILL BE  123
    IF vVALUE IS NULL THEN
        vVALUE := vLINE;
    END IF;    
   vLINE := SUBSTR(vLINE,INSTR(vLINE,',')+1) ;                              -- CHANGE   123,ABC,9877 TO BE   ABC,9877  
   IF I = 1 THEN 
    :DATA.BMK_NAME := vVALUE; 
   ELSIF I = 2 THEN 
    vREPORT_DATE := last_day(to_date(vVALUE,'dd-mm-yyyy')); 
    :DATA.REPORT_DATE := vREPORT_DATE;
   ELSIF I = 3 THEN                 
    :DATA.BMK_RETURN := to_number(vVALUE);
   END IF;
  END LOOP; 
  EXCEPTION
    WHEN NO_DATA_FOUND THEN
    MESSAGE('Please Check the data type is appropriate on you excel file');
    MESSAGE('Please Check the data type is appropriate on you excel file');
END; 
-----------------------------------------------------------------------
-- notes
1- you must install webutil version 106 or later
2- make sure that you attached and compiled the webutill.pll scucessfuly


来源:https://stackoverflow.com/questions/53845416/how-to-open-direct-csv-file-using-text-io-in-oracle-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!