I am accepting the table name and the export type from the user inside the procedure and calling the script inside the procedure. The script will accept the table name as a parameter.
------SQL SCRIPT----- edit csvfilename
set heading off
spool myfile.csv
select * from &1;
set colsep ','
spool off;
-----STORED PROCEDURE---------
SQL> CREATE OR REPLACE PROCEDURE Export_Table
2 (
3 tbl_nme IN varchar2,
4 export_type IN varchar2
5 )
6 AS
7 BEGIN
8 IF export_type = 'csv' THEN
9 EXECUTE IMMEDIATE '@csvfilename.sql tbl_name';
10 END IF;
11 END Export_Table;
12 /
Procedure created.
/
------ERROR----
SQL> EXECUTE Export_Table('Mail','csv');
BEGIN Export_Table('Mail','csv'); END;
ERROR at line 1:
ORA-00900: invalid SQL statement
ORA-06512: at "TESTADMIN.EXPORT_TABLE", line 9
ORA-06512: at line 1
Any help would be appreciated.