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 |

PostgreSQL •Ò22 - PL/pgSQLAƒJ[ƒ\ƒ‹ for ƒ‹[ƒvAƒJ[ƒ\ƒ‹§ŒäAFETCH

¡select into

  Eselect into ‚ÍAOracle ‚Ì PL/SQL ‚Æ“¯“™‚Å‚ ‚éB

drop function fnctest1();
create function fnctest1() returns int as
'
declare
  ct int;
begin
  select count(*) into ct from testm;
  raise debug ''count = %'', ct;
  return ct;
end;
'
language 'plpgsql'
;

select fnctest1();

DEBUG:  count = 4
 fnctest1
----------
        4

¡ƒJ[ƒ\ƒ‹ for ƒ‹[ƒv

  Efor ƒ‹[ƒv‚Å‚Ì select ‚É‚ÍA’Êí‚Ì‚à‚Ì‚ÆAexecute ‚ðŽw’肵‚½“®“I‚È
    ‚à‚Ì‚ªŽw’è‚Å‚«‚éB
    ‚±‚ꂪˆê”ÔŠÈ’P‚ɃJ[ƒ\ƒ‹ƒ‹[ƒv‚ðì‚ê‚éB

drop function fnctest1();
create function fnctest1() returns int as
'
declare
  rec record;
begin
  for rec in select * from testm loop
    raise debug ''key = %  data1 = %'', rec.key, rec.data1;
  end loop;
  return 0;
end;
'
language 'plpgsql'
;

select fnctest1();

DEBUG:  key = a001      data1 = 1
DEBUG:  key = a011      data1 = 1
DEBUG:  key = b002      data1 = 10
DEBUG:  key = c003      data1 = 100

  Efor ƒ‹[ƒv‚Å‚Ì select ‚É execute ‚ðŽw’肵‚½ê‡‚ÍAŽŸ‚̂悤‚É‚È‚éB

drop function fnctest1();
create function fnctest1() returns int as
'
declare
  rec record;
  s varchar(20) := ''testm'';
begin
  for rec in execute ''select * from '' || s loop
    raise debug ''key = %  data1 = %'', rec.key, rec.data1;
  end loop;
  return 0;
end;
'
language 'plpgsql'
;

¡ƒJ[ƒ\ƒ‹§Œä FETCH

  EƒJ[ƒ\ƒ‹§Œä‚É‚àFX‚ȃpƒ^[ƒ“‚ª‚ ‚éB“®“I‚È‚à‚Ì‚Í execute ‚ðŽw’è
    ‚µ‚Ä—˜—p‚·‚éBŽŸ‚ÍArefcursor ‚ðŽg—p‚µ‚½—á‚Å‚ ‚éB

drop function fnctest1();
create function fnctest1() returns int as
'
declare
  cu refcursor;
  rec record;
begin
  open cu for select * from testm;
  loop
    fetch cu into rec;
    if not found then
      exit;
    end if;
    raise debug ''key = %  data1 = %'', rec.key, rec.data1;
  end loop;
  close cu;
  return 0;
end;
'
language 'plpgsql'
;

select fnctest1();

DEBUG:  key = a001      data1 = 1
DEBUG:  key = a011      data1 = 1
DEBUG:  key = b002      data1 = 10
DEBUG:  key = c003      data1 = 100

  EŽŸ‚ÍAcursor for ‚ðŽg—p‚µ‚½—á‚Å‚ ‚éB

drop function fnctest1();
create function fnctest1() returns int as
'
declare
  cu cursor for select * from testm;
  rec record;
begin
  open cu;
  loop
    fetch cu into rec;
    if not found then
      exit;
    end if;
    raise debug ''key = %  data1 = %'', rec.key, rec.data1;
  end loop;
  close cu;
  return 0;
end;
'
language 'plpgsql'
;

  EŽŸ‚ÍAcursor is ‚ÅAƒJ[ƒ\ƒ‹ƒpƒ‰ƒƒ^‚ðŽg—p‚µ‚½—á‚Å‚ ‚éB

drop function fnctest1();
create function fnctest1() returns int as
'
declare
  cu cursor (sel varchar) is select * from testm where key like sel || ''%'';
  rec record;
begin
  open cu(''a'');
  loop
    fetch cu into rec;
    if not found then
      exit;
    end if;
    raise debug ''key = %  data1 = %'', rec.key, rec.data1;
  end loop;
  close cu;
  return 0;
end;
'
language 'plpgsql'
;

  EŽŸ‚ÍAƒJ[ƒ\ƒ‹‚Å“®“I SQL ‚ðŽg—p‚µ‚½—á‚Å‚ ‚éB

drop function fnctest1();
create function fnctest1() returns int as
'
declare
  cu refcursor;
  rec record;
  s varchar(20) := ''testm'';
begin
  open cu for execute ''select * from '' || s;
  loop
    fetch cu into rec;
    if not found then
      exit;
    end if;
    raise debug ''key = %  data1 = %'', rec.key, rec.data1;
  end loop;
  close cu;
  return 0;
end;
'
language 'plpgsql'
;

¡PostgreSQL •ÒAJAVA ServletAJSP •ÒŽ‘—¿
¡MySQL •ÒŽ‘—¿
¡SQL Šî‘b•ÒŽ‘—¿
¡SQL Šî‘bŽÀ’n•ÒŽ‘—¿
¡SQL ƒ`ƒ…[ƒjƒ“ƒO•ÒŽ‘—¿
¡Oracle PL/SQL •ÒŽ‘—¿
| 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