如果在同一天批准多个交易,如何避免员工的交易?

时间:2015-12-08 13:23:05

标签: sql plsql

如果同一天批准了多项交易,如何避免员工的交易? 请尽快帮助我。

1 个答案:

答案 0 :(得分:0)

-- To check in the anonymous block code if CONSTRAINT cannot be applied later on the table

    DECLARE
      lv_cnt PLS_INTEGER;
      lv_emp PLS_INTEGER;
      lv_day DATE;
    BEGIN
      SELECT COUNT(1)
      INTO lv_cnt
      FROM emp
      WHERE empno          = lv_emp
      AND transaction_stat = 'APPROVED'
      AND tran_date        = lv_day;
      IF lv_cnt            > 1 THEN
        RAISE_APPLICATION_ERROR(-200001,'Cannot proceed with this transaction as already approved transaction for this day is present',TRUE);
      ELSE
        dbms_output.put_line('your piece of code for new transaction');
      END IF;
    END;