Cursor within Triggers
Posted by: Chintan Shah
Date: January 11, 2011 01:32AM

Following is my trigger for Audit Trails or Logging...

DELIMITER $$

DROP TRIGGER /*!50032 IF EXISTS */ `CBMDATA`.`trgProperty`$$

CREATE
/*!50017 DEFINER = 'iconmans'@'10.10.10.%' */
TRIGGER `trgProperty` AFTER UPDATE ON `property`
FOR EACH ROW BEGIN
DECLARE oldColName VARCHAR(100);
DECLARE oldColValue TEXT;
DECLARE newColName VARCHAR(100);
DECLARE newColValue TEXT;

DECLARE done INT DEFAULT 0;
DECLARE colname VARCHAR(500);
DECLARE curColName CURSOR FOR SELECT COLUMN_NAME as colname FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA = 'CBMDATA' AND TABLE_NAME = 'property';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

OPEN curColName;
REPEAT
FETCH curColName INTO colname;
SET oldColName = CONCAT("OLD.", colname);
SET newColName = CONCAT("NEW.", colname);
SET oldColValue := oldColName;
SET newColValue := newColName;

INSERT INTO `CBMDATA`.`log_propert`(FIELD_NAME,OLD_VALUE,NEW_VALUE,OFF_MODIFY_DATE) VALUES (colname,oldColValue,newColValue,now());

# IF NOT done THEN
# IF oldColValue <> newColValue THEN
# INSERT INTO `CBMDATA`.`log_propert`(FIELD_NAME,OLD_VALUE,NEW_VALUE,OFF_MODIFY_DATE) VALUES (colname,oldColValue,newColValue,now());
# END IF;
# END IF;
UNTIL done END REPEAT;
CLOSE curColName;
END;
$$

DELIMITER ;

My issue is that, I want a way by which i can evaluate variables like oldColName and newColName...

Please give me reply as soon as possible
In Advance, Thank you !!!

Options: ReplyQuote


Subject
Written By
Posted
Cursor within Triggers
January 11, 2011 01:32AM
January 12, 2011 10:06AM
January 13, 2011 01:30PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.