MySQL Forums
Forum List  »  Triggers

Need help creating a Trigger to replace a String
Posted by: Kung Wong
Date: February 22, 2012 09:00AM

Hello, I have the following problem:

I got a table called Article and a table called Image.

I need to write a Trigger, that inserts a replaced ArticleNumber into the Image table, as soon a new Article got inserted.

The logic for the replacement is

$renamedFilename = str_replace("-", "--", $renamedFilename);
$renamedFilename = str_replace("ß", "sz", $renamedFilename);
$renamedFilename = str_replace("Ü", "UE", $renamedFilename);
$renamedFilename = str_replace("Ö", "OE", $renamedFilename);
$renamedFilename = str_replace("Ä", "AE", $renamedFilename);
$renamedFilename = str_replace("ü", "ue", $renamedFilename);
$renamedFilename = str_replace("ö", "oe", $renamedFilename);
$renamedFilename = str_replace("ä", "ae", $renamedFilename);
$renamedFilename = str_replace("/", "__", $renamedFilename);
$renamedFilename = str_replace(".", "-", $renamedFilename);
$renamedFilename = str_replace(" ", "_", $renamedFilename);

But how do I add so many replaces into the trigger?

I thought of something like

DELIMITER $$

CREATE TRIGGER create_image_trigger
AFTER INSERT ON article
FOR EACH ROW
BEGIN
INSERT INTO image SET image = REPLACE(article_no, "-", "--")

END;
$$

DELIMITER ;

But that can't handle multiple replacements ...

Or do I need a function to handle that ?

with kind regards

Options: ReplyQuote


Subject
Views
Written By
Posted
Need help creating a Trigger to replace a String
2544
February 22, 2012 09:00AM


Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.

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.