Home > database >  Trigger problems (according to the condition to decide whether to insert in another table to another
Trigger problems (according to the condition to decide whether to insert in another table to another

Time:09-22

Insert A data trigger, when inserted into A data table A, according to the value of one field query another qualified record in table B (may be N records), and then according to the value of A field in table B one judge whether to insert data into table C, how to write this trigger, thank you!

CodePudding user response:

Under the table structure said, and then gives some test data,

CodePudding user response:

Table A:
 
The create table A
(
Id VARCHAR2 (100) not null,
The value NUMBER (18, 2)
)

The create table B
(
Id VARCHAR2 (100) not null,
Zhi, NUMBER (18, 2)
)

The create table C
(
Id VARCHAR2 (100) not null,
The value NUMBER (18, 2),
Zhi, NUMBER (18, 2)
)


When there is A table data into, to insert the field value of the value of the field in table B zhi data by contrast, when A table when A value is greater than the table B zhi, insert the data of A table to table C corresponding fields

CodePudding user response:

 
INSERT INTO A (ID, VAULE) VALUES (' ad1ae75d - fb8 bb27-4 - afe8-381 eafc0505c ', 29.40);
INSERT INTO A (ID, VAULE) VALUES (' acbaae20 ca3e550b1-9 - adb6 ef5-4846-874 ', 30.40);
INSERT INTO A (ID, VAULE) VALUES (' 54 a234b7 FFD - 376 - c - 4-8 FFF - 2 bd836bf9cab ', 29.20);
INSERT INTO A (ID, VAULE) VALUES (' electronics f34ea7-4-4606-8814-31 fb07c4cb463d ', 46.30);
INSERT INTO A (ID, VAULE) VALUES (' 3866 ef03 - e50 dd9d - 4 - cc5f879 b900-42294 ', 55.10);
INSERT INTO A (ID, VAULE) VALUES (' ec59fdc7 - b418-420 - d - b388-057 b6b049075 ', 29.20);
INSERT INTO A (ID, VAULE) VALUES (' 3328 be49-4116-4825 - b100-8 b2c0b4208c3 ', 29.50);


INSERT INTO B (ID, ZHI) VALUES (' ad1ae75d - fb8 bb27-4 - afe8-381 eafc0505c ', 40.00);
INSERT INTO B (ID, ZHI) VALUES (' acbaae20 ca3e550b1-9 - adb6 ef5-4846-874 ', 50.00);
INSERT INTO B (ID, ZHI) VALUES (' 54 a234b7 FFD - 376 - c - 4-8 FFF - 2 bd836bf9cab ', 60.00);
  • Related