Little application of Oracle trigger [转]

xiaoxiao2021-03-06  83

Previous colleagues have to come once before this time you add records in the Oracle database: SELECT MAX (ID) from t_examineinfo.

It feels quite trouble and low efficiency, so use trigger to solve this problem.

First create a test watch Test, DDL as follows:

Create Table Test (ID Number NOT NULL, NAME VARCHAR2 (10) Not null, Sex Varchar2 (1) Not NULL) Build a sequence seq_t_examineinfo, DDL as follows:

Create sequence seq_t_examineinfo minvalue 1 maxValue 9999999999999999 Start with 21 increment by 1 cache 20;

Then create a trigger called Test_TIGGER in the Test Test, which is as follows:

Create or Replace Trigger Test_tigger Before Insert SEQ_T_EXAMINFO.NEXTVAL INTO: New.ID from Dual

End test_tigger;

At this point, debugging with PLSQL Developer: INSERT INTO TEST (Name, SEX) VALUES ('WZJ', '616');

SELECT *.

Record has been successfully inserted, and it is achieved to automatically increase 1 method in the character value in Oracle.

转载请注明原文地址:https://www.9cbs.com/read-121685.html

New Post(0)