Click here to Skip to main content
15,886,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a simple table with one key field and some other non-key attributes. I need to generate an output file with some select query data every time i run the script. But the problem is the output file should be dynamically named on the key column it is selecting each time.

E.g. if we are selecting the [name], [age], [emp_id](pk) and [designation] of the highest salaried employee by running the script, the output file should be named
[emp_id].txt and it should contain
[name]
[age]
[emp_id]
[designation]
Posted
Updated 16-Jan-15 22:47pm
v2

1 solution

Not sure if I understood your problem correctly, but if you run the select and when looping through the result you decide the file name.

So something like:
SQL
DECLARE
  emp_rec employee%ROWTYPE;
  CURSOR cur_emp IS SELECT e.*
                    FROM   employee e
                    WHERE  ...the conditions..;
   emp_file UTL_FILE.FILE_TYPE;
BEGIN
   OPEN cur_emp;
   FETCH cur_emp INTO emp_rec;
   WHILE cur_emp%FOUND LOOP
      emp_file := UTL_FILE.FOpen('directory', TO_CHAR(emp_rec.emp_id) || '.txt','w'); 
      UTL_FILE.Put_Line(emp_file, ...data to write..., 1); 
      UTL_FILE.FClose(emp_file);    
   END LOOP;
   CLOSE cur_emp;
END; 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900