Prezados membros da lista,

bom dia!

Sou iniciante em programação utilizando a linguagem plpgsql e tenho dúvidas
sobre algumas mensagens de erro que tenho recebido ao tentar criar uma
pequena função para migração de dados entre duas tabelas.

Talvez uma rápida olhada de vocês já será suficiente para orientar meus
primeiros passos.

Agradeço antecipadamente a atenção.

Segue o código:

CREATE FUNCTION doc_pendentes() Returns void AS '

DECLARE
    doc_matric  varchar(15);
    doc_men1    varchar(76);
    doc_men2    varchar(76);
    gvc_docpend RECORD;

BEGIN


 SELECT men_cal1||men_cal2, men_men1, men_men2

INTO doc_matric, doc_men1, doc_men2

FROM fai__men;


 WHILE doc_matric is not null

LOOP

 if doc_men2 is not null then

if UPPER(doc_men1||doc_men2) LIKE “%NASCIMENTO%” then

INSERT INTO gvc_docpend (dcp_alumatric,dcp_aludocdescr,dcp_docentregue)
VALUES (doc_matric,“Certidão de nascimento”)

 endif;

if UPPER(doc_men1||doc_men2) LIKE “%CASAMENTO%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue) (
doc_matric, “Certidão de casamento”)

endif;

if UPPER(doc_men1||doc_men2) LIKE “%HISTORICO%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue) (
doc_matric , “Histórico Escolar”)

endif;

if UPPER(doc_men1||doc_men2) LIKE “%IDENTIDADE%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue) (
doc_matric, “Documento de Identidade”)

endif;

if UPPER(doc_men1||doc_men2) LIKE “%TITULO%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue) (
doc_matric, “Título de eleitor”)

endif;

if UPPER(doc_men1||doc_men2) LIKE “%RESERVISTA%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue)
(doc_matric, “Certificado de Reservista”)

endif;

if UPPER(doc_men1||doc_men2) LIKE “%FOTOS%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue)
(doc_matric, “Fotos 3x4”)

endif

else if doc_men2 is null then

if UPPER(doc_men1) LIKE “%NASCIMENTO%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue)
(doc_matric, “Certidão de nascimento”)

endif;

if UPPER(doc_men1) LIKE “%CASAMENTO%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue)
(doc_matric, “Certidão de casamento”)

endif;

if UPPER(doc_men1) LIKE “%HISTORICO%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue)
(doc_matric, “Histórico Escolar”)

endif;

if UPPER(doc_men1) LIKE “%IDENTIDADE%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue)
(doc_matric, “Documento de Identidade”)

endif;

if UPPER(doc_men1) LIKE “%TITULO%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue)
(doc_matric, “Título de eleitor”)

endif;

if UPPER(doc_men1) LIKE “%RESERVISTA%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue)
(doc_matric, “Certificado de Reservista”)

endif;

if UPPER(doc_men1) LIKE “%FOTOS%” then

INSERT INTO gvc_docpend (dcp_alumatric, dcp_aludocdescr, dcp_docentregue)
(doc_matric, “Fotos 3x4”)

 endif;

endif

END LOOP;

END WHILE;

END FUNCTION' language plpgsql;

*ERROS OBTIDOS*:

**

*Erro de SQL:*

ERRO:  erro de sintaxe em ou próximo a "$1"
LINE 1: INSERT INTO  $1  (dcp_alumatric,dcp_aludocdescr,dcp_docentre...
                     ^
QUERY:  INSERT INTO  $1
(dcp_alumatric,dcp_aludocdescr,dcp_docentregue) VALUES ( $2 ,“Certidão
de nascimento”) endif
CONTEXT:  SQL statement in PL/PgSQL function "doc_pendentes" near line 19

Terei que criar outra função que irá receber como parâmetros de
entrada os dados que tratei nesta função para que eu consiga fazer a
inserção dos dados na tabela gvc_docpend?
Já lí o Manual do postgresql referente ao INSERT INTO mas não entendi
na prática onde estou errando. Há alguma maneira mais ágil de se fazer
o tratamento que estou fazendo aqui?
Aceito sugestões.

Abraço a todos,

Jeanne

------------------------------------------------------------------------------------------------------------------------------

"O bem que praticas em qualquer lugar será teu advogado em toda parte."
Emmanuel
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a