title: Creating trigger in oracle for preventing duplicate keys before inserting cmd
body: <p>I am trying to create a trigger in oracle which will detect a duplicate inseted primary key and will rename a new key by adding a prefix char for example 'P_'.
  If somebody know the elegant solution for this problem, I will glad to see the answer :).</p>
  
  <p>I started to write smth like this:</p>
  
  <pre><code>create or replace 
  TRIGGER t1_trigger
  BEFORE INSERT
  ON T1
  DECLARE selected_id varchar2(10);
  BEGIN
    SELECT id INTO selected_id FROM T1 WHERE id = :new.id;
    IF (selected_id NOT NULL)
    THEN INSERT INTO T1 VALUES('p_');
    END IF;
  END;
  </code></pre>