Oracle trigger: view, schema, database

Source: Internet
Author: User

Oracle trigger: view, schema, database view trigger, instead of we know that if a view is only composed of a table, there are not many restrictions on the operations on The view. if the view is composed of multiple tables, the unpdate, insert, and delete operations on the view will fail. but sometimes we do what we need to do. in this case, you need to use the trigger, and then use the instead of keyword to specify some alternative operations. for example, if you have a view, my_view creates a trigger as follows: create or replace trigger my_view_trigger instead of insert or update on my_view declare insert into tmp (eno) values (: new. eno); end; trigger when executing SQL: insert into my_view (eno, name) values (88, 'test. however, the view's instead of Type trigger has a special relationship with other types of triggers. the name can also be used to replace the SQL operation that triggers it. that is, insert into my_view (eno, name) values (88, 'test'); the operation of the SQL itself will not work. only pl/SQL statement blocks in the trigger are actually executed. note: 1. an instead of Type trigger can only be created for a view, and the view cannot have a check option (such as with check read only). This prevents conflicts between different functions. if it is a read-only view, you can't create a trigger and do some DML operations. 2. the before or after option cannot be specified, because the SQL that triggers the trigger is not actually executed, so before or after does not make any sense. database and Schema-level Triggers may be used by developers for tables and views. for databases, schema triggers are generally used by DBAs. for example, a trigger is triggered when a DDL operation is performed on the schema. (a trigger for a table or view can only perform DML operations, but not DDL operations ). for example, create or replace trigger ddl_trigger after ddl on schema begin insert into tblog values (systimestamp, ora_sysevent, ora_login_user, login, login); END; where ora_login_user is the login name, ora_dict_obj_type indicates the object type (such as a table or view). ora_dict_obj_name indicates the object name, such as the table name or view name. you may see that these variables are not defined. it is actually defined by oracle. You only need to use it. trigger is triggered if any user executes the following SQL statement: create table tmp_tb (eno int. however, it seems that the specific schema cannot be directly specified, but it can only be used for all schemas. assume that you need to make some records each time you log on. you can CREATE the following trigger create or replace trigger logon_triggerAFTER logon on databasebegininsert into tblog VALUES (ora_login_user, ora_client_ip_address, systimestamp); END; here the logon database does not start, instead, each time a session is connected.

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.