Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select codestabelecimento, nomecompletoestab, codmunicipiosae, nomemunicipio40
- from tb_estabelecimento join tb_municipio on codmunicipiosae = codmunicipio
- where nomecompletoestab like 'MANOEL%' limit 15;
- Table "public.tb_estabelecimento"
- Column | Type | Modifiers
- ------------------------------+------------------------+-----------
- codestabelecimento | integer | not null
- codmunicipiosae | smallint | not null
- nomecompletoestab | character varying(120) |
- Table "public.tb_municipio"
- Column | Type | Modifiers
- ------------------------------+-----------------------+-----------
- codmunicipio | smallint | not null
- nomemunicipio40 | character varying(40) |
- create type tp_estab_munic as (
- codestabelecimento int, nomecompletoestab varchar(120),
- codmunicipiosae int2, nomemunicipio40 varchar(40)
- );
- create function listar_estab_munic(param text) returns setof tp_estab_munic as
- $$
- declare
- rec tp_estab_munic;
- begin
- for rec in
- select codestabelecimento, nomecompletoestab, codmunicipiosae, nomemunicipio40
- from tb_estabelecimento join tb_municipio on codmunicipiosae = codmunicipio
- where nomecompletoestab like param
- limit 15
- loop
- return next rec;
- end loop;
- return;
- end
- $$ language plpgsql;
- select * from listar_estab_munic('MANOEL%');
- select * from listar_estab_munic('LUCAS%');
Add Comment
Please, Sign In to add comment