[新手推荐]Oracle基本语法集锦
作者:佚名 出处:斑马社区 更新时间:2007-08-08 责任编辑:
 
 

【斑马资讯 教程】1、表

create table test (names varchar2(12),dates date,num int,dou double);

2、视图

create or replace view vi_test asselect * from test;

3、同义词

create or replace synonym aafor dbusrcard001.aa;

4、存储过程

create or replace produce dd(v_id in employee.empoy_id%type)asbeginenddd;

5、函数

create or replace function ee(v_id in employee%rowtype) return varchar(15)isvar_test varchar2(15);beginreturn var_test;exception when others thenend

6、三种触发器的定义

create or replace trigger ffalter deleteon testfor each rowdeclarebegindelete from test;if sql%rowcount < 0 or sql%rowcount is null thenrais_replaction_err(-20004,"错误")end ifendcreate or replace trigger ggalter inserton testfor each rowdeclarebeginif :old.names = :new.names thenraise_replaction_err(-2003,"编码重复");end ifendcreate or replace trigger hhfor updateon testfor each rowdeclarebeginif updating thenif :old.names <> :new.names thenreaise_replaction_err(-2002,"关键字不能修改")end ifend ifend

7、定义游标

declarecursor aa isselect names,num from test;beginfor bb in aaloopif bb.names = "ORACLE" thenend ifend loop;end

8、速度优化,前一语句不后一语句的速度快几十倍

select names,dates from test,bwhere test.names = b.names(+) andb.names is null andb.dates > date('2003-01-01','yyyy-mm-dd')select names,datesfrom test where names not in ( select names from bwhere dates > to_date('2003-01-01','yyyy-mm-dd'))

9、查找重复记录

select names,num from test where rowid != (select max(rowid) from test b where b.names = test.names andb.num = test.num)

10、查找表TEST中时间最新的前10条记录

select * from (select * from test order by dates desc) where rownum < 11

11、序列号的产生

create sequence row_idminvalue 1maxvalue 9999999999999999999999start with 1increment by 1insert into test values(row_id.nextval,....)

 
     
 
 
继续>>Oracle
[第1页][第2页][下一页]
 
内容导航  
第1页[新手推荐]Oracle基本.. 第2页Oracle
上一篇 : Oracle10g在Solaris10上.. 下一篇Unix和Solaris的简要发展..
 
  您要为所发表的言论的后果负责,请各位遵纪守法并注意文明用语
标题:  

[ 关于本站 ] [ 广告服务 ] [ 商务合作 ] [ 联系我们 ] [ 合作伙伴 ] [ 法律顾问 ] [ 网站地图 ]
千橡公司 京ICP证041489号 Copyright (c) 1997-2007 All Right Reserved.