WHENEVER SQLERROR EXIT SQL.SQLCODE

BEGIN
  DBMS_REDACT.DROP_POLICY(
    object_schema => 'ADMIN',
    object_name   => 'DDS_AUDIT_PAYMENTS',
    policy_name   => 'DDS_REDACT_CARD_TOKEN'
  );
EXCEPTION
  WHEN OTHERS THEN NULL;
END;
/

BEGIN
  DBMS_REDACT.ADD_POLICY(
    object_schema          => 'ADMIN',
    object_name            => 'DDS_AUDIT_PAYMENTS',
    policy_name            => 'DDS_REDACT_CARD_TOKEN',
    column_name            => 'CARD_TOKEN',
    function_type          => DBMS_REDACT.PARTIAL,
    function_parameters    => 'VVVFVVVVFVVV,VVVFVVVVFVVV,*,4,7',
    expression             => '1=1',
    policy_description     => 'Masks payment card tokens in query results for audit demos.',
    column_description     => 'Card token is partially redacted; full value remains stored in the database.'
  );
END;
/
