zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    [考试反思]0421省选模拟76:学傻
    [考试反思]0420省选模拟75:安在
    [考试反思]0418省选模拟74:杂枝
    [考试反思]0417省选模拟73:纠结
    [考试反思]0416省选模拟72:停滞
    [考试反思]0415省选模拟71:限制
    [考试反思]0414省选模拟70:阻塞
    [考试反思]0413省选模拟69:遗弃
    [考试反思]0411省选模拟68:毒瘤
    [考试反思]0410省选模拟67:迷惑
  • 原文地址:https://www.cnblogs.com/ramanujan/p/3788742.html
Copyright © 2011-2022 走看看