Script to Output Tables to CSV Showing Heading Only Once
You could run two queries - the first pulls the list of field names in tbl1 from user_tables and then the second query then pulls the actual data from tbl1? Spool all to the same file. Don't have a running instance of Oracle to test, but that may be a solution to your issue? Removes the need for PL/SQL - although I fail to see the difference between running a shell script and a simple PL/SQL one.