




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
数据库启动数据库Sqlplus/nolog登陆连接数据库Conn ygj/123orcl as sysdba;表空间创建表空间Create tablespace tbs_school2 datafile F:appRainboworadataorcl school_01.dbf3 size 20m autoextend on;修改表空间Alter database datafile F:appRainboworadataorcl school_01.dbf resize 30m;用户创建用户Create user 用户名 identified by 密码2 default tablespace 表空间名3 temporary tablespace temp;授权Grant 角色名 to 用户名;表创建表Create table 表名(字段名 字段类型(字段长度), 字段名 字段类型(字段长度)Create table school(id varchar2(5),name varchar2(40),studentCount number(3);查询表desc表名; 添加字段alter table 表名 add(字段名 字段类型(字段长度);修改字段alter table 表名 modify(字段名 字段类型(字段长度);删除字段Alter table 表名 drop column 字段名;删除表Drop table 表名约束增加主键约束Alter table 表名 add constraint约束名primary key(字段名);查看主键约束Select constraint_name from user_constraints where table_name = 表名(大写);增加唯一约束Alter table 表名 add constraint约束名unique(字段名);增加检查约束Alter table 表名 add constraint约束名check(字段名0);删除约束Alter table 表名 drop constraint约束名;表数据操作创建记录Insert into 表名 (字段名,字段名,字段名,createdate) values(字段值,字段值,字段值,to_date(2012-03-19,yyyy-mm-dd);创建备份表Create table school_bk(字段名 字段类型(字段长度), 字段名 字段类型(字段长度)备份数据Insert into school_bk select t.*,sysdate from school t;提交数据commit更新表数据Update 表名 set 字段名 = 字段值, 字段名 = 字段值 where id = 00002;删除表数据Delete from 表名 where id = 00002,恢复备份表Insert into 表名 select id,name,studentCount from school_bk截断表,不需要提交Truncate table 表名;查询字段部分查询Select 字段名,字段名 from 表名; 条件查询Select * from 表名 where 字段名 between 100 and 200; 升序排序查询Select * from school order by 字段名; 降序排序查询Select * from school order by 字段名 desc; 别名查询Select id as “编号”,name as “学校” from 表名限制查询行数Select id as “编号”,name as “学校” from 表名 where rownum 150;声明及赋值变量declare num number(16); name %type;begin num := 20; dbms_output.put_line(num= | num); select name into name from school s where s.id=00001; dbms_output.put_line(name);end;逻辑控制结构declare birthyear number;begin birthyear :=1990; if birthyear between 1980 and 1989 then dbms_output.put_line(80后); elsif birthyear between 1990 and 1999 then dbms_output.put_line(90后); else dbms_output.put_line(00后); end if;end;多分支条件结构(查询语句中使用)select (case when atk between 2000 and 2999 then 高级怪兽 when atk between 3000 and 3999 then 超级怪兽 when atk between 4000 and 4999 then 神之卡 else 没有找到匹配项 end)lv from card;多分支条件结构2declareatk number;begin atk := 4000; case when atk between 2000 and 2999 then dbms_output.put_line(高级卡); when atk between 3000 and 3999 then dbms_output.put_line(超级卡); when atk between 4000 and 4999 then dbms_output.put_line(神之卡); else dbms_output.put_line(没有找到匹配项); end case;end;LOOP循环declare i number := 0;begin dbms_output.put_line(循环之前i= | i); loop if i 4 then exit; end if; dbms_output.put_line(循环第 | (i + 1) | 次); i := i + 1; end loop; dbms_output.put_line(循环结束);end;FOR循环begin for i in 1.100 loop if(mod(i,3)=0)then dbms_output.put_line(i); end if; end loop;end;捕获异常declare salary number := 0 ; salary_exception exception ;begin salary := &salary; if salary 0 then raise salary_exception; end if; dbms_output.put_line(输入的工资是|salary); exception when salary_exception then dbms_output.put_line(输入的工资数据不合法!);end;内链接两种查询方式select , from card c,owner o where c.owner=o.id;select , from card c join owner o on c.owner=o.id;左外连接查询方式select , from card c left join owner o on c.owner=o.id;右外连接查询方式select , from card c right join owner o on c.owner=o.id;全外连接查询方式select , from card c full join owner o on c.owner=o.id;组合查询select id,name from ownerunion allselect id,name from owner2;简单子查询select name,owner from card where owner = (select id from owner where name = 游戏);相关子查询select name,owner from card where owner in (select id from owner where name = 游戏 or name=城之内);内嵌视图子查询select name,owner from card e where exists (select o.id from owner o where ( = 游戏or =城之内)and e.owner = o.id);创建序列create sequence seq_location_pk start with 0 increment by 1 maxvalue 3000 cycle cache 30;使用序列begin insert into location (id,name) values (seq_location_pk.nextval,北京); insert into location (id,name) values (seq_location_pk.nextval,上海); insert into location (id,name) values (seq_loca
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 企业名称可持续发展报告2020-2025年实践报告放射治疗器械
- 国际贸易合同常见条款及范本
- 小学数学各年级重点知识点对比分析
- 员工离职率分析报告与改善措施
- 初中数学几何专题思维拓展训练题
- 电子商务客户满意度提升方案集
- 五年级数学下册应用题专项训练解析
- 电子银行系统操作安全规范
- 小学二年级数学课程教学日志
- 企业员工安全培训教育资料包
- 桩基冲击钻机施工方案
- 基金考试题库大全及答案
- 2025至2030中国生物基化学品行业产业运行态势及投资规划深度研究报告
- 雾化吸入课件
- 航海船舶运输管理总结
- 2025年注册安全工程师实务《其他安全》试题+答案
- 采购战略合作协议范本5篇
- 安徽省六校联考2025-2026学年高三上学期开学检测语文试题(解析版)
- 财务部安全生产培训报告课件
- 会计毕业论文烟草专业
- 年产5万吨电熔锆刚玉新材料扩建项目环境影响报告表
评论
0/150
提交评论