Create ASCII Files Using Utl - File Package
Create ASCII Files Using Utl - File Package
Create ASCII Files Using Utl - File Package
l_status := dbms_sql.execute(l_theCursor);
loop
exit when(dbms_sql.fetch_rows(l_theCursor) <= 0);
l_separator := '';
for i in 1 .. l_colCnt loop
dbms_sql.column_value(l_theCursor, i, l_columnValue);
utl_file.put(l_output, l_separator || l_columnValue);
l_separator := p_separator;
end loop;
utl_file.new_line(l_output);
l_cnt := l_cnt + 1;
dbms_application_info.set_client_info(l_cnt || ' rows are generated') ;
end loop;
dbms_sql.close_cursor(l_theCursor);
utl_file.fclose(l_output);
return l_cnt;
end dump_csv;
-------------------------------------------------------------------------------
Usage:
-------------------------------------------------------------------------------
declare
l_rows number;
begin
l_rows := dump_csv( 'select * from dba_users',
',',
'/home/demouser/output',
'users.txt' );
dbms_output.put_line( to_char(l_rows) ||
' rows extracted to ascii file' );
end;