Monday, February 04, 2008

csv file and automatic ftp

create directory yangbodir as '/oracle/';
CREATE OR REPLACE PROCEDURE printcsvreport(filedir IN VARCHAR2, filename IN VARCHAR2)
AS
filehndl UTL_FILE.FILE_TYPE;
CURSOR JobCursor IS select * from test;
vJobRecord JobCursor%RowType;
BEGIN
OPEN JobCursor;
filehndl := UTL_FILE.FOPEN(filedir,filename,'w');
FETCH JobCursor INTO vJobRecord;
while JobCursor%FOUND loop
--UTL_FILE.PUT_LINE(filehndl,'Just Heading'||' Next heading');
UTL_FILE.PUTF(filehndl,'%s %s %s %s\n', vJobRecord.id||'|'||vJobRecord.name||'|'||vJobRecord.birth||'|'||vJobRecord.description);
FETCH JobCursor INTO vJobRecord;
end loop;
CLOSE JobCursor;
UTL_FILE.FCLOSE(filehndl);
EXCEPTION
WHEN UTL_FILE.INVALID_OPERATION
THEN UTL_FILE.FCLOSE(filehndl);
-- raise a user-defined exception
RAISE_APPLICATION_ERROR(-20051,'Invalid Operation');
END;
/




begin
printcsvreport('YANGBODIR','testyangbo');
end;
/

ftp 10.10.0.180 《《EOF
user username password
cd /dbms/
lcd /oracle
put testyangbo
bye
EOF

No comments: