oracle基础知识整理(2)

2019-06-17 19:24

视图

create view 视图名 as select……

索引

create index 索引名 on 表名(字段名)

高级

数据类型

? 基本

数值型:number(长度,精度),decimal、int 字符串:char,varchar,nvarchar,nchar,clob,blob 日期:date,timestram ? 表

变量名 表名.字段名%type 表的某个字段类型 变量名 表名%rowtype 某个表的记录类型 ? 复合类型

type 类型名 is record( 变量名 数据类型, …… )

变量名 类型名 ? 游标

type 游标名 is ref cursor 定义游标类型 游标变量 游标名

open 游标变量 for select…… 打开游标 fech 游标变量 into 循环取值 close 游标变量 关闭游标 游标变量%notdate

控制结构

? 判断

·if 条件 then …… end if

·if 条件 then …… else …… end if

·if 条件 then …… elsif 条件 then…… else …… end if ? 循环

·when 条件 loop …… end loop ·loop …… exit when 条件 end loop

存储过程

? 语法

create procedure 过程名(变量名 in 数据类型,变量名 out 数据类型) as

declare 变量名 数据类型 --定义变量,可以用:=赋初值 begin 处理语句

exception --异常处理

when 异常处理 then …… when others then…… end

? 分页存储过程

·create package my_package is

type my_cursor is ref cursor end

·create procedure cut(v_in_table in varchar,v_in_size in number,v_in_page in number,

v_out_count out number,v_out_ye out number,v_out_rs out my_package.my_cursor) as

declare v_sql varchar(2000); declare v_start number; declare v_end number; begin

execute immeteate ?select count(*) into?||v_out_count||? from ?||v_in_table; if mod(v_out_count,v_in_size)=0 then v_out_ye:=v_out_count/v_in_size; else

v_out_ye:=v_out_count/v_in_size+1; end if;

v_start:=v_in_size*(v_in_page-1)+1; v_end:=v_in_size*v_in_page

v_sql:=?select * from (select t1.*,rownum num from (select * from ?||v_in_table||? )) t where num?>=v_start;

open v_out_rs for v_sql; end

函数

create function 函数名(参数列表) return 返回值类型 as

declare 变量名 数据类型; begin dml……

return 变量名; end

包用于把同一对象的操作放一块,方便管理 ? 创建包(用于定义类型) create package 包名 is

type 类型名 is record; type 游标名 is ref cursor;

function 函数名(参数列表) return 返回值类型; procedure 过程名(参数列表); end

? 创建包体

create package body 包名 is

变量名 类型名; 变量名 游标名;

function 函数名(参数列表)return 返回值类型 is begin …… end;

procedure 过程名(参数列表) is begin …… end; end

触发器

? dml

create trigger 触发器名

before/after --在操作之前/之后执行 之前的值为:new.字段名 之后的值为:old.字段名 delete [or update or insert of 字段名] on 表名

[for each row] --加上此句为行级触发,每dml一行都会触发,不加为表级触发,不考虑多少行,只执行一次 begin

--处理语句 (可以抛异常 调用函数 raise_application_error(错误号,‘错误信息’)

错误号在-20001到-29000之间;

可以用deleting updating inserting 判断操作类型)

end;

? ddl

create trigger 触发器名 after 事件

on 用户名.shame begin end

? 系统

create trigger 触发器名 before/after

事件(logon logoff startup shutdown) on database begin end

? 管理触发器

alter trigger 触发器名 diable锁定触发器 alter trigger 触发器名 enable解锁触发器 drop trigger 触发器名 删除触发器

Java调用数据库 jdbc

? 直接调用

public static void main(String[] args) throws Exception {

// TODO Auto-generated method stub Connection conn = null;

PreparedStatement ps = null; Statement stmt = null; ResultSet rs = null; try {

Class.forName(\); conn

=

DriverManager.getConnection(\, \, \);

}

//预定义类型

ps = conn.prepareStatement(\); ps.setString(1, \);

ps.executeUpdate();//执行增删改

rs = ps.executeQuery();//执行查询,需要定义结果集来接收结果 while(rs.next()){ }

//普通类型

stmt = conn.createStatement(); stmt.executeUpdate(\);//执行增删改

rs = stmt.executeQuery(\);//执行查询,需要定义结果集来接收结while(rs.next()){ }

// TODO Auto-generated catch block e.printStackTrace(); if(rs!=null){ }

if(stmt!=null){ }

if(ps!=null){ }

if(conn!=null){ }

conn.close(); ps.close(); stmt.close(); rs.close();

System.out.println(rs.getString(1)); System.out.println(rs.getString(1));

}

} catch (Exception e) {

}finally{


oracle基础知识整理(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2018年养老院建设现状及发展趋势分析 (目录)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: