生成创建触发器所需的SQL(Oracle)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了生成创建触发器所需的SQL(Oracle)相关的知识,希望对你有一定的参考价值。
Generate the SQL necessary to create triggers that use the sequences listed above.NOTE: This particular script assumes that the tables all start with ‘tbl’.
It may need to be modified to work with different naming conventions.
SELECT 'CREATE OR REPLACE TRIGGER trg' || substr (TABLE_NAME,4,LENGTH(TABLE_NAME)-3) || ' before insert on tbl' || substr (TABLE_NAME,4,LENGTH(TABLE_NAME)-3) || ' for each row declare begin if (:new.' || substr (TABLE_NAME,4,LENGTH(TABLE_NAME)-3) || 'id =0) or (:new.' || substr (TABLE_NAME,4,LENGTH(TABLE_NAME)-3) || 'id is null) then begin select tbl' || substr (TABLE_NAME,4,LENGTH(TABLE_NAME)-3) || '_seq.nextval into :new.' || substr (TABLE_NAME,4,LENGTH(TABLE_NAME)-3) || 'id from dual; end; end if; end; / ' FROM user_tables
以上是关于生成创建触发器所需的SQL(Oracle)的主要内容,如果未能解决你的问题,请参考以下文章
ORACLE SQL Developer 所需的属性主机名不能为空或为空