已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
绪论:1、Oracle,甲骨文,1977年开始研发,总部位于美国加州红木滩市,创始人为Larry Ellison(埃里森) 、Bob Miner、Ed Oates2、Oracle服务器实例数据库;Oracle实例内存后台进程;第四章:表空间的创建与删除例4.1 建立名称为data_ts1的数据表空间,大小为50M,区间统一为128KB大小。 SQL conn system/systempwdorcl SQL drop tablespace data _ts1 including conntents;SQL create tablespace data _ts12tempfile %oracle_home%databasedata_ts1.dbf SIZE 50M REUSE3uniform size 128K;例4.2 建立名称为temp_ts1的临时表空间,使用temp_ts1.dbf文件存放临时数据。 SQL conn system/systempwdorclSQL drop tablespace temp_ts1 including conntents;SQL create temporary tablespace temp_ts12 tempfile %oracle_home%databasetemp_ts1.dbf size 20M reuse3 uniform size 128k;例4.3 创建10号部门经理用户EMP_MGR10,指定该用户的数据表空间为data_ts1,临时表空间为temp_ts1。授权该用户可以查看SCOTT用户下雇员表中的记录。 SQL conn system/systempwdorclSQL drop user emp_mgr10 cascade;SQL create user emp_mgr10 identified by emp_mgr10pwd2 default tablespace data_ts1 temporary tablespace temp_ts1;SQL grant connect to emp_mgr10;SQL conn scott/tigerorcl4 tempfile %oracle_home%databasetemp_ts1.dbf size 20M reuse5 uniform size 128k;例4.4 创建和应用撤销表空间。 SQL conn system/systempwdorclSQL drop tablespace undo_ts1 including conntents;SQL create undo tablespace undo_ts12 datafile %oracle_home%databaseundo_ts1.dbf size 50M reuse;例4.5 创建大文件表空间,并指定为SCOTT用户的默认数据表空间。 SQL conn system/systempwdorclSQL drop tablespace bigfile_ts1 including conntents;SQL create bigfile tablespace bigfile_ts12 datafile %oracle_home%databasebigfile_ts1.dbf size 50M reuse;SQL alter user scott default tablespace bigfile_ts1;需要注意的是,大文件表空间的段空间管理不能为手工(MANUAL),只能为自动(AUTO)。例4.6 调整数据表空间data_ts1的大小。 SQL conn system/systempwdorcl-为表空间data_ts1增加一数据文件,大小为1M。SQL alter tablespace data_ts12add datafile %oracle_home%database data _ts2.dbf size 1M;-重置该数据文件大小为2M。SQL alter tablespace2datafile %oracle_home%database data _ts2.dbf size 2M;-修改该数据库,允许该文件自动扩展,每次扩展1M,文件最大扩展到10M。SQL alter database datafile %oracle_home%databasedata_ts2.dbf 2autoextend on next 1M maxsize 10M;例4.7 删除temp_ts1表空间。 SQL conn system/systempwdorclSQL drop tablespace temp_ts12including contents and datafiles3cascade constraints ;例4.8 回退段创建与删除。 SQL conn system/systempwdorclSQL drop rollback segment undo_ts1_rbs1;SQL create rollback segment undo_ts1_rbs1;2tablespace undo_ts1 storage( initial 5K3next 5K4optimal 5000K5minextents 156maxextents 100);第5章:常用方案对象类型:表:table索引:index 视图:view 序列:sequence用户:user 约束:constraint 表空间:tablespace回退段:rollback segment同义词:synonym 数据库链接:database link聚簇:cluster分区:partition 函数/过程/包:func tion/procedure/package触发器:trigger 类型:type约束的类型: NOT NULL:非空约束check :检查约束,用于限制该列的取值范围Unique :唯一性约束,指定某列值不能重复 primary key :主键约束Foreign key :外键约束,也叫参照完整性约束Ref :定义列对象的参照关系References :参照完整性约束例5.1 创建采用系统默认存储参数值的关系表。 EXA_05_01.SQL 例5.2 为SCOTT的雇员表emp创建一个备份表emp_bak。SQL conn scott/tigeremp_orcl SQL dorp table emp_bak; SQL create table emp_bak SQL as select * from emp; SQL desc emp_bak SQL select * from emp_bak; 例5.3 创建表stu2,并指定它的存储参数。 EXA_05_03.SQL 例5.4 创建学生相关表,在列中定义约束。 EXA_05_04.SQL例5.5 创建学生相关表,在列之外定义约束。 EXA_05_05.SQL例5.6 创建学生相关表,在列之外定义约束。 EXA_05_06.SQL例7.1 某电子商务网站估计每月产生近千万条订单记录。该网站采用年YYYY+月MM+当月流水号nnnnnnnn的形式标识和区分每一份订单。当有用户提交一份订单时,系统自动生成该订单的编号并告知用户这个唯一的订单号。创建一序列,用于生成每月的订单流水号。(老师要求例子)conn scott/tigerorcldrop sequence order_seq;create sequence order_seq increment by 1 start with 10000000 cache 500 nocycle;col sequence_name format a13select sequence_name, min_value, max_value, increment_by, last_number from user_sequences; select order_seq.currval from dual;select order_seq.nextval from dual;select order_seq.currval from dual;select order_seq.nextval from dual;select order_seq.currval from dual;-函数案例:案例1.返回工人年工资。create or replace function xxc_fun1(newname varchar2)return number is yearSal number(10,2);beginselect sal*12+nvl(comm,0)*12 into yearSal from emp where ename=newname;return yearSal;end;例9.编写函数按YYYY-MM-DD HH24:MI:SS格式以字符串形式返回当前系统时间。connect scott/tigerorclcreate or replace function current_time return varchar2 asbegin return to_char(sysdate,yyyy-mm-dd hh24)|: | to_char(sysdate,mi)|:|to_char(sysdate,ss);end;/select current_time from dual;例9.21 查询指定编号雇员的名字、工资和佣金。 存储过程conn scott/tigerorclcreate or replace procedure query_emp (p_no in emp.empno%type, p_name out emp.ename%type, p_sal out emp.sal%type, p_comm out m%type)isbegin select ename,sal,comm into p_name,p_sal,p_comm from emp where empno = p_no;end query_emp;/variable g_name varchar2(25)variable g_sal numbervariable g_comm numberexecute query_emp(7369,:g_name,:g_sal,:g_comm)print g_name例9.39创建触发器:1 在scott的emp表上建立语句前触发器emp_permit_changes。Create or replace trigger scott.emp_helloBefore Delete or insert or update On scott.emp Begin raise_application_error(-20001,how are you!);End;2 修改触发器使emp_hello触发器不能触发:alter trigger scott.emp_hello disable;3 删除触发器drop trigger scott.emp_hello;end;/update emp set sal=100 where empno=7369;例9.37 为雇员表emp创建一触发器,确保插入记录的工资列sal不小于0,同时新记录的sal列值不能高于已有记录最高工资的2倍。conn scott/tigerorclcreate or replace trigger check_sal_emp before insert or update on emp referencing old as old new as new for each row begin if :new.sal 2 * wage_package3.g_sal then raise_application_error(-20502,雇员工资超过现有最高工资2倍); end if;end;/insert into emp (empno, ename, hiredate,job, sal, deptno) values (300, jordan, sysdate,it_prog, -3, 10);insert into emp (empno, ename, hiredate,job, sal, deptno) values (300, tracyzhou, sysdate,acc.offi., 16000, 10);Oracle实例有两种类:单进程实例和多进程实例。多进程系统中,进程分为两类:用户进程和Oracle进程。Oracle进程又分为两类:服务器进程(server process)和后台进程(background process)。Oracle数据库的索引模式:(1) B-树索引(2) B-树簇索引(3) 散列簇索引(4) 全局和本地索引(5) 反序索引(6) 位图索引(7) 基于函数的索引(8) 域索引创建视图:1、生成一个部门号是10的视图:create view d10emp as select empno, ename, sal from emp where deptno = 10;2、 删除视图: drop view d10emp;3、 创建索引:create index i_ename on emp(ename);create unique index i_empno on emp(empno);索引应用如果查询语句如下则没有用到索引i_ename:select ename,job,sal from emp;如果查询语句如下则用到索引i_ename:selct * from emp where ename = jones;4、删除索引:drop index i_ename;5、创建一个用户:create user myself identified by my;6、修改用户口令:alter user myself identified by me;7、对象权限授权:把dept 的select对象权限授给myself用户:grant select on dept to myself;把emp的select权限授给所有用户:grant select on emp to public;8、收回对象权限:从myself收回所有dept的对象权限:revoke all on dept from myself;收回所有用户对emp的select权限:revoke select on emp from public;9、删除用户:drop user myself;实验三: 数据插入(insert)、修改update和删除delete1 用Insert在基本表customer中插入数据SQLinsert into customer values (nicholson,ca,6989.99);2 在表STATE中插入指定的字段SQLinsert into state (state_name,state_cd)2values (massachusetttes,MA);1 row created.3修改数据把state表中newyork改为florida,ny改为fd:update state set state_name = florida, state_cd = fd where state_name = newyork and state_cd = ny;4删除数据从state表删除state_name为Florida和state_cd为fd的记录:delete from state where state_name = florida and state_cd = fd;删除表全部数据:delete from hzx.sc2、对s、c、sc表进行操作:s (s#,sname,age,sex) 对应的中文为: (学号,姓名,年龄,性别)sc (s#,c#,grade) 对应的中文为:学习(学号,课程号,成绩) c(c#,cname,teacher) 对应的中文为:课程(课程号,课程名,任课教师)1)、把c2课程的非空成绩提高10%。update stu.sc set grade = grade*1.1 where c# = c2 and c# is not null;2)、在sc表中删除课程名为physics的成绩的元组。delete from stu.sc where c#=physisc;3)、在s和sc表中删除学号为s8的所有数据。delete from stu.sc where s#=s8; delete from stu.s where s#=s8;实验四:
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年体育用品行业用户心智占领与品牌塑造研究报告
- 跌倒、坠床的应急预案与流程演练脚本
- 2026初中历史教资面试常考考题题库及解析
- 2026年内蒙古自治区呼和浩特市国家公务员公共基础知识模拟题带答案
- 2026年大学电大专科学前儿童发展心理学选择判断题题库带答案
- 2026年工程测量试题题库及答案
- 2026年教育软件测试原理题库及答案
- 2026年考研卫生毒理学经典题库及答案
- 2026年市场监督执法考试题库及参考答案
- 2026年陕西省榆林市继续教育公需科目模拟试卷及答案
- 中煤电力社会招录笔试试题2026
- 2026年溶剂油行业洞察报告及未来五至十年发展趋势报告
- 2026年初级会计资格考试《初级会计实务》真题+答案解析
- 高校外籍留学生管理安全培训
- 高三思想政治教学设计:必修四哲学原理举例说明的情境关联词教学实践
- T/QLMZ 19-2024化妆品用原料 海藻酸钠
- 幼儿同伴交往能力评估量表(PAS)实施规范
- 2026年退管人员测试题及答案
- 商会招聘笔试题及答案
- 癫痫诊疗指南(2025年版)
- 年中小学教师正高级职称评聘答辩试题附答案
评论
0/150
提交评论