在网上查了oracle自增主键的列子,但是里面语句涉及的只是自己并不了解,所以本人结合着文档学习了一下oracle自增主键所涉及的一些知识。
首先是触发器:
Use the CREATE
TRIGGER
statement to create a database trigger, which is:
-
A stored PL/SQL block associated with a table, a schema, or the database or
-
An anonymous PL/SQL block or a call to a procedure implemented in PL/SQL or Java
Oracle Database automatically executes a trigger when specified conditions occur.
咱们要用的是与一个表相关的存储pl/sql语句块。
To create a trigger in your own schema on a table in your own schema or on your own schema (SCHEMA
), you must have the CREATE
TRIGGER
system privilege.
先决条件,在一个表上创建出发器必须有create trigger系统权限
If the trigger issues SQL statements or calls procedures or functions, then the owner of the trigger must have the privileges necessary to perform these operations. These privileges must be granted directly to the owner rather than acquired through roles.
如果触发器发表了一个sql语句或者程序或者函数,触发器的所有者必须有执行这些操作的权限。这些权限一定要直接授权给该所有者而不是通过角色获得。
大概了解了触发器,咱们看看语法
一下语法说明:
Re-creates the trigger if it exists, and recompiles it.
Users who were granted privileges on the trigger before it was redefined can still access the procedure without being regranted the privileges.
就是如果该触发器存在,重新创建,重新编译它
咱们的sql语句先写个初步:create or replace trigger trigger_sequence
Causes the database to fire the trigger before running the triggering event. For row triggers, the trigger fires before each affected row is changed.
就是说执行触发器事件之前引起数据库调用该触发器。对于行触发器,触发器在每个受影响的行改变前调用。
触发器事件就是引起该触发器出发的操作,而行触发器就是如果触发器事件引起的每个行都会引起触发器出发
对于咱们是insert 一行之前要先把序列的值赋给该行的主键,也就是选中before
sql语句这回写成
:create or replace trigger trigger_sequence before insert on author
Specifies a SQL condition that the database evaluates for each row that the triggering statement affects. If the value of