SAK }‘ŠÙ

SAK Streets ƒƒCƒ“ƒXƒgƒŠ[ƒg }‘ŠÙEƒJƒtƒF ˆê—— SAK Streets ŒŸõ
| VB | SQL | Perl | PHP | ASP | JSP | C | PC | HP | FAQ | ƒtƒŠ[ƒ\ƒtƒg |

Oracle PL/SQL •Ò7 - •W€ƒtƒ@ƒCƒ‹ I/O utl_file.fopenAutl_file.put_line

UTL_FILE ‚ðŽg—p‚·‚é‚ÆAƒeƒLƒXƒgƒtƒ@ƒCƒ‹“üo—Í‚ð PL/SQL ‚Ås‚¦‚éB
(Oracle9i - 9.0.1 ‚Å‹@”\Šg’£‚ ‚è)

¡init.ora Ý’è

  Ej:\oracle\admin\sak\pfile\init.ora ‚É‘Š“–‚·‚é init.ora ‚É“üo—Í‚ð
    ‹–‰Â‚·‚éƒfƒBƒŒƒNƒgƒŠ‚ðŽw’肵‚È‚¢‚Æ UTL_FILE ‚̓Aƒxƒ“ƒh‚·‚éB
    Ž„‚ÍuŽíXv‚̉ӊ‚ɒljÁ‚µ‚½B

###########################################
# ŽíX
###########################################
compatible=9.0.0
db_name=sak
utl_file_dir=g:\tmp,g:\tmp2

  Eutl_file_dir=* ‚Æu*v‚ðŽw’è‚·‚é‚Æ–³§ŒÀ‚̃AƒNƒZƒX‚Æ‚È‚éB
    ‚±‚ê‚ÍA‚«‚¿‚ñ‚ÆŽw’肵‚½•û‚ªˆÀ‘S‚©‚à‚µ‚ê‚È‚¢B
    •¡”‚̃fƒBƒŒƒNƒgƒŠ‚ÍAƒJƒ“ƒ}u,v‹æØ‚è‚ÅŽw’è‚·‚éB

¡ƒtƒ@ƒCƒ‹ƒI[ƒvƒ“

declare
  fno utl_file.file_type;
begin
  fno := utl_file.fopen('g:\tmp', 'test.txt', 'R', 4002);
  |                      |         |           |   |_ ƒŒƒR[ƒh’·
  |                      |         |           |      ‰üs‚àŠÜ‚ß‚½ƒoƒCƒg’·
  |                      |         |           |      1 ` 32767
  |                      |         |           |      ŒÃ‚¢ Oracle ‚Å‚Í
  |                      |         |           |      Žw’è‚·‚é‚ƃGƒ‰[
  |                      |         |           |_ R Input
  |                      |         |              W Output
  |                      |         |              A Append
  |                      |         |_ ƒtƒ@ƒCƒ‹–¼
  |                      |_ ƒpƒX
  |_ ƒtƒ@ƒCƒ‹”Ô†

  ...
  ...
end;
/

¡ƒtƒ@ƒCƒ‹ƒNƒ[ƒY

declare
  fno utl_file.file_type;
begin
  fno := utl_file.fopen('g:\tmp', 'test.txt', 'R');
  ...
  ...
  utl_file.fclose(fno);
                  |_ ƒtƒ@ƒCƒ‹”Ô†
end;
/

¡ƒtƒ@ƒCƒ‹ƒNƒ[ƒY ALL

declare
  fno utl_file.file_type;
begin
  fno := utl_file.fopen('g:\tmp', 'test.txt', 'R');
  ...
  ...
  utl_file.fclose_all;
           |_ ƒI[ƒvƒ“’†‚Ì‘Sƒtƒ@ƒCƒ‹ƒNƒ[ƒY
end;
/

¡ƒtƒ@ƒCƒ‹ƒŠ[ƒh

declare
  fno utl_file.file_type;
  rec varchar2(1000);
begin
  fno := utl_file.fopen('g:\tmp', 'test.txt', 'R');
  begin
    loop
      utl_file.get_line(fno, rec);
                        |    |_ ƒŒƒR[ƒhƒeƒLƒXƒg
                        |_ ƒtƒ@ƒCƒ‹”Ô†
      ...
      ...
    end loop;
  exception
    when NO_DATA_FOUND then -- ƒŒƒR[ƒh AT END
      null;
    when OTHERS then
      dbms_output.put_line ('** ƒŠ[ƒhƒGƒ‰[ **');
  end;
  utl_file.fclose(fno);
                  |_ ƒtƒ@ƒCƒ‹”Ô†
end;
/

¡ƒtƒ@ƒCƒ‹ƒ‰ƒCƒg

declare
  fno utl_file.file_type;
  rec varchar2(1000);
begin
  fno := utl_file.fopen('g:\tmp', 'test.txt', 'W');
  rec := 'aaaaaaaaaaaa';
  utl_file.put_line(fno, rec);
                    |    |_ ƒŒƒR[ƒhƒeƒLƒXƒg
                    |_ ƒtƒ@ƒCƒ‹”Ô†
  utl_file.fclose(fno);
end;
/

¡ƒeƒLƒXƒgƒtƒ@ƒCƒ‹ƒŠ[ƒhƒTƒ“ƒvƒ‹

set serveroutput on;

declare
  fno utl_file.file_type;
  rec varchar2(1000);
begin
  dbms_output.put_line ('start...');
  fno := utl_file.fopen('g:\tmp', 'test.txt', 'R');
  begin
    loop
      utl_file.get_line(fno, rec);
      dbms_output.put_line (rec);
    end loop;
  exception
    when NO_DATA_FOUND then -- ƒŒƒR[ƒh AT END
      null;
    when OTHERS then
      dbms_output.put_line ('** ƒŠ[ƒhƒGƒ‰[ **');
  end;
  utl_file.fclose(fno);
  dbms_output.put_line ('end');
exception
  when OTHERS then
    dbms_output.put_line ('** ƒGƒ‰[ **');
end;
/

¡ƒŒƒR[ƒhƒOƒ‹[ƒuƒV[ƒPƒ“ƒX”Ô†‚ð•t—^‚µ‚ÄACSV Œ`Ž®‚ŃeƒLƒXƒtƒ@ƒCƒ‹o—Í

set serveroutput on;

declare
  cursor c1 is select “¾ˆÓæCD, •i”Ô
    from Žó’m order by “¾ˆÓæCD, •i”Ô;
  ct number;
  svtkcd varchar2(20) := ' ';
  fno utl_file.file_type;
  rec varchar2(1000);
begin
  dbms_output.put_line ('start...');
  fno := utl_file.fopen('g:\tmp', 'test.txt', 'W');
  for c1_rec in c1 loop
    if svtkcd != c1_rec.“¾ˆÓæCD then
      ct := 0;
      svtkcd := c1_rec.“¾ˆÓæCD;
    end if;
    ct := ct + 1;
    rec := '"' || ct
      || '","' || c1_rec.“¾ˆÓæCD
      || '","' || c1_rec.•i”Ô
      || '"';
    utl_file.put_line(fno, rec);
  end loop;
  utl_file.fclose(fno);
  dbms_output.put_line ('end');
exception
  when OTHERS then
    dbms_output.put_line ('** ƒGƒ‰[ **');
end;
/

¡Oracle PL/SQL •ÒŽ‘—¿
¡SQL Šî‘bŽÀ’n•ÒŽ‘—¿
¡SQL Šî‘b•ÒŽ‘—¿
¡SQL ƒ`ƒ…[ƒjƒ“ƒO•ÒŽ‘—¿
¡PostgreSQL •ÒAJAVA ServletAJSP •ÒŽ‘—¿
¡MySQL •ÒŽ‘—¿
| VB | SQL | Perl | PHP | ASP | JSP | C | PC | HP | FAQ | ƒtƒŠ[ƒ\ƒtƒg |

SAK Streets ƒƒCƒ“ƒXƒgƒŠ[ƒg }‘ŠÙEƒJƒtƒF ˆê—— SAK Streets ŒŸõ



Copyright (C) 1999-2024 Y.SAK