Oracle笔记

一、概念

1.表空间:段->分区->块

。表空间分类:系统、临时表、永久表、大小文件表

。段分类:数据段、临时段、索引段、回滚段。

2.该关心的11G新特性:=>符号指定函数特定参数、序列、正则表达式、触发器、continue可以再循环使用。

 

二、sql 基础(不熟部分)

DDL:

1.索引

2.修改表:alter  add(列) modify(列) drop(约束)

DML:

1.通配符%、占位符_'

2.inner join:         ...from table1 inner join table2 on (some predicate)...

 

3.not exists的双重使用:(问题:查询选修所有课程的学生)

来源:http://bbs.csdn.net/topics/320174935

student 是学生表  course 是选课表  sc 是课程表

select sname           --0
from student
where not exists
               (select *      --1
                 from course
                 where not exists 
                              (select * --2
                               from sc
                               where sno =student.sno
                                 and cno=course.cno)

我的理解:2部分返回由0给定的学生选修了由1给定课程的元组,当存在时,1部分不返回结果,迭代下去,若对所有1中的course都不返回结果,则说明对0给定的学生选修了所有的课程,此时0的not exists成立,输出当前sname,再从0继续迭代。  相当于三重for循环

 

三、PL SQL 部分

1. type && record:

  type re_sometable is record(...,....,...) ;               --与C的结构体类比

2.goto

declare
    n int := 10;
begin
    <<goto_mark>>
    if n > 0 then 
      dbms_output.put_line(n);
      n := n-1;
   goto goto_mark; end if; end;

 3.CURSOR(游标)

a。cursor c is (sele....)

b。open cursor : 1.确定联编变量值;  2.确定活动集;  3.指针指向第一行

 

动态游标变量:

1.限定返回值:

 type c_dept is ref cursor return dept%rowtype;

 2.不限定返回值:

type c_dept is ref cursor;

 3.声明变量、打开、使用:

--先定义变量  
c1 c_dept

--打开 open c1 for select * from dept;
--不能这样用: --for t1 in c1 loop --..报错 --end loop; --可以这样用: loop exit when c1%notfound; fetch c1 into v_dept; --v_dept是dept的记录类型 end loop;

 4.程序包

--声明
create or replace package abc is 
    ...
end abc;

--包体定义
create or replace package body abc is
    ...
end abc;

 5.触发器

行级与语句级的区别(当不添加for each row 时,before/after为语句级触发,而inseadof为行级):

--before 触发器,没有for each row,触发一次
update dept set deptno = deptno ;
--有for each row时,触发update操作涉及到的行数的次数

 6.索引

create (unique...)index ind on (some table)

7.序列

--定义
create sequence seq increment by 3 start with 2 maxvalue 1000 cycle nocache;
--使用,seq.currval定要在seq.nextval之后使用
select seq.nextval from dual;
select seq.currval from dual; --返回上次nextval 的值

--从user_sequences中查看sequence的状态:
select * from user_sequences;

 8.同义词synonym

create (public) synonym for some_table;        --需要权限

 9.sqlplus下以数据库系统管理员身份登录sys

账号:sys as sysdba
密码:回车
--授予Scott创建synonym的权限
grant create any synonym to scott;

 10.权限

--了解所有权限的信息
select role, password, from dba_roles;

 11.错误

err_code int ;      --错误代码,可填sqlcode

err_message varchar2(100);    --错误信息,sqlerrm

posted @ 2014-06-14 21:43  Ramanujan  阅读(206)  评论(0编辑  收藏  举报