What is the relationship between sequences, triggers, and stored procedures?

Source: Internet
Author: User

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;

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.