易截截图软件、单文件、免安装、纯绿色、仅160KB

Oracle创建触发器

今天在百度上搜索了下oracle写的触发器,感觉还可以。
就收藏咯。
用户表:创建触发器之前首先要创建序列
用户表序列:
create sequence users_seq;
用户表触发器:
create or replace trigger bifer_users_userid_pk
before insert
on users
for each row
begin
select users_seq.nextval into:new.userid from dual;
end;
/
商品表:
商品表序列:create sequence product_seq;
商品表触发器:
create or replace trigger bifer_product_itemid_pk
before insert
on product
for each row
begin
select product_seq.nextval into:new.itemid from dual;
end;
/
商品品牌表:
商品品牌表序列:create sequence brand_seq;
商品品牌表触发器:
create or replace trigger bifer_brand_brandid_pk
before insert
on brand
for each row
begin
select brand_seq.nextval into:new.brandid from dual;
end;
/
商品类别表:
商品表序列:create sequence class_seq;
商品表触发器:
create or replace trigger bifer_class_classid_pk
before insert
on class
for each row
begin
select class_seq.nextval into:new.classid from dual;
end;
/
一个触发器只能用于一个表,而一个表可以有最多三个触发器,商品品牌类别表是复合主键所以就为商品表建了两个触发器分贝作用于每个主键
商品品牌类别表:
商品品牌类别序列:create sequence brand_class_seq;
商品品牌类别触发器(brandid):
create or replace trigger brand_class_brandid_pk
before insert
on brand_class
for each row
begin
select brand_class_seq.nextval into:new.brandid from dual;
end;
/
商品品牌类别触发器(classid):
create or replace trigger brand_class_classid_pk
before insert
on brand_class
for each row
begin
select brand_class_seq.nextval into:new.classid from dual;
end;
/
在oracle中,为了方便常常用触发器及序列结合起来实现     
先建表、再建序列、然后是触发器,最后测试
=============================================                
                   &


相关文档:

ORACLE JOBS

一、设置初始化参数 job_queue_processes
  sql> alter system set job_queue_processes=n;(n>0)
  job_queue_processes最大值为1000
  
  查看job queue 后台进程
  sql>select name,description from v$bgprocess;
  
  二,dbms_job package 用法介绍
  包含以下子过程:
  
  ......

oracle不可更新的试图

关键词:with read only
作用:用于指定所创建的试图不可以通过本视图更新表
执行一下SQL,创建表T,和两个试图V1,V2:
CREATE TABLE T(ID INTEGER);
CREATE VIEW V1 AS SELECT * from T;
CREATE VIEW V2 AS SELECT * from T WITH READ ONLY;
执行SQL:
INSERT INTO V1 VALUES(1);
--------------------
1 row cre ......

ORACLE的lpad函数、rpad函数用法

ORACLE的lpad函数、rpad函数用法
语法:select lpad('12345678',1,'0') from dual;
返回字符串‘12345678’的从左边长度为1的字符串,如果不够,左边补‘0’
语法:select rpad('12345678',1,'0') from dual; 
返回字符串‘12345678’的从左边长度为1的字符串,如果不够,右边补&ls ......

Oracle 10.1 Statistics

Oracle 10.1 Statistics:
In Oracle 9.2 there were 264 statistics; in Oracle 10.1 there are 332 statistics
The following table shows the 106 statistics that were added in Oracle 10.1:
 
Name
application wait time
cluster wait time
concurrency wait time
consistent gets direct
consistent ......

oracle 日期显示英文格式

     我们初学者安装oracle的时候,字符集选择的一般是简体中文的格式,这方便我们英文不好的菜鸟,出错的时候定位错误,但是有一个问题伴随出现,我们写关于日期的sql的语句,我们想要英文的格式怎么办?下面有两个办法:
1. 连接到数据库后,我们使用如下语句
  ALTER SESSION SET NLS_D ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号