Get the App
SLTechnology News&Howtos  ›  Database  › 

How to understand NEW and OLD in database triggers

Shulou Source: shulou.com Published: 2022-05-31 15:24:43 10月02日 Update

This article mainly explains "how to understand NEW and OLD in database triggers". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand NEW and OLD in database triggers".

I created these two tables and added two rows of data to the plch_ parts table:

CREATE TABLE plch_parts (partnum NUMBER, partname VARCHAR2 (50)) / BEGIN INSERT INTO plch_parts VALUES (123,' Steering Wheel'); INSERT INTO plch_parts VALUES (456,' Brake Pedal'); COMMIT;END;/CREATE TABLE plch_log (partnum NUMBER, partname VARCHAR2 (50), changed_on DATE, changed_by VARCHAR2 (100)) /

Then I added a trigger to the plch_parts table:

CREATE OR REPLACE TRIGGER plch_parts_trig AFTER UPDATE ON plch_parts FOR EACH ROWDECLAREBEGIN INSERT INTO plch_log VALUES (: new.partnum,: new.partname, SYSDATE, USER); END plch_parts_trig;/

Then I executed this block:

BEGIN UPDATE plch_parts SET partnum =-1 * partnum WHERE partname = 'Brake Pedal'; UPDATE plch_parts SET partname = UPPER (partname) WHERE partnum = 123; COMMIT;END;/

Which of the following options show the results of this query:

SELECT partnum, partname FROM plch_logORDER BY partnum/

(A)

PARTNUM PARTNAME-456 Brake Pedal 123 STEERING WHEEL

(B)

PARTNUM PARTNAME-123 Steering Wheel 456 Brake Pedal

(C)

PARTNUM PARTNAME-123 STEERING WHEEL 456 Brake Pedal

(D)

PARTNUM PARTNAME-- 123 STEERING WHEEL-456 Brake Pedal

Answer A

SQL > SELECT partnum, partname 2 FROM plch_log 3 ORDER BY partnum 4 / PARTNUM PARTNAME- 456 Brake Pedal 123 STEERING WHEELSQL > Thank you for reading. That's how to understand NEW and OLD in database triggers. After the study of this article, I believe you have a deeper understanding of how to understand the NEW and OLD in database triggers, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Data triggers databases learning content that is ideas situations articles more knowledge knowledge points answers articles results follow questions China plus practice push Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Information Linux MySQL Redmi