Então teste assim:

select anomesInc('200603', 10);

Aqui vai legal.

Em 27/04/06, Nelson Pereira Júnior<[EMAIL PROTECTED]> escreveu:
> Compilei e testei a sua função chamando-a:
>
> select anomesInc('POGSQL', 10);
>
> Deu o mesmo erro que a minha função:
>
> ERROR:  syntax error at or near "continue" at character 1
> QUERY:  continue
> CONTEXT:  PL/pgSQL function "anomesinc" line 8 at SQL statement
>
>
> ----- Original Message -----
> From: "Ribamar Sousa" <[EMAIL PROTECTED]>
> To: <[email protected]>
> Sent: Thursday, April 27, 2006 11:58 AM
> Subject: Re: [PostgreSQL-Brasil] CONTINUE num loop com PSPGSQL
>
>
> Acredito que ajuda quando se envia o código testado.
> Veja este que roda sem erro com continue:
>
> CREATE or REPLACE FUNCTION anomesInc(char(6),integer) RETURNS char(6) AS '
> DECLARE
>     anomes ALIAS for $1;
>     n ALIAS for $2;
>     ano integer;
>     mes integer;
> BEGIN
>     FOR i in 1..n LOOP
> continue;
>     end loop;
>     ano := substr(anomes, 1, 4)::integer;
>     mes := substr(anomes, 5, 2)::integer;
>     FOR i in 1..n LOOP
>         mes := mes + 1;
> --continue;
>         IF mes = 13 THEN
>             mes := 1;
>             ano := ano + 1;
>         END IF;
>     END LOOP;
>     RETURN ano::text || lpad(mes::text,2,''0'');
> END;
> ' LANGUAGE plpgsql;
>
> 2006/4/27, Nelson Pereira Júnior <[EMAIL PROTECTED]>:
> > Na documentação diz pra eu usar como descrevo abaixo. Compilo e naum da
> > erros, mas quando vou fazer o select, dá erro, dizendo
> >
> > ERROR:  syntax error at or near "continue" at character 1
> > QUERY:  continue when  $1
> > CONTEXT:  PL/pgSQL function "lex_lista_pessoa" line 51 at SQL statement
> >
> > while true loop
> >
> >     instrução;
> >     instrução;
> >
> >     continue when id > 50;
> >
> >     instrução;
> >     instrução;
> >
> > end loop;
> >
> > ----- Original Message -----
> > From: "Ribamar Sousa" <[EMAIL PROTECTED]>
> > To: <[email protected]>
> > Sent: Thursday, April 27, 2006 10:12 AM
> > Subject: Re: [PostgreSQL-Brasil] CONTINUE num loop com PSPGSQL
> >
> >
> > Da documentação oficial:
> >
> > Inclusive o contínue.
> >
> > P.S.: Pelo que entendi, você precisa sair da iteração atual e não do loop.
> >
> > 36.7.3. Simple Loops
> >
> > With the LOOP, EXIT, CONTINUE, WHILE, and FOR statements, you can
> > arrange for your PL/pgSQL function to repeat a series of commands.
> > 36.7.3.1. LOOP
> >
> > [ <<label>> ]
> > LOOP
> >     statements
> > END LOOP [ label ];
> >
> > LOOP defines an unconditional loop that is repeated indefinitely until
> > terminated by an EXIT or RETURN statement. The optional label can be
> > used by EXIT and CONTINUE statements in nested loops to specify which
> > loop the statement should be applied to.
> > 36.7.3.2. EXIT
> >
> > EXIT [ label ] [ WHEN expression ];
> >
> > If no label is given, the innermost loop is terminated and the
> > statement following END LOOP is executed next. If label is given, it
> > must be the label of the current or some outer level of nested loop or
> > block. Then the named loop or block is terminated and control
> > continues with the statement after the loop's/block's corresponding
> > END.
> >
> > If WHEN is specified, the loop exit occurs only if expression is true.
> > Otherwise, control passes to the statement after EXIT.
> >
> > EXIT can be used with all types of loops; it is not limited to use
> > with unconditional loops. When used with a BEGIN block, EXIT passes
> > control to the next statement after the end of the block.
> >
> > Examples:
> >
> > LOOP
> >     -- some computations
> >     IF count > 0 THEN
> >         EXIT;  -- exit loop
> >     END IF;
> > END LOOP;
> >
> > LOOP
> >     -- some computations
> >     EXIT WHEN count > 0;  -- same result as previous example
> > END LOOP;
> >
> > BEGIN
> >     -- some computations
> >     IF stocks > 100000 THEN
> >         EXIT;  -- causes exit from the BEGIN block
> >     END IF;
> > END;
> >
> > 2006/4/27, Nelson Pereira Júnior <[EMAIL PROTECTED]>:
> > >
> > >
> > >
> > > Olá,
> > >
> > > Alguém sabe como faço para que de dentro de um loop eu interrompa as
> > > instruções seguintes passando para o próximo loop?
> > >
> > > Exemplo:
> > >
> > > while true loop
> > >
> > >     instrucao1;
> > >     instrucao1;
> > >     instrucao1;
> > >
> > >     if passou = true then
> > >         continue; --Vai para o proximo loop sem executar as linhas de
> > > baixo
> > >     end if;
> > >
> > >     instrucao1;
> > >     instrucao1;
> > >
> > > end loop;
> > >
> > > Alguém sabe como faço isso usando PSPGSQL?
> > > _______________________________________________
> > > Grupo de Usuários do PostgreSQL no Brasil
> > > http://www.postgresql.org.br
> > >
> > >
> >
> >
> > --
> > Ribamar FS - ribafs[ ]users.sourceforge.com
> > http://www.ribafs.tk
> > _______________________________________________
> > Grupo de Usuários do PostgreSQL no Brasil
> > http://www.postgresql.org.br
> >
> >
> > _______________________________________________
> > Grupo de Usuários do PostgreSQL no Brasil
> > http://www.postgresql.org.br
> >
>
>
> --
> Ribamar FS - ribafs[ ]users.sourceforge.com
> http://www.ribafs.tk
> _______________________________________________
> Grupo de Usuários do PostgreSQL no Brasil
> http://www.postgresql.org.br
>
>
> _______________________________________________
> Grupo de Usuários do PostgreSQL no Brasil
> http://www.postgresql.org.br
>


--
Ribamar FS - ribafs[ ]users.sourceforge.com
http://www.ribafs.tk
_______________________________________________
Grupo de Usuários do PostgreSQL no Brasil
http://www.postgresql.org.br

Responder a