Exemplo para se criar uma Trigger

create or replace trigger
before insert or update
on

for each row
declare

begin

exception

end ;
/

create or replace trigger TRG_BI_TTCPJ
before insert on TTCPJ
for each row
begin
select SEQ_TTCPJ into :NEW.CODIGO from dual;
end;
/

Exemplo UTL_FILE

create or replace procedure criaarquivo (
path in varchar2,
filename in varchar2
)
is
output_file utl_file.file_type;
begin
output_file := utl_file.fopen (path,filename, ‘W’);

for cur_rec in (select linhas from TTCPJ order by codigo) loop
utl_file.put_line (output_file, cur_rec.linhas);
end loop;

utl_file.fclose(output_file);

–exception
— when others then null;
end;
/