Pular para o conteúdo

Fóruns SQL e PL/SQL CURSOS – APANHANDO NA SYNTAX CURSOS – APANHANDO NA SYNTAX

#78589
wesleyNet
Participante

    Resolvido:

    Create or replace Function IDLAN_PAGREC( string_campo in varchar2 ) Return NUMBER is
    –Retorna o último IDLAN conforme tipo de pagamento, campo FLAN.PAGREC
    v_result NUMBER(5);
    ID RM.FLAN.IDLAN%Type;
    cursor C1 is select max(IDLAN) from RM.FLAN WHERE PAGREC=’2′;
    Begin
    OPEN C1;
    fetch C1 INTO ID;
    if string_campo = ‘1’ then
    v_result := ID+1;
    End if;
    if string_campo = ‘2’ then
    v_result := ID+1;
    End if;
    Return (v_result);
    CLOSE C1;
    end;

    [quote=”wesleyNet”:1o1pvdfo]Olá galera

    Estou tentando usar cursor dentro de uma função. A função retorna
    o último id mais um de uma determionada tabela.

    Segue:
    Create or replace Function ULT_IDLAN_COF_PAGREC( string_campo in varchar2 ) Return NUMBER is
    v_result NUMBER(5);
    –Função retorna o último IDLAN conforme tipo de pagamento, campo FLAN.PAGREC
    cursor C1 is select (Max(IDLAN)+1) util_id from RM.FLAN WHERE PAGREC=’2′;
    Begin
    OPEN C1;
    fetch C1 INTO UTIL_ID;
    if string_campo = ‘2’ then
    v_result := UTIL_ID;
    End if;
    Return (v_result);
    CLOSE C1;
    end;

    [b]

    Estou tentando atribuir o UTIL_ID para a variável mas não dá certo:

    SQL> show errors;
    Errors for FUNCTION ULT_IDLAN_COF_PAGREC:

    LINE/COL ERROR


    7/2 PL/SQL: SQL Statement ignored
    7/16 PLS-00201: identifier ‘UTIL_ID’ must be declared
    9/1 PL/SQL: Statement ignored
    9/13 PLS-00201: identifier ‘UTIL_ID’ must be declared

    Obrigado pela Atenção. 😀 [/b][/quote]