Solved

A UNIQUE TRIGGER ON TWO COLUMNS - ORACLE PL/SQL PROGRAMMING

Posted on 2008-10-13
3
962 Views
Last Modified: 2013-12-18
Good evening!
In a table called NEREPSTA_CONFIG, I have a column called REPSTA_SFTP_PASSWORD (type VARCHAR2), on which I've built the following trigger:
CREATE OR REPLACE TRIGGER MASTER.REPSTA_SOURCE
BEFORE INSERT OR UPDATE
OF REPSTA_SFTP_PASSWORD
ON MASTER.NEREPSTA_CONFIG
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
   :NEW.repsta_sftp_password := cripta (:NEW.repsta_sftp_password);
END;
/

So, when a new record is inserted, on commit the NEREPSTA_SFTP_PASSWORD column is encrypted with che "CRIPTA" function.  Moreover, when the field NEREPSTA_SFTP_PASSWORD is updated, on commit it's encrypted with the same "CRIPTA" function.
Now please suppose to ALTER the NEREPSTA_CONFIG table, adding a new column called NGNEER_SFTP_PASSWORD: I would like to modify the trigger in order to use the CRIPTA stored function ONLY on the field updated or inserted, not on both fields inconditionally: only the modified field has to be cripted with the CRIPTA function.  Of course, if you INSERT a NEW record, both the fields NEREPSTA_SFTP_PASSWORD and NGNEER_SFTP_PASSWORD has to be crypted.

Any clues??
0
Comment
Question by:CRISTIANO_CORRADI
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 500 total points
ID: 22703764

Try this:

CREATE OR REPLACE TRIGGER MASTER.REPSTA_SOURCE
BEFORE INSERT OR UPDATE
OF REPSTA_SFTP_PASSWORD, NGNEER_SFTP_PASSWORD
ON MASTER.NEREPSTA_CONFIG
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
  IF INSERTING THEN
   :NEW.repsta_sftp_password := cripta (:NEW.repsta_sftp_password);
   :NEW.ngneer_sftp_password := cripta (:NEW.ngneer_sftp_password);
  ELSE
    IF UPDATING('REPSTA_SFTP_PASSWORD') THEN
     :NEW.repsta_sftp_password := cripta (:NEW.repsta_sftp_password);
    ELSE
      IF UPDATING('NGNEER_SFTP_PASSWORD ') THEN
       :NEW.ngneer_sftp_password := cripta (:NEW.ngneer_sftp_password);
      END IF;
    END IF;
  END IF;
END;
/

Open in new window

0
 

Author Comment

by:CRISTIANO_CORRADI
ID: 22703829
Thanks for your help: I've modified your source code as follows.

500 points for you ;-)
CREATE OR REPLACE TRIGGER MASTER.repsta_source
   BEFORE INSERT OR UPDATE OF repsta_sftp_password, ngneer_sftp_password
   ON MASTER.nerepsta_config
   REFERENCING NEW AS NEW OLD AS OLD
   FOR EACH ROW
BEGIN
   IF INSERTING
   THEN
      BEGIN
         :NEW.repsta_sftp_password := cripta (:NEW.repsta_sftp_password);
         :NEW.ngneer_sftp_password := cripta (:NEW.ngneer_sftp_password);
      END;
   END IF;
 
   IF UPDATING ('REPSTA_SFTP_PASSWORD')
   THEN
      :NEW.repsta_sftp_password := cripta (:NEW.repsta_sftp_password);
   END IF;
 
   IF UPDATING ('NGNEER_SFTP_PASSWORD')
   THEN
      :NEW.ngneer_sftp_password := cripta (:NEW.ngneer_sftp_password);
   END IF;
END;
/

Open in new window

0
 

Author Closing Comment

by:CRISTIANO_CORRADI
ID: 31505599
Thank you very much for your fast, kind help ;-)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Queries 15 46
how to trim oracle sql sentence in unix 17 58
upgrading Oracle 10g/ 11g / 11g R2 to Oracle 12c 25 69
Oracle Nested table uses ? 2 30
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question