ORACLE的基本语法集锦

简介:

-- 表
create table test (names varchar2(12),
                   dates date,
                   num   int,
                   dou   double);
-- 视图
create or replace view vi_test as
select * from test;

-- 同义词
create or replace synonym aa
for dbusrcard001.aa;

-- 存储过程
create or replace produce dd(v_id in employee.empoy_id%type)
as
begin
   
end
dd;

-- 函数
create or replace function ee(v_id in employee%rowtype) return varchar(15)
is
var_test varchar2(15);
begin
  return var_test;
exception when others then
   
end

-- 三种触发器的定义
create or replace trigger ff
alter delete
on test
for each row
declare
begin
   delete from test;
   if sql%rowcount < 0 or sql%rowcount is null then
      rais_replaction_err(-20004,"错误")
   end if
end


create or replace trigger gg
alter insert
on test
for each row
declare
begin
   if :old.names = :new.names then
      raise_replaction_err(-2003,"编码重复");
   end if
end


create or replace trigger hh
for update
on test
for each row
declare
begin
  if updating then
     if :old.names <> :new.names then
 reaise_replaction_err(-2002,"关键字不能修改")
     end if
  end if
end

-- 定义游标
declare
   cursor aa is
      select names,num from test;
begin
   for bb in aa
   loop
        if bb.names = "ORACLE" then
        
        end if
   end loop;
   
end

-- 速度优化,前一语句不后一语句的速度快几十倍
select names,dates 
from test,b
where test.names = b.names(+) and
      b.names is null and
      b.dates > date('2003-01-01','yyyy-mm-dd')

 
select names,dates
from test 
where names not in ( select names 
                       from b
                      where dates > to_date('2003-01-01','yyyy-mm-dd'))
                      

-- 查找重复记录
select names,num 
from test 
where rowid != (select max(rowid) 
                 from test b 
                where b.names = test.names and
                      b.num = test.num)


-- 查找表TEST中时间最新的前10条记录
select * from (select * from test order by dates desc) where rownum < 11

-- 序列号的产生
create sequence row_id
minvalue 1
maxvalue 9999999999999999999999
start with 1
increment by 1

insert into test values(row_id.nextval,....)



本文转自左正博客园博客,原文链接:http://www.cnblogs.com/soundcode/archive/2011/01/03/1924365.html,如需转载请自行联系原作者

目录
相关文章
|
7月前
|
SQL Oracle 关系型数据库
Polar DB-O (兼容 Oracle 语法版本)和Polar DB PostgreSQL 版本概述(二)
Polar DB-O (兼容 Oracle 语法版本)和Polar DB PostgreSQL 版本概述(二)
682 0
|
8月前
|
Oracle 关系型数据库 数据库
一篇文章教你学会使用Oracle 数据库中、WITH 临时表名 AS ()语法
一篇文章教你学会使用Oracle 数据库中、WITH 临时表名 AS ()语法
67 0
|
8月前
|
Oracle 关系型数据库 数据库
一篇文章带你了解Oracle 数据库中 CROSS JOIN(cross join) 语法的作用
一篇文章带你了解Oracle 数据库中 CROSS JOIN(cross join) 语法的作用
297 0
|
8月前
|
SQL Oracle 关系型数据库
Oracle 数据库 常见SQL语法
Oracle 数据库 常见SQL语法
120 0
|
10月前
|
存储 SQL Oracle
Oracle存储过程~基本语法
Oracle存储过程~基本语法
|
SQL Oracle 关系型数据库
在Oracle中,什么是Quote(q) Q语法?
在Oracle中,什么是Quote(q) Q语法?
148 0
|
Oracle 关系型数据库
oracle学习58-plsql轻量版基本语法
oracle学习58-plsql轻量版基本语法
144 0
oracle学习58-plsql轻量版基本语法
|
存储 SQL Oracle
Oracle触发器语法及实例
触发器是特定事件出现的时候,自动执行的代码块。类似于存储过程,触发器与存储过程的区别在于:存储过程是由用户或应用程序显式调用的,而触发器是不能被直接调用的。
140 0
|
存储 Oracle 关系型数据库
Oracle存储过程迁移ODPS-03(专有云):ODPS1.0支持exists语法
专有云目前还有不少ODPS1.0版本,主要是应对V3之前的平台版本。这个版本的ODPS不支持exists语法,如何换种写法实现。
2971 0