@lily
To convert the output of an Oracle stored procedure to a CSV file, you can follow these steps:
Here is an example of how you can use these steps to convert the output of an Oracle stored procedure to a CSV file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
CREATE OR REPLACE PROCEDURE export_to_csv AS cursor c_data is select column1, column2, column3 from your_table; v_file utl_file.file_type; v_row varchar2(100); BEGIN v_file := utl_file.fopen('DIRECTORY_PATH', 'output.csv', 'W'); for r_data in c_data loop v_row := '"'||r_data.column1||'","'||r_data.column2||'","'||r_data.column3||'"'; utl_file.put_line(v_file, v_row); end loop; utl_file.fclose(v_file); END; / |
In this example, the stored procedure export_to_csv
retrieves data from the your_table
table and writes it to a CSV file named output.csv
in the specified directory path. Make sure to replace 'DIRECTORY_PATH'
with the actual directory path where you want to save the CSV file.
You can then execute the stored procedure export_to_csv
to generate the CSV file with the output of the query from the stored procedure.