CREATE OR REPLACE PROCEDURE write_quot_data
IS
file_handle UTL_FILE.file_type;
BEGIN
FOR T_DATE IN (SELECT TRADE_DATE FROM TEST_TRADE_DATE WHERE TRADE_DATE>=20080101 AND TRADE_DATE<=20080104 ORDER BY TRADE_DATE) LOOP
file_handle := UTL_FILE.FOPEN('txtdir',T_DATE.TRADE_DATE || '.txt','w');
FOR x IN (SELECT * FROM test2 WHERE TRADE_DATE=T_DATE.TRADE_DATE) LOOP
UTL_FILE.PUT_LINE(file_handle, X.TRADE_DATE || ',' ||to_char(nvl(X.PRICE,'0'),'FM9999990.00')|| ','||to_char(nvl(X.closeprice,'0'),'FM9999990.00') || ',' ||to_char(nvl(X.qty,'0'),'FM99999999999') );
END LOOP;
UTL_FILE.FCLOSE(file_handle);
END LOOP;
EXCEPTION WHEN OTHERS THEN