Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Database trigger
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Before each - row-level trigger === This example demonstrates a BEFORE EACH ROW trigger that modifies the INSERT using a WHEN conditional. If the last name is larger than 10 letters, using the SUBSTR function<ref>{{Cite web|url=https://www.databasestar.com/oracle-sql-functions/|title=Oracle SQL Functions β The Complete List|date=December 26, 2014}}</ref> we change the last_name column value to an abbreviation. <syntaxhighlight lang="sql"> CREATE OR REPLACE TRIGGER phone_book_insert BEFORE INSERT ON phone_book FOR EACH ROW WHEN (LENGTH(new.last_name) > 10) BEGIN :new.last_name := SUBSTR(:new.last_name,0,1); END; </syntaxhighlight> Now performing an INSERT of someone with a large name. <syntaxhighlight lang="sql"> INSERT INTO phone_book VALUES (6, 'VeryVeryLongLastName', 'Erin', 'Minneapolis', 'MN', '989 University Drive', '123-222-4456', 55408, TO_DATE('11/21/1991', 'MM/DD/YYYY')); </syntaxhighlight> {| class="wikitable" |- ! Person_ID !! Last_Name !! First_Name !! City !! State_Abbreviation !! Address !! Phone_Number !! Zip_code !! DOB |- | 6 || V || Erin || Minneapolis || MN || 989 University Drive || 123-222-4456 || 55408 || 21-NOV-91 |} The trigger worked as per the result above, modifying the value of the INSERT '''before''' it was executed.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)