create or replace trigger 名
before or after DML(Insert ,uodate ,delete)on 表名
begin
执行语句
end;
/
对操作进行日志备份
create or replace trigger 名
before insert on emp
begin
insert into emp_log(user,to_cahr(sysdate,'yyyy-mm-dd hh:mi:ss','insert);
end;
create or replace trigger t_timelimited
after insert or delete or update on emp
declare
v_time varchar2(20);
begin
v_time:=to_char(sysdate,'hh24');
if v_time=19 then
raise_application_error(-20009,'这个时段禁止此操作');
end if;
end;
19时 不能进行 这些操作
create or replace trigger t_emp
before insert or update or delete on emp
begin
if inserting then
insert into emp_log values(user,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'insert');
elsif updating then
insert into emp_log values(user,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'update');
elsif deleting then
insert into emp_log values(user,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'delete');
end if;
end;
EMP表删除 几行 就插入EMP2 几行
create or replace trigger t_new
before delete on emp
for each row
begin
if deleting then
insert into emp2 values (:old.empno,:old.ename,:old.job,:old.mgr,:old.hiredate,:old.sal,:old.comm,:old.deptno);
end if;
end;
/
行级触发器 :new.字段名 是 更改后新的内容
:old.字段名 是更改前的内容
要使用 new 和 old 必须先 加上 for each row
old和new 如果执行update 更改前的就是old 更改后的就是new
如果是删除 new 就是 空 如果插入 old 就是空
创建序列
SQL> create sequence s_sstu;
序列已创建。
创建表---------------------------------------------------------------------
SQL> create table stu(
2 id int,
3 name varchar2(20));
创建触发器-----------------------------------------------------------------
create or replace trigger t_stu
before insert on stu
for each row
begin
select s_sstu.nextval into :new.id from dual;
end;
/
插入--------------------------------------------------
insert into stu(name) values('mt');
execute immediate 'sql语句'
begin
execute immediate 'create table emp as select * from emp';
end;
可以执行
分享到:
相关推荐
Oracle中EXECUTE IMMEDIATE用法
oracle动态sql之EXECUTE IMMEDIATE.docx
动态创建和执行SQL语句性能超前,EXECUTE IMMEDIATE的目标在于减小企业费用并获得较高的性能,较之以前它相当容易编码.尽管DBMS_SQL仍然可用,但是推荐使用EXECUTE IMMEDIATE,因为它获的收益在包之上。 — 使用技巧 ...
execute immediate 用法研究 为初学者打造。
用execute immediate 执行备份恢复SQLSVR数据库
NULL 博文链接:https://wushuangyan26.iteye.com/blog/1306094
动态sql语句基本语法 1 :普通SQL语句可以用Exec执行 例: Select * from tableName Exec('select * from tableName') Exec sp_executesql N'select * from tableName' -- 请注意字符串前一定要加N 2:字段名,...
EXECUTE --动态地执行SQL 语句 DESCRIBE --描述准备好的查询 ---局部变量 declare @id char(10) --set @id = '10010001' select @id = '10010001' ---全局变量 ---必须以@@开头 --IF ELSE ...
在回答这个问题前,我们先来回顾一下:在ORACLE数据库架构下,SQL语句由用户进程产生,然后传到相对应的服务端进程,之后由服务器进程执行该SQL语句,如果是SELECT语句,服务器进程还需要将执行结果回传给用户进程。...
在编写自己的程序时,需要实现将数据导入数据库,并且是带参数的传递。...cur.execute(sql_str) 执行程序后,产生错误: ProgrammingError: (1064, “You have an error in your SQL syntax; check the m
execute immediate str_sql into tabtcn; --动态执行DDL语句
全书涵盖了 PL/SQL提供的大量功能,包括高效数据处理、安全、触发器、DBA包以及高效的调试技术等。此外,书中含有丰富的示例,并提供了大量提示和技巧。《精通Oracle PL/SQL》结构清晰,示例丰富,实践性强,适用于 ...
exec sp_executesql @sql 注意:在top后不能直接跟一个变量,所以在实际应用中只有这样的进行特殊的处理。Rid为一个标识列,如果top后还有具体的字段,这样做是非常有好处的。因为这样可以避免 top的字段如果是...
判断execute(sql)执行成功与否,帮助更好的控制代码操作性
MSSQL为我们提供了两种动态执行SQL语句的命令,分别是 EXEC 和 SP_EXECUTESQL ,我们先来看一下两种方式的用法。 先建立一个表,并添加一些数据来进行演示: 复制代码 CREATE TABLE t_student( Id INT NOT NULL, ...
// 确认本地已经安装oracle的客户端 // ※只会执行sql文 不会自动删除表内数据 // oracleStup.bat // 命令行 用户名/密码 @库名 不需要修改 sqlplus C3/AISIN@C3 @sqlFile.sql > execute.log // sqlFile.sql // @...
ExecuteSQL.java
SQL Server EXEC和sp_executesql的区别
经典SQL语句大全 下列语句部分是Mssql语句,不可以在access中使用。 SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) DCL—数据控制...
C# 访问Oracle示例+PL/SQL+存储过程+触发器 完整示例 测试可用 --PL/SQL基础1 declare begin dbms_output.('不输出不换行'); dbms_output.put_line('输出并换行'); end; --PL/SQL基础2 declare dig number(20,...