I'm trying the following in PLSQL:
I have a table who contain a list of table names, something like: Table_1, Table_2, Table_3, etc...
I rewrite that table on a daily basis, so the list of tables is dynamic, one day you might get 3 tables, tomorrow 7 tables and so on.
Based on that list of tables, i want to export the content of those tables using the UTL_FILE.
So far, i tried to fetch the table names into a variable and then loop over the variable, but it doesn't work.
I have the following codes:
Declare
var1 SYS_REFCURSOR;
var2 varchar2(20);
var3 varchar2(20);
ARCHIVE UTL_FILE.FILE_TYPE;
Cursor cur2 IS SELECT TABLE_NAME FROM LIST_OF_TABLES;
BEGIN
ARCHIVO:=UTL_FILE.FOPEN('test_path','test.txt','W');
for i in cur2 loop
var2:= i.table_name;
OPEN var1 for 'SELECT SKUID, CMRPRICE FROM '||VAR2;
loop
FOR C IN MICURSOR LOOP
UTL_FILE.PUT_LINE(ARCHIVE,(''||C.SKUID||''||','||''|| C.CMRPRICE||''));
END LOOP;
UTL_FILE.FCLOSE(ARCHIVE);
close var1;
end loop;
END;
i expect to obtain the same amount of files as tables on the table list
Thanks in advance
SKUID, CMRPRICE. so Is that columns exist in each table?when others then dbms_output.put_line( dbms_utility.format_error_stack ); dbms_output.put_line( dbms_utility.format_error_backtrace );just before theEND;stated at the bottm.MICURSOR? You open and close dynamic cursorvar1but you don't fetch from it.