Prova Substitutiva (14/12/04) 1) -- Create table MOVIMENTOS create table MOVIMENTOS ( ID_MVTO NUMBER not null, DATA DATE, ID_PRODUTO VARCHAR2(30), QTDE NUMBER ) tablespace USERS pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited ); -- Create/Recreate primary, unique and foreign key constraints alter table MOVIMENTOS add constraint ID_MOVTO primary key (ID_MVTO) using index tablespace USERS pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited ); -- Create table PRODUTO create table PRODUTO ( ID NUMBER not null, SALDO NUMBER(8,2) ) tablespace USERS pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited ); -- Create/Recreate primary, unique and foreign key constraints alter table PRODUTO add constraint ID primary key (ID) using index tablespace USERS pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited ); 2) create sequence seq_Id_movimento start with 1; create or replace trigger trg_Id_movimento before insert on MOVIMENTOS for each row begin select seq_Id_movimento.nextval into :new.Id_mvto from dual; end; 3) create or replace trigger trg_movimentosaldo after insert or update or delete on MOVIMENTOS for each row declare saldo number; qtde number; begin if inserting then select qtde into qtde_movto from MOVIMENTOS where Id=:new.Id; end if; update PRODUTO set saldo = (saldo + (:new.qtde) where Id = :new.PRODUTO end; 4) insert into MOVIMENTOS (0, sysdate,'33333333',300); 5) create or replace function funcao_movimento (id_produto number) return number is begin select id_produto into PRODUTO from MOVIMENTOS where id_produto.MOVIMENTOS = id.PRODUTO group by PRODUTO; return (qtde); retunr (soma_qtde); end; 6) create or replace procedure deleta_movimentos is begin for aux in(select * from movimentos)loop delete MOVIMENTOS where to_char (data,'ddd')>30 and MOVIMENTOS.id_produto = aux.Id_movto; end loop; commit; end;