Monday, 15 August 2011

iterating thru cursor in Oracle -



iterating thru cursor in Oracle -

i've found question @ http://dba.stackexchange.com/questions/3587/oracle-automate-export-unload-of-data. valid utilize such construction:

for r in (select * table) loop utl_file.put_line(lffilelog, r.row); end loop;

i'm trying utilize this:

create or replace procedure p_name(destfolder in varchar2, filename in varchar2) v_filehandle utl_file.file_type; cursor dataset select field1, field2, fieldn table1, table2, (select field3 table3); -- clause ... , on.. begin v_filehandle := utl_file.fopen(destfolder, filename, 'w'); r in dataset loop utl_file.put_line(v_filehandle, r.row); end loop; end; /

and getting pls-00302 error states should have defined row component. far undrestand field should exist in query. right?

can write row cursor?

the reply mentionned not complete, think given illustration (pseudo-code) lacks implementation details.

as is:

your select clause invalid, aren't selecting anything. want select? the build xx.row xx cursor doesn't exist furthermore, utl_file.get_line procedure accepts varchar2 sec argument, not kind of rowtype you can't name table table (although name "table").

given table mytable(col1, col2, ... , coln) write:

create or replace procedure p_name() v_filehandle utl_file.file_type; cursor dataset select col1, col2, /*...*/ coln mytable; begin /*utl_file.fopen maybe?*/ r in dataset loop utl_file.put_line(v_filehandle, r.col1 ||';'|| r.col2 /*...*/ || r.coln); end loop; end;

oracle cursor

No comments:

Post a Comment