Guest User

Untitled

a guest
Feb 19th, 2018
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. select codestabelecimento, nomecompletoestab, codmunicipiosae, nomemunicipio40
  2. from tb_estabelecimento join tb_municipio on codmunicipiosae = codmunicipio
  3. where nomecompletoestab like 'MANOEL%' limit 15;
  4.  
  5.  
  6. Table "public.tb_estabelecimento"
  7. Column | Type | Modifiers
  8. ------------------------------+------------------------+-----------
  9. codestabelecimento | integer | not null
  10. codmunicipiosae | smallint | not null
  11. nomecompletoestab | character varying(120) |
  12.  
  13. Table "public.tb_municipio"
  14. Column | Type | Modifiers
  15. ------------------------------+-----------------------+-----------
  16. codmunicipio | smallint | not null
  17. nomemunicipio40 | character varying(40) |
  18.  
  19.  
  20. create type tp_estab_munic as (
  21. codestabelecimento int, nomecompletoestab varchar(120),
  22. codmunicipiosae int2, nomemunicipio40 varchar(40)
  23. );
  24.  
  25. create function listar_estab_munic(param text) returns setof tp_estab_munic as
  26. $$
  27. declare
  28. rec tp_estab_munic;
  29. begin
  30. for rec in
  31. select codestabelecimento, nomecompletoestab, codmunicipiosae, nomemunicipio40
  32. from tb_estabelecimento join tb_municipio on codmunicipiosae = codmunicipio
  33. where nomecompletoestab like param
  34. limit 15
  35. loop
  36. return next rec;
  37. end loop;
  38. return;
  39. end
  40. $$ language plpgsql;
  41.  
  42. select * from listar_estab_munic('MANOEL%');
  43. select * from listar_estab_munic('LUCAS%');
Add Comment
Please, Sign In to add comment