Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Trigger to copy one column to another with Replace

PhilMan2Mar 5 2014 — edited Mar 6 2014

Hello,

Every time I modify a row, I'd like to copy the contents of the SONG_FULL_NAME column to the SONG_PDF column, replacing the spaces with underscores.

I had a trigger to capture the user's name and modified date, and I figured that I would just enhance that existing trigger, but I can't seem to make it work.

I'm using Oracle XE 11.2

create or replace

TRIGGER "SOME_SCHEMA"."BU_SONG_LISTING"

BEFORE UPDATE ON SONG_LISTING

FOR EACH ROW

DECLARE

  v_username varchar2(512);

 

BEGIN

  :new.MODIFIED_DATE := SYSDATE;

     -- Find username of person performing INSERT into table

   SELECT user INTO v_username

   FROM dual;

  :new.MODIFIED_BY := v_username;

  :new.SONG_PDF := replace(:new.SONG_FULL_NAME, ‘ ‘, ‘_’);

END;

The goal is to always replace SONG_PDF with the data from SONG_FULL_NAME, but replacing the spaces with underscores.

Thanks for looking at this.

This post has been answered by Mike Kutz on Mar 6 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 3 2014
Added on Mar 5 2014
6 comments
597 views