Oracle学习笔记(五) 电脑资料_第1页
Oracle学习笔记(五) 电脑资料_第2页
Oracle学习笔记(五) 电脑资料_第3页
Oracle学习笔记(五) 电脑资料_第4页
Oracle学习笔记(五) 电脑资料_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Oracle学习笔记(五) 电脑资料 Oracle学习笔记(五) 举例一个完整的数据库脚本 -从此处开始复制,存成文件名为xxx.sql -先删除所有约束条件 alter table xxx drop constraint. -删除序列 drop sequence xxx -删除视图 drop view xxx drop view aaa. -删除表 drop table xxx. -创建表 create table xxx. -创建视图 -创建序列 -创建约束条件 -增加基础数据 DML操作 insert / update / delete 事务(Transaction)处理语句:mit/rollback/savepoint DDL:create / drop / alter / truncate SQLtruncate table student; SQLdrop table student; 其它数据库对象:视图/索引 视图的本质-sql查询语句 -简单视图 create view emp_10 as select * from emp where deptno = 10; -复杂视图 create view emp_sum as select deptno, sum(sal) sum_sal from emp group by deptno; create view emp_dept as select e.ename, d.dname from emp e join dept e on e.deptno = d.deptno; -索引index xx0225 -行内视图:查询语句出现在 from 后面 -匿名视图 select ename, sal from emp e join (select deptno, avg(sal) avgsal from emp group by deptno) a on e.deptno = a.deptno and e.sal a.avgsal; -子查询:查询语句出现在条件中 select ename, sal from emp where sal (select sal from emp where ename = SCOTT); -伪列 rownum, rowid,oracle特有的概念 select rownum,ename, sal from emp where rownum 5; -第5条到第10条记录的获取方式 -这种方式仅适用于oracle数据库 select ename, sal from (select ename, sal, rownum rn from emp ) where rn between 5 and 10; -排名问题,Top-N分析 -薪水最高的三个人,成绩最低的五个人 -错误的例子: select ename, sal from emp where rownum = 3 order by sal desc; -正确的例子: select ename, sal from (select * from emp where sal is not null order by sal desc)where rownum = 3; -序列Sequence -一种数据库对象.主要用于生成主键值. create sequence myseq_ning; -序列的两个伪列:nextval, currval -nextval获得序列的下一个值 -currval获得序列的当前值 -当序列建好以后,必须先执行nextval,才能执行currval. select myseq_ning.nextval from dual; select myseq_ning.currval from dual; create table mytable_ning(id number primary key, name varchar2(20); insert into mytable_ning values(myseq_ning.nextval, chris); select * from mytable_ning; -创建序列,起点是1000,步进是10 create sequence mysequ_ning start with 1000 increment by 10; user_objects; user_tables; user_sequences; user_views; . -获得openlab用户名下所有的对象种类. select distinct object_type from user_objects; -PL/SQL编程 -匿名块 / 函数 / 过程 / 包 / 触发器 -打开输出,sqlplus命令 set serveroutput on declare v_count number := 0; begin select count(*) into v_count from emp; dbms_output.put_line(total num is |v_count); end; / begin dbms_output.put_line(Hello World); end; / declare . begin . exception . end; declare v_sal number := 0; begin select sal into v_sal from emp where ename = aaa; dbms_output.put_line(sal is |v_sal); exception when too_many_rows then dbms_output.put_line(too many rows!); when no_data_found then dbms_output.put_line(no data!); when others then dbms_output.put_line(some error!); end; / 0-1000 0% 1001-2000 1% xx-3000 2% 3001-5000 4% 5001-. 5% -函数 create or replace function tax_ning( v_sal number) return number is v_result number; begin if (v_sal 1000) then v_result := 0; elsif (v_sal 2000) then v_result := v_sal * 0.01; elsif (v_sal 15000) then dbms_output.put_line(too many sal); else update emp set sal =

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论