SELECT count(cre_key_tipo)
INTO v_count
FROM table
WHERE cre_key_tipo = 'G'
AND cre_key_tipo IN (SELECT cli_id FROM cliente_regime_especial
WHERE cre_key_tipo = (SELECT cre_key_tipo
FROM table
WHERE cre_key_tipo = 'E'));
SELECT count(cre_key_tipo)
INTO v_count
FROM table
WHERE cre_key_tipo = 'E'
AND cre_key_tipo IN (SELECT cli_id FROM cliente_regime_especial
WHERE cre_key_tipo IN (SELECT cre_key_tipo
FROM table
WHERE cre_key_tipo = 'G'));
if v_count > 1 and w_count > 1 then
botao:=alerta('STOP1','Só é permitido um tipo de Regime especial por cliente!');
raise form_trigger_failure;
end if;
Eu preciso que dentro de um forms um cliente que possuir a flag 'G', não poderá possuir mais nenhuma flag 'E', mas ao mesmo tempo ele pode possuir diversas flag 'E' caso não possua nenhuma flag 'G'.
SELECT count(cre_key_tipo)
INTO v_count_G
FROM cliente_regime_especial
where cli_id = :codigo_cliente
and cre_key_tipo = 'G'
Exception
When others then
v_count_G :=0;
SELECT count(cre_key_tipo)
INTO v_count_E
FROM cliente_regime_especial
where cli_id = :codigo_cliente
and cre_key_tipo = 'E'
Exception
When others then
v_count_E :=0;
If ((v_count_G > 0) and (v_count_E > 0)) then
botao:=alerta('STOP1','Só é permitido um tipo de Regime especial por cliente!');
raise form_trigger_failure;
end if;