What is the relationship between sequences, triggers, and stored procedures? I haven't used oracle databases for a long time. Today I reviewed oracle sequences, triggers, and stored procedures, previously, the concepts of triggers and stored procedures were a bit vague. Let's review our experiences today: stored procedures are equivalent to packaged SQL syntax and can contain complex SQL operations, when a program is called, you only need to execute the stored procedure and perform complex database operations in one sentence. A trigger is also a packaged SQL syntax and a special type of stored procedure that cannot be directly called by users. When a trigger is created, it is defined to modify data of a specific table or column. In addition: the TRIGGER stored procedures are different in code writing. For example, the create trigger must be the first statement in batch processing and can only be applied to one table. It seems that you must create a sequence before creating a trigger! The following code describes the sequence, trigger, and stored procedure: Create sequence:
[SQL] // create sequence SEQ minvalue 1 maxvalue 999999999999999999999999999 start with 1 increment by 1 cache 20; create trigger: [SQL] // create trigger create or replace trigger Tg before insert on user for each row declare begin select Seq. nextval into: New. ID from dual; end Tg; create a stored procedure: [SQL] // create or replace procedure Pro (v_name varchar2, v_pwd varchar2, v_role varchar2) is begin insert into user (ID, NAME, PASSWORD, ROLE) values (Seq. nextval, v_name, v_pwd, v_role); // user is the table name commit; end;