It would an help for creation of procedure in Oracle 10g
I have two tables (table1 and table2). In table1 I go to have given that I go to play in table2 and in case that the register already is in table2,
necessary to make update and if not, insert. As I make this implementation in “if” and as I make the declaration of table2.
It follows what I have mounted…
AS
cod_erro NUMBER;
message_erro VARCHAR2(255);
CURSOR C1 IS
SELECT emp, codigo, descricao FROM table1 FOR UPDATE;
REGISTRO C1%ROWTYPE;
BEGIN
OPEN C1;
LOOP
FETCH C1 INTO REGISTRO;
EXIT WHEN C1%NOTFOUND;
if ??????? (if table1.emp=table2.emp then to make update, if not it insert)
then
update table2 set cod=REGISTRO.cod,descricao=REGISTRO.descricao) ;
else
insert into table2 (emp, codigo, descricao) values (REGISTRO.emp,REGISTRO.cod,REGISTRO.descricao);
end if;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
cod_erro := SQLCODE;
message_erro := SQLERRM;
INSERT INTO CARLOS.ERROS_IMPORT
VALUES (cod_erro, message_erro, sysdate);
update table1 set date=SYSDATE where CURRENT OF c1;
CLOSE C1 ;
END;
thanks
Carl