Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-13
3
Medium Priority
?
968 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

636 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