PLSQL高级查询.doc

  1. 1、本文档共8页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
PLSQL高级查询

数据库 启动数据库 Sqlplus/nolog 登陆连接数据库 Conn ygj/123@orcl as sysdba; 表空间 创建表空间 Create tablespace tbs_school 2 datafile ‘F:\app\Rainbow\oradata\orcl\ school_01.dbf’ 3 size 20m autoextend on; 修改表空间 Alter database datafile ‘F:\app\Rainbow\oradata\orcl\ 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 3; 用户授权 Sys账户连接数据库 Conn sys/123@school as sysdba; 创建用户 Create user test1 identified by sys Default tablespace 表空间名 Temporary tablespace 临时表空间名 Quota 5m on 表空间名; 用户授权 连接表权限Grant create session to 用户; 创建表权限Grant create table to用户; 撤销权限 Revoke create session,create table from 用户; 创建角色 Create role 角色名; 角色授权 Grant create session,cre

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档