Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE AGENDA (
- ID_AGENDA D_ROWID,
- ID_COLABORADOR D_ROWID,
- DT_INICIAL D_DATA NOT NULL,
- DT_FINAL D_DATA NOT NULL,
- DESCRICAO D_TEXTO,
- LAST_UPDATE D_CURRENT_TIME,
- LAST_OWNER D_CURRENT_USER,
- STATUS D_STATUS,
- MODIFICADO_EM COMPUTED BY (CAST((SUBSTRING(CAST(LAST_UPDATE AS VARCHAR(30)) FROM 1 FOR 10)||' por '||LAST_OWNER) AS VARCHAR(40))),
- STATUS_COM COMPUTED BY ((
- CASE
- WHEN STATUS='A' THEN 'Aberto'
- WHEN STATUS='F' THEN 'Permanente'
- WHEN STATUS='C' THEN 'Cancelado'
- END))
- );
- /******************************************************************************/
- /*** Unique Constraints ***/
- /******************************************************************************/
- ALTER TABLE AGENDA ADD CONSTRAINT UNQ1_AGENDA UNIQUE (ID_COLABORADOR, DT_INICIAL, DT_FINAL);
- ALTER TABLE AGENDA ADD CONSTRAINT PK_AGENDA PRIMARY KEY (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (2, 0, '2012-04-30', '2012-05-01', '01/05/2012 dia do trabalhador imenda de feriado', '2013-04-22 13:58:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (3, 0, '2012-06-07', '2012-06-07', '07/06/2012 Corpus Christi', '2013-04-22 14:01:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (4, 0, '2012-06-07', '2012-09-09', '07 de setembro - independencia - imenda de feriado', '2013-04-22 14:02:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (5, 0, '2012-10-12', '2012-10-14', '12 outubro Padroeira do Brasil imenda de feriado', '2013-04-22 14:03:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (6, 0, '2012-11-02', '2012-11-04', '2 novembro Finados imenda de feriado', '2013-04-22 14:04:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (7, 0, '2012-11-15', '2012-11-15', '15 novembro Proclamação da Repúblic..', '2013-04-22 14:05:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (8, 0, '2012-12-22', '2013-01-02', 'Ferias coletiva', '2013-04-22 14:07:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (9, 0, '2013-02-11', '2013-02-12', 'Carnaval', '2013-04-22 14:10:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (10, 0, '2013-03-29', '2013-03-31', '
- 29/03 - Sexta-feira Santa', '2013-04-22 14:13:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (11, 0, '2013-05-01', '2013-05-01', '01/05 - dia do trabalhador', '2013-04-22 14:14:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (12, 0, '2013-05-30', '2013-06-02', '30/05/2013 Corpus Christi imenda de feriado', '2013-04-22 14:16:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (13, 0, '2013-11-15', '2013-11-17', '15 novembro Proclamação da Repúblic.. imenda de feriado', '2013-04-22 14:20:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (14, 0, '2013-12-23', '2014-01-02', 'Ferias coletivas', '2013-04-22 14:24:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (1, 0, '2012-04-06', '2012-04-08', 'Imenda de feriado 06/04 sexta feira santa', '2013-04-22 13:57:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (45, 0, '2014-03-03', '2014-03-04', 'CARNAVAL', '2014-02-21 16:28:59', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (59, 0, '2014-07-09', '2014-07-09', 'FERIADO', '2014-07-10 17:24:14', 'SYSDBARM', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (84, 0, '2014-12-24', '2015-01-04', 'Férias coletivas', '2014-12-15 09:52:37', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (89, 0, '2015-02-16', '2015-02-17', 'CARNAVAL', '2015-01-26 09:58:00', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (102, 0, '2015-04-03', '2015-04-05', 'SEXTA FEIRA SANTA E PASCOA', '2015-03-30 08:17:15', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (103, 0, '2015-04-20', '2015-04-22', 'DIA PONTE E TIRADENTES', '2015-04-13 08:07:27', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (106, 0, '2015-06-04', '2015-06-06', 'FERIADO E DIA PONTE CORPUS CHRISTI', '2015-04-13 08:09:44', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (105, 0, '2015-05-01', '2015-05-02', 'FERIADO DIA DO TRABALHO', '2015-04-13 08:08:25', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (107, 0, '2015-07-09', '2015-07-11', 'FERIADO E DIA PONTE REVOLUÇÃO DE 32.', '2015-04-13 08:29:03', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (108, 0, '2015-12-24', '2016-01-04', 'DIAS PONTES DE FIM DE ANO.', '2015-04-13 08:31:35', 'SYSDBA', 'A')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (124, 0, '2015-09-06', '2015-09-07', 'FERIADO', '2015-08-31 09:09:12', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (125, 0, '2015-10-11', '2015-10-12', 'FERIADO, NOSSA SENHORA APARECIDA', '2015-08-31 09:11:25', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- UPDATE OR INSERT INTO AGENDA (ID_AGENDA, ID_COLABORADOR, DT_INICIAL, DT_FINAL, DESCRICAO, LAST_UPDATE, LAST_OWNER, STATUS)
- VALUES (126, 0, '2015-11-01', '2015-11-02', 'FERIADO, FINADOS', '2015-08-31 09:14:13', 'SYSDBA', 'F')
- MATCHING (ID_AGENDA);
- COMMIT WORK;
- /* Uma procediure para incluir algo nessa tabela seria assim: */
- CREATE OR ALTER PROCEDURE sp_agenda (
- p_acao VARCHAR(32),
- p_id_agenda BIGINT = 0,
- p_id_colaborador BIGINT = 0,
- p_dt_inicial DATE = CURRENT_DATE,
- p_dt_final DATE = CURRENT_DATE,
- p_descricao d_texto = '',
- p_status CHAR(1) = 'A')
- RETURNS (
- result_value BIGINT)
- AS
- DECLARE variable l_status VARCHAR(1) = '';
- DECLARE variable l_id_colaborador BIGINT = 0;
- DECLARE variable l_dt_inicial DATE = CURRENT_DATE;
- DECLARE variable l_dt_final DATE = CURRENT_DATE;
- DECLARE variable l_permitido INTEGER = 0;
- BEGIN
- result_value=0;
- IF (:p_acao NOT IN ('INCLUIR','ALTERAR','EXCLUIR')) THEN
- BEGIN
- exception ERR 'Ação solicitada ('||:p_acao||') está fora dos parametros permitidos !';
- suspend;
- exit;
- END
- l_id_colaborador=:p_id_colaborador;
- IF (:p_acao='INCLUIR') THEN
- BEGIN
- SELECT COALESCE(MAX(id_agenda),0) FROM agenda INTO :p_id_agenda;
- p_id_agenda=:p_id_agenda+1;
- INSERT INTO agenda(
- id_agenda,
- id_colaborador,
- dt_inicial,
- dt_final,
- descricao,
- last_update,
- last_owner,
- STATUS)
- VALUES(
- :p_id_agenda,
- :p_id_colaborador,
- :p_dt_inicial,
- :p_dt_final,
- :p_descricao,
- CURRENT_TIMESTAMP,
- CURRENT_USER,
- 'A');
- result_value=1;
- END
- IF (:p_acao IN ('ALTERAR','EXCLUIR')) THEN
- BEGIN
- SELECT dt_inicial, dt_final, STATUS FROM agenda
- WHERE id_agenda=:p_id_agenda
- INTO :l_dt_inicial, :l_dt_final, :l_status;
- IF (:l_status = 'F') THEN
- BEGIN
- exception ERR 'Esse agendamento é considerado [Permanente], isso quer dizer que não pode ser modificado porque já está em uso!'
- suspend;
- exit;
- END
- END
- IF (:p_acao='ALTERAR') THEN
- BEGIN
- UPDATE agenda
- SET descricao=:p_descricao,
- dt_inicial=:p_dt_inicial,
- dt_final=:p_dt_final,
- last_update=CURRENT_TIMESTAMP,
- last_owner=CURRENT_USER,
- STATUS=:p_status
- WHERE id_agenda=:p_id_agenda;
- result_value=1;
- END
- IF (:p_acao='EXCLUIR') THEN
- BEGIN
- DELETE FROM agenda
- WHERE id_agenda=:p_id_agenda AND status<>'F';
- result_value=1;
- END
- suspend;
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement